U E D R , A S I H C RSS

usa_selfish/김태진

Difference between r1.2 and the current

@@ -33,18 +33,8 @@
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;
}
}
}*/
qsort((void*)arr, N, sizeof(cow), compare);
array[0]=arr[0];
k=1;
for(i=0;i<N;i++){
@@ -62,22 +52,14 @@

int compare(const void* a,const void* b)
{
//((cow *)a)->right;
return *(int*)a-*(int*)b;//*((cow *)a)->right - *((cow *)b)->right;
return ((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;
}
*/
}

}

}}}
----


풀이

//
//  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(cow), compare);

	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)
{
	return ((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;

}


ACM_ICPC/2012스터디
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:45
Processing time 0.0234 sec