A - Present Problem UVALive - 7000

xiaoxiao2021-02-28  33

这个题目一开始是想着交换的思路,就是一能去二,二也能去一,就是交换的顺序注意一下就可以,其实就是反着推一遍就可以,记得顺序要是反的,从最后推到前面。记得可能有重复的点,这个题目,

#include <iostream> #include <vector> #include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std; const int maxn = 100000 + 10; struct Node { int x,y; Node(int a = 0,int b = 0) { x = a; y = b; } //operator } num[maxn]; int n,m,l; int par[maxn]; int ans[maxn]; bool judge(Node a,Node b) { if(a.x == b.x && a.y == b.y) return true; return false; } void init() { for(int i = 0; i < n; i++) { par[i] = i; } } bool cmp(const Node a,const Node b) { if(a.y != b.y) return a.y < b.y; return a.x < b.x; } int main() { int t; scanf("%d",&t); while(t--) { //memset(ans,0,sizeof(ans)); scanf("%d %d %d",&n,&m,&l); init(); for(int i = 0; i < m; i++) { int x,y; scanf("%d %d",&num[i].x,&num[i].y); } sort(num,num+m,cmp); for(int i = 0; i < m; i++) { int l = num[i].x; int r = l+1; if(r >= n) continue; if(i != m - 1 && judge(num[i],num[i+1])) continue; swap(par[l],par[r]); } for(int i = 0; i < n; i++) { ans[par[i]] = i; } for(int i = 0; i < n; i++) { cout<<ans[i]<<endl; } } return 0; }

转载请注明原文地址: https://www.6miu.com/read-600260.html

最新回复(0)