劫持选举 EOJ 3535(随机)

传送门

题解:刚学了随机。。。立刻去搞之前一场比赛的题目

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
#include <iomanip>
#include <set>
#include<ctime>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0)
const double Pi=3.14159265;
const double e=2.71828182;
const int N=2e3+5;
const ull base=163;
const int INF=0x3f3f3f3f;
using namespace std;
int a[N],b[N];
int p[N];
int main(){
    fio;
    int n;
    cin>>n;
    srand(time(0));
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    while(clock()<1.7*CLOCKS_PER_SEC){
        ll l1=0,l2=0,r1=0,r2=0;
        int tot=0,cnt=0;
        for(int i=1;i<=n;i++){
            int x=rand()%2;
            if(x==0)p[i]=0,l1+=a[i],l2+=b[i],tot++;
            else p[i]=1,r1+=a[i],r2+=b[i],cnt++;
        }
        if(l1>l2&&r1>r2){
            cout<<tot<<" "<<cnt<<endl;
            for(int i=1;i<=n;i++){
                if(p[i]==0)cout<<i<<" ";
            }
            puts("");
            for(int i=1;i<=n;i++){
                if(p[i]==1)cout<<i<<" ";
            }
            return 0;
        }
    }
    cout<<"Game Over!"<<endl;
    return 0;
}

 

posted @ 2018-04-05 22:58  采蘑菇的小西佬  阅读(140)  评论(0编辑  收藏  举报