풀이 ¶
// // main.cpp // usa_selfish // // Created by 김 태진 on 12. 8. 14.. // Copyright (c) 2012년 __MyCompanyName__. All rights reserved. // #include <stdio.h> #include <stdlib.h> #include <algorithm> using namespace std; typedef struct cow cow; struct cow{ int left; int right; }; int compare(const void* a,const void* b); int comp(cow a,cow b); int main() { int N,i,j,k; cow arr[50000],temp; cow array[10000]; scanf("%d",&N); for(i=0;i<N;i++){ scanf("%d %d",&arr[i].left,&arr[i].right); // scanf("%d",&arr[i]); } // qsort((void*)arr, N, sizeof(int), comp); sort(arr,arr+N-1,comp); /* for(i=0;i<N-1;i++){ for(j=i+1;j<N;j++){ if(arr[i].right>arr[j].right){ temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } }*/ array[0]=arr[0]; k=1; for(i=0;i<N;i++){ if(array[k-1].right<=arr[i].left){ array[k]=arr[i]; k++; } } printf("%d",k); return 0; } int compare(const void* a,const void* b) { //((cow *)a)->right; return *(int*)a-*(int*)b;//*((cow *)a)->right - *((cow *)b)->right; } int comp(cow a,cow b) { //if(a.left == b.left)return a.right<b.right; return a.right<b.right; /* if(a.right > b.right){ return a.right > b.right; }else{ return a.right < b.right; } */ }
ACM_ICPC/2012스터디