zoj 3757 Alice and Bob and Cue Sports 模拟

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757

 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>

#define MAXN 1050
#define PI acos(-1.0)
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,t) for(int i=s; i<=t; i++)
#define show(x) { cerr<<">>>"<<#x<<" = "<<x<<endl; }
#define showtwo(x,y) { cerr<<">>>"<<#x<<"="<<x<<"  "<<#y<<" = "<<y<<endl; }
using namespace std;

int n,m;
int a[MAXN],ans[2];
bool used[MAXN*10];

int main()
{
    //freopen("E:\\acm\\input.txt","r",stdin);
    while(cin>>n>>m)
    {
        memset(used,0,sizeof(used));
        a[0] = ans[0] = ans[1] = 0;
        FOR(i,1,n) scanf("%d",&a[i]);
        sort(a+1,a+n+1);

        int cur = 0,i = 1;
        while(m--)  //去第i个球
        {
            while(used[a[i]])  i++;

            int p,q,p_largest ,q_sum;
            bool target_in_p,target_in_q,cue_in_q;
            q_sum = p_largest  = 0;
            target_in_p = target_in_q = cue_in_q = 0;
            cin>>p;
            FOR(j,1,p)
            {
                int num; cin>>num;
                p_largest = max(p_largest,num);
                if(num == a[i]) target_in_p = true;
            }
            cin>>q;
            FOR(j,1,q)
            {
                int num; cin>>num;
                if(num == a[i]) target_in_q = true;
                if(num == 0)    cue_in_q = true;
                else            used[num] = true;
                q_sum += num;
            }

            bool foul = false;
            if(p == 0)
                ans[cur^1] += a[i],foul = true;
            else if( !cue_in_q && (!target_in_p || p > 1 ))
                ans[cur^1] += p_largest,foul = true;
            else if(cue_in_q)
                ans[cur^1] += p_largest,foul = true;

            if(!foul && target_in_q)
            {
                ans[cur] += q_sum;
                cur ^= 1;
            }
            else if((target_in_q &&  foul) || ( !target_in_q && q-cue_in_q > 0) )
            {
                ans[cur^1] += q_sum;
            }
            cur ^= 1;
        }
        printf("%d : %d\n",ans[0],ans[1]);
    }
}
View Code

 

posted @ 2014-03-17 15:48  等待最好的两个人  阅读(161)  评论(0编辑  收藏  举报