标签:shuff signed long freopen div cst include namespace iostream
有种迷一样的讽刺效果
每个城市有1000头牛,然后你现在知道对于自己政党每个城市的选票,把城市划分成三个州,保证在至少两个州内获胜
找出前2K大的然后random_shuffle,直到前K个加起来和后K个加起来都满足超过半数也就是K × 500
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
//#define ivorysi
#define MAXN 305
#define eps 1e-8
#define pb push_back
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int K;
int a[MAXN],sum,id[MAXN];
bool cmp(int c,int d) {
return a[c] > a[d];
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
srand(20020421);
scanf("%d",&K);
for(int i = 1 ; i <= 3 * K ; ++i) {id[i] = i;scanf("%d",&a[i]);}
sort(id + 1,id + 3 * K + 1,cmp);
for(int i = 1 ; i <= 2 * K ; ++i) sum += a[id[i]];
while(1) {
random_shuffle(id + 1,id + 2 * K + 1);
int S = 0;
for(int i = 1 ; i <= K ; ++i) S += a[id[i]];
if(S > K * 500 && sum - S > K * 500) {
for(int i = 1 ; i <= 3 * K ; ++i) {
printf("%d\n",id[i]);
}
return 0;
}
}
}
标签:shuff signed long freopen div cst include namespace iostream
原文地址:https://www.cnblogs.com/ivorysi/p/9045583.html