HDU 6029 Graph Theory

xiaoxiao2021-02-28  54

http://acm.hdu.edu.cn/showproblem.php?pid=6029

有n个数字,给出两种操作,询问是否存在完美匹配。

一开始以为是二分图,但是这复杂度有点爆表,所以不知道怎么下手,然后队友dalao告诉我,只需要不断维护前面没有匹配到的就可以的。所以写了一发,1A

#include<bits/stdc++.h> using namespace std; int main() { bool sw[100005]; int T, n, ope, front; cin >> T; while(T--) { memset(sw, 0, sizeof(sw)); front = 1; scanf("%d", &n); for(int i = 2; i <= n; i++) { scanf("%d", &ope); if(ope == 1) { sw[i] = 1; while(front < i) { if(!sw[front]) { sw[front] = 1; break; } front++; } } } if(n % 2 == 1) { cout << "No" << endl; continue; } for(; front <= n; front++) if(!sw[front]) { cout << "No" << endl; break; } if(front >= n + 1) cout << "Yes" << endl; } return 0; }

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

最新回复(0)