Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA 请大神帮忙看看怎么一直WA,数据试了很多#include "stdio.h" #include "stdlib.h" int cmp(const void *m, const void *n){ int *a=(int*)m,*b=(int*)n; return (*a==*b)?(*(a+1)<*(b+1)):(*a>*b); } int main() { int data[20005][2]; int t,m; scanf("%d",&t); while(t--){ scanf("%d",&m); for(int i=0;i<m;i++)scanf("%d %d",&data[i][0],&data[i][1]); qsort(data,m,sizeof(int)*2,cmp); int j=0; for(int i=1;i<m;i++){ if(data[i][1]<=data[j][1])data[++j][1]=data[i][1]; else { int s=0,e=j,mid; while(s<=e){ mid = (s+e)/2; if(data[mid][1]<data[i][1])e = mid-1; else s = mid+1; } data[s][1]=data[i][1]; } } printf("%d\n",j+1); } system("pause"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator