其他分享
首页 > 其他分享> > 1327B - Princesses and Princes

1327B - Princesses and Princes

作者:互联网

暴力:

暴力枚举所有人即可

数据有误,第三行应该是\(2 1\),害我调半天

#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int N = 100010;
int n;
set <int> ans;
int main () {
	int T;
	cin >> T;
	while (T--) {
		bool success = false;
		cin >> n;
		ans.clear ();
		for (int i = 1;i <= n;i++) ans.insert (i);
		int idx;
		for (int i = 1;i <= n;i++) {
			int k;
			bool flag = false;
			cin >> k;
			while (k--) {
				int x;
				cin >> x;
				if (ans.count (x) && !flag) {
					ans.erase (x);
					flag = true;
				}
			}
			if (!flag) {
				idx = i;
				success = true;
			}
		}
		if (success) {
			cout << "IMPROVE" << endl;
			cout << idx << ' ' << *ans.begin () << endl;
		}
		else cout << "OPTIMAL" << endl;
	}
	return 0;
}

标签:1327B,Princes,success,int,Princesses,cin,flag,ans,include
来源: https://www.cnblogs.com/incra/p/16388258.html