标签:一模一样 需要 多少 class codeforce sort 压缩 cin code
题意:每个顾客有几种想要的原料,每个披萨含有几种原料,问你买两块披萨,让最多的顾客全部吃到想要的原料,同时花最少的钱,需要买哪两块
原料只有九种,O(n^2)枚举披萨转换为(512*512)枚举状态,买两个状态一样的跑一遍,买两个状态不一样的跑一遍
是被队友嫌弃的码风
signed main()
{
int n, m; cin >> n >> m;
vector<int> many(512, 0); //某格式可以让多少顾客开心
rep(i, n) //顾客
{
int k, sum = 0; cin >> k;
rep(j, k)
{
int x; cin >> x;
sum |= (1 << (x - 1));
}
rep(j, 512) if ((j & sum) == sum)++ many[j];
}
vector<pii> pizza[512]; //每个格式的披萨价钱
rep(i, m) //披萨
{
int k, c, sum = 0; cin >> c >> k;
rep(j, k)
{
int x; cin >> x;
sum |= (1 << (x - 1));
}
pizza[sum].push_back(make_pair(c, i + 1));
}
int maxhappy = 0, mincost = 1 << 30, a = 1, b = 2;
//买两个一模一样的披萨
for (int i = 0; i < 512; ++i)
{
sort(all(pizza[i]));
if (pizza[i].size() >= 2 && (many[i] > maxhappy || (many[i] == maxhappy && pizza[i][0].first + pizza[i][1].first < mincost)))
maxhappy = many[i], mincost = pizza[i][0].first + pizza[i][1].first, a = pizza[i][0].second, b = pizza[i][1].second;
}
//买两个不一样的披萨
for (int i = 0; i < 512; ++i)
for (int j = i + 1; j < 512; ++j)
if (pizza[i].size() && pizza[j].size() && (many[i | j] > maxhappy || (many[i | j] == maxhappy && pizza[i][0].first + pizza[j][0].first < mincost)))
maxhappy = many[i | j], mincost = pizza[i][0].first + pizza[j][0].first, a = pizza[i][0].second, b = pizza[j][0].second;
cout << a << " " << b << endl;
return 0;
}
Codeforces Round #568 (Div. 2) F - Two Pizzas (状态压缩,暴力)
标签:一模一样 需要 多少 class codeforce sort 压缩 cin code
原文地址:https://www.cnblogs.com/Herlo/p/12224500.html