2 条题解
-
1
#include<bits/stdc++.h> using namespace std; int zu[100001]; int x, r=0; int cnt=0; struct mac { int x; int y; }; mac man[10001]; int main() { int s; cin >> x; for(int i=0;i<x;i++){ cin >> man[i].x >> man[i].y; } for(int j=0;j<x;j++){ int maxx = man[j].x,maxy=man[j].y; for(int i=0;i<x;i++){ if(i!=j)if(maxx>=man[i].x&&maxy>=man[i].y)man[i].x=0,man[i].y=0; } } int is=0; mac mst[1001]; for(int i=0;i<x;i++){ if(0!=man[i].x&&0!=man[i].y){ mst[is].x = man[i].x; mst[is].y = man[i].y; is++; } } for(int j=0;j<is;j++){ for(int i=0;i<is-1;i++){ if(mst[i].x > mst[i+1].x){ int c=mst[i].x; mst[i].x=mst[i+1].x; mst[i+1].x=c; c=mst[i].y; mst[i].y=mst[i+1].y; mst[i+1].y=c; } } } for(int j=0;j<is;j++){ if(j!=0)cout <<','; cout << '('<<mst[j].x<<','<<mst[j].y<<')'; } return 0; }
这是我通过“活动选择”改的 可以加进
-
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; struct node{ LL x,y; }a[20010]; bool cmp(const node &x,const node &y){ if(x.y!=y.y) return x.y>y.y; return x.x>y.x; } int main(){ LL n; scanf("%lld",&n); for(LL i=1;i<=n;i++) cin>>a[i].x>>a[i].y; sort(a+1,a+n+1,cmp); LL f=1,la=-1; for(LL i=1;i<=n;i++){ if(a[i].x>la){ la=a[i].x; if(f) f=0; else cout<<","; printf("(%lld,%lld)",a[i].x,a[i].y); } } return 0; }
- 1
信息
- ID
- 220
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 6
- 已通过
- 5
- 上传者