现在的位置: 首页 > 综合 > 正文

zoj 3757 Alice and Bob and Cue Sports

2014年11月08日 ⁄ 综合 ⁄ 共 1558字 ⁄ 字号 评论关闭

模拟题,一定要根据题目意思!

#include <iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>

using namespace std;
typedef struct ball{
  int no,in; //球的编号,球是否在洞内
}Ball;

Ball goal_ball[1010];
int b1[1010],b2[1010];
int n,m;

int cmp(const void * a, const void * b)
{
    Ball* _a = (Ball*)a;
    Ball* _b = (Ball*)b;
    return _a->no - _b->no;
}

int get_goal() //查找目标球
{
    for(int i = 0;i < n;i++)
    {
        if(!goal_ball[i].in)
        {
            return goal_ball[i].no;
        }
    }
}

int main()
{
    int ans[2] ;
    while(scanf("%d %d",&n,&m)!= EOF)
    {
        ans[0] = 0,ans[1] = 0;
        int cur = 0; //0表示Alice击打,1表示Bob
        for(int i = 0; i < n;i++)
        {
            scanf("%d",&goal_ball[i].no);
            goal_ball[i].in = 0;
        }
        qsort(goal_ball,n,sizeof(Ball),cmp);
        int num1,num2;
        for(int i = 0; i < m;i++)
        {
            scanf("%d",&num1); //击球数
            for(int j = 0;j < num1;j++)
            {
                scanf("%d",&b1[j]);
            }
            sort(b1,b1 + num1);
            scanf("%d",&num2); //进洞的球数
            for(int j = 0;j < num2;j++)
            {
                scanf("%d",&b2[j]);
            }
            sort(b2,b2 + num2);
            int goal = get_goal();
            int pen = 0; //没犯规
            if(num1 == 0) //没有击中球
            {
                cur = 1 - cur;
                ans[cur] += goal;
                pen = 1;
            }
            else if(num1 > 0 && num2 > 0 && b2[0] == 0) //击中球且母球入袋
            {
                cur = 1 - cur;
                ans[cur] += b1[num1 - 1];
                pen = 1;
            }
            else if(num1 > 1 || (num1 == 1 && b1[0] != goal)) //击中多余一个球或击中的不是目标球
            {
                 cur = 1 - cur;
                 ans[cur] += b1[num1 - 1];
                 pen = 1;
            }
            else if (num2 == 0) //没犯规且没进球
            {
                 cur = 1 - cur;
            }
            if(num2 > 0) //进洞了
            {

                if(pen) //犯规
                {
                     for(int j = 0 ; j < num2;j++)
                     {
                         ans[cur] += b2[j];
                         int temp = b2[j];
                         for(int k = 0;k < n;k++)
                         {
                             if(goal_ball[k].no == temp)
                                 goal_ball[k].in = 1;
                         }
                     }
                }
                else if(b2[0] != goal)//进洞的球中没有目标球
                {
                    cur = 1 - cur;
                    for(int j = 0 ; j < num2;j++)
                     {
                         ans[cur] += b2[j];
                         int temp = b2[j];
                         for(int k = 0;k < n;k++)
                         {
                             if(goal_ball[k].no == temp)
                                 goal_ball[k].in = 1;
                         }
                     }
                }
                else //没犯规并且目标球进洞
                {
                    for(int j = 0 ; j < num2;j++)
                    {
                         ans[cur] += b2[j];
                         int temp = b2[j];
                         for(int k = 0;k < n;k++)
                         {
                             if(goal_ball[k].no == temp)
                                 goal_ball[k].in = 1;
                         }
                     }
                }
            }
        }

        printf("%d : %d\n",ans[0],ans[1]);
    }
    return 0;
}

抱歉!评论已关闭.