랭작문제
정렬을 열심히 해주고
범위에 상관없이
가져갈수있는 책들 중 가장 앞번호만 가져가게 해주었다
모두가 앞번호를 가져가려 하고,
앞번호를 가져갈 수 있는 사람들부터 책을 나눠주게 되면,
가장 많은 수의 책을 나눠줄 수 있게 된다.
https://www.acmicpc.net/problem/9576
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
bool chk[1010] = {0};
int n,m,a,b,cnt,t;
vector<pair<int,int>> v;
bool compare(pair<int,int> a, pair<int,int> b){
if(a.second == b.second) return a.first < b.first;
return a.second < b.second;
}
int main(){
scanf("%d", &t);
while(t--){
cnt = 0;
v.clear();
for(int i=0; i<1010; i++) chk[i] = false;
scanf("%d %d", &n, &m);
for(int i=0; i<m; i++){ scanf("%d %d", &a, &b); v.push_back({a,b}); }
sort(v.begin(), v.end(), compare);
for(int i=0; i<m; i++){
for(int j=v[i].first; j<=v[i].second; j++) if(chk[j] == false){ chk[j] = true; cnt++; break; }
}
printf("%d\n", cnt);
}
return 0;
}
얘도 적당히 짜주면 무난하게 AC
와 내가 골드1을 무난하게 AC라 말할수 있는 날이 오다니
감회가 새롭군
깔끔하게 AC 받았다.
반응형