• ZOJ 3757 Alice and Bob and Cue Sports [模拟]


    Alice and Bob both love playing games. Now, Alice and Bob are playing a cue sport like Nine-ball Pool. Two players move in turn. A move is that one player use the cue ball to hit the target ball for pocketing the target ball. At the beginning of game, there are one cue ball and n object balls. Each object ball has a number (a positive integer) on it, and no two object balls have the same number. In a move, the target ball is a object ball still on the table with the smallest number. If the player does the following things in a move, a foul is called and a penalty point is added to the opposite's point:

    • Cue ball do not hit any object ball. Penalty: the number of target ball.
    • Cue ball is not pocketed and hit at least one ball, but do not hit target ball first or hit more than one object ball first at the same time. Penalty: the largest number of ball in the first hit balls.
    • Cue ball is pocketed and hit at least one ball. Penalty: the largest number of ball in the first hit balls.
    If the player pockets the target ball without a foul, a point will be added to the player's points, which is the sum of numbers of the ball pocketed in this move, and the player can make another move. But, if the player pockets the target ball with a foul or pockets at least one object ball not including the target ball, this point will be added to the opposite's points. If cue ball is pocketed, it will be pull out of the pocket and put on the table again while object balls will not be put on the table again after they are pocketed, even if the player pocketed them with a foul.

    Now given n object balls and m moves, Bob wants to write a program to calculate the final points of Alice and him after thesem moves. Because of Lady's first Rule, Alice always moves first.

    Input

    There are multiple cases. The first line of each case consists of two integers,n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000), as described above. The second line consists ofn positive integers. Each integer ai means the number of ith object ball (1 ≤ai ≤ 10000). There are 2m lines followed. The (2i-1)th and (2i)th lines describe the ith move. The (2i-1)th line first includes an integerp, meaning cue ball hits p balls first. There are p integers followed in the same line, describing the hit balls. The(2i)th line first includes an integer q, meaning there areq balls pocketed. There are q integers followed in the same line, describing the pocketed balls (0 means cue ball). It's guaranteed that there is no impossible data.

    Output

    For each case, output one line as the format: "AP : BP", whereAP means Alice's points and BP means Bob's points.

    Sample Input

    3 3
    2 3 5
    1 2
    1 2
    1 3
    1 5
    1 3
    1 3
    

    Sample Output

    2 : 8
    

    真考验英语水平。。。看了好久,中间还搞错了一次 >_<

    题意:两个人打台球,Alice先,然后按规则轮流进行。台面上除了白球还有n个球,每个球有一个唯一编号(同时也是打进该球的得分)(白球编号为0)。在一次击球中,目标球是台面上编号最小的球,如果选手犯规,则要给对手加上相应的分。

    犯规有以下几种(括号中是相应的罚分):

    1.白球没击中任何球(目标球得分)

    2.白球没进袋,且击到至少一球,但没有首先击到目标球 或 同时首先击中多个球。 (击中的球的最大编号)

    3.白球进袋,且至少击到一球。 (击中的球的最大编号)

    如果选手没犯规并且打进目标球,则给该选手加上进的球的得分和(可以同时打进多个球),并且该选手可以继续击球(只有这种情况可以连续击球)。如果选手犯规进球,或者有进球但没有进目标球,则得分加到对手身上。 白球进袋还会拿出来,其他球进袋不再拿出(不管是不是犯规打进的)。

    注意一点,如果击球选手又犯规又进球,则需要给对手加两次分,即犯规罚分和进球得分。

    输入,第一行n和m。下一行n个数表示n个球的编号。下面还有2m行,每两行表示一次击球。第一行是首先击中的球,第二行是打进的球。

    最后输出两个人的比分。


    题目搞懂后按规则一步步判断就好了,细心。



    #include<cassert>
    #include<algorithm>
    #include<cmath>
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<set>
    #include<queue>
    #include<map>
    using namespace std;
    #define rep(i,f,t) for(int i = (f), _end = (t); i <= _end; ++i)
    #define clr(c,x) memset(c,x,sizeof(c));
    #define debug(x) cout<<"debug  "<<x<<endl;
    const int INF = 0x3f3f3f3f;
    typedef long long int64;
    
    inline int RD(){
        int res;
        scanf("%d",&res);
        return res;
    }
    
    #define Rush for(int casn = RD(), cas = 1; cas <= casn; ++cas)
    
    //*******************************************************************************
    
    typedef set<int> Set;
    Set ball;
    int sc[2];
    const int maxn = 1010;
    
    void init(){
        ball.clear();
        sc[0] = sc[1] = 0;
    }
    int main(){
        int n,m;
        while(scanf("%d%d",&n,&m) == 2){
            init();
            rep(i,1,n){
                int bb = RD();
                ball.insert(bb);
            }
            int now = 0; //Alice
            int next = 1; //Bob
            while(m--){
                int p = RD();
                int target = *ball.begin();
    
                int maxhit = target;
                rep(j,1,p){
                    int tmp = RD();
                    maxhit = max(maxhit,tmp);
                }
    
                int score = 0;
                bool tgin = false; //目标球进袋
                bool foul = false;
    
                int q = RD();
                while(q--){
                    int tmp = RD();
                    if(tmp == 0)foul = true; //白球进袋
                    else if(tmp == target)tgin = true; //目标球进袋
    
                    ball.erase(tmp);
                    score += tmp;
                }
    
                //没打到球 或 打到非目标球(maxhit > target) 或 白球进袋
                if(p == 0 || maxhit > target || foul){
                    foul = true; //犯规,得分都归对方
                    sc[next] += maxhit; //先把犯规的罚分给对方加上
                }
                if(!tgin)foul = true;
    
                if(foul){
                    sc[next] += score;
                    swap(now,next);
                }else{
                    sc[now] += score;
                }
            }
    
            printf("%d : %d
    ",sc[0],sc[1]);
        }
    
        return 0;
    }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    nyoj 115------城市平乱( dijkstra // bellman )
    nyoj-----284坦克大战(带权值的图搜索)
    nyoj-----42一笔画问题
    hdu-------1081To The Max
    nyoj------170网络的可靠性
    HDUOJ-------1052Tian Ji -- The Horse Racing(田忌赛马)
    初学Java之Pattern与Matcher类
    初学java之StringBuffer类的常用方法
    初学java之大数处理
    hdu---1024Max Sum Plus Plus(动态规划)
  • 原文地址:https://www.cnblogs.com/DSChan/p/4861992.html
Copyright © 2020-2023  润新知