uva-10763-交换生

题意:有一个交换生由A->B,想交换得有一个B->A,问,是不是所有人都能交换成.

俩个数字交换偶数次还是自身,开一个数组mark,模拟完所有样例后,看数组是不是还是初始化数组.

#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector> namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap; constexpr int N = 500001;
//constexpr int N = 30; //priority_queue<int,vector<int>, greater<int> >q; int mark[N];
void init()
{
for (int i = 0;i < N;i++)
mark[i] = i;
} void solve()
{
int n, s, e;
while (cin >> n && n)
{
init();
for (int i = 0;i < n;i++)
{
cin >> s >> e;
auto t = mark[e];
mark[e] = mark[s];
mark[s] = t;
}
int ok = 1;
for (int i = 0;i < N;i++)
if (mark[i] != i)
{
ok = 0;
break;
}
if (ok)
cout << "YES" << endl;
else
cout << "NO" << endl;
} } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return 0;
}

  

上一篇:Xcode7中添加3DTouch


下一篇:UITableView的常用方法与示例