标签:string style return png 描述 scanf bsp cst ring
开一个数组,读入一次交换两个数,如果最后数组不变,即符合匹配
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #define MAXN 500005 using namespace std; int arr[MAXN]; void swap(int a,int b){ int t=arr[a]; arr[a] = arr[b]; arr[b] = t; } bool isOk(){ for(int i=0; i<MAXN; ++i) if(arr[i]!=i) return false; return true; } int main(){ int n, i, a, b; while(scanf("%d",&n), n){ for(int i=0; i<MAXN; ++i) arr[i] = i; for(int i=0; i<n; ++i){ scanf("%d %d", &a, &b); swap(a, b); } if(isOk()) printf("YES\n"); else printf("NO\n"); } return 0; }
交换学生 (Foreign Exchange,UVa10763)
标签:string style return png 描述 scanf bsp cst ring
原文地址:https://www.cnblogs.com/secoding/p/9495832.html