您的位置:首页 > 其它

D. Mike and distribution 首先学习了一个玄学的东西

2017-04-22 23:45 393 查看
http://codeforces.com/contest/798/problem/D

D. Mike and distribution

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integersA = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length n each which he uses to ask people some quite peculiar questions.

To test you on how good are you at spotting inequality in life, he wants you to find an "unfair" subset of the original sequence. To be more precise, he wants you to select k numbers P = [p1, p2, ..., pk] such that 1 ≤ pi ≤ n for1 ≤ i ≤ k and elements in P are distinct. Sequence P will represent indices of elements that you'll select from both sequences. He calls such a subset P "unfair" if and only if the following conditions are satisfied: 2·(ap1 + ... + apk)is greater than the sum of all elements from sequence A, and 2·(bp1 + ... + bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + 20;
struct Node {
int a, id;
bool operator < (const struct Node & rhs) const {
return a > rhs.a;
}
}a[maxn];
int b[maxn];
vector<int>ans;
void work() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i].a;
a[i].id = i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
sort(a + 1, a + 1 + n);
int sel = n / 2 + 1;
ans.push_back(a[1].id);
for (int i = 2; i <= n; i += 2) {
int want = a[i].id;
if (i + 1 <= n && b[want] < b[a[i + 1].id]) {
want = a[i + 1].id;
}
ans.push_back(want);
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); ++i) {
cout << ans[i] << " ";
}
}

int main() {
#ifdef local
freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return 0;
}


View Code
2017-4-23 22:22:03

要开始补sg函数(博弈)和构造题。先复习下字符串准备省赛。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐