1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> struct Arr { int l,w; }arr[50001]; int cmp(const void * a,const void * b) { struct Arr *c=(struct Arr *)a; struct Arr *d=(struct Arr *)b; if(c->l!=d->l) return c->l - d->l; else return c->w - d->w; } int main() { int T,N,i,j,t; scanf("%d",&T); while(T--) { int count=0; scanf("%d",&N); for(i=0;i<N;i++) scanf("%d%d",&arr[i].l,&arr[i].w); qsort(arr,N,sizeof(arr[0]),cmp); for(i=0;i<N;i++) { if(arr[i].w!=0) { t=arr[i].w; count++; for(j=i+1;j<N;j++) { if(t<=arr[j].w) { t=arr[j].w; arr[j].w=0; } } } } printf("%d\n",count); } return 0; }
C++ :
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct mb { int len; int weight; }w[10001]; bool cmp(mb x,mb y) //排序 { if(x.len<y.len) return true; //升序 if(x.len==y.len&&x.weight<y.weight) return true; return false; } int main() { int s,n,i,j,count,t; scanf("%d",&s); while(s--) { count=0; scanf("%d",&n); for(i=0;i<=n-1;i++) { scanf("%d %d",&w[i].len,&w[i].weight); } sort(w,w+n,cmp); for(i=0;i<=n-1;i++) { if(w[i].weight!=0) //数未出现过 { t=w[i].weight; count++; //开启一单位 for(j=i+1;j<=n-1;j++) { if(w[j].weight>=t) { t=w[j].weight; w[j].weight=0; } } } } printf("%d\n",count); } return 0; }
- 1
信息
- ID
- 780
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者