ZOJ 3757 Alice and Bob and Cue Sports

来源:互联网 发布:水化学分析软件 编辑:程序博客网 时间:2024/06/05 17:06
ZOJ Problem Set - 3757
Alice and Bob and Cue Sports

Time Limit: 2 Seconds Memory Limit: 65536 KB

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 32 3 51 21 21 31 51 31 3

Sample Output

2 : 8

Author: YU, Xiaoyao
Source: ZOJ Monthly, March 2014

题目思路:根据题目意思直接模拟就可以了,英文题目比各大博客中的中文翻译写的更清楚

#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <sstream>#include <stack>#include <map>#include <queue>using namespace std;long long num[200000];long long hit[101000];long long in[101000];long long w[101000];//每个球的重量int main(){long long n,m; while(cin >> n >> m){for(int i=1;i<=n;i++)cin >> w[i];long long ans[2]={0};long long now = 0;sort(w+1,w+1+n);//排序后找出目标球long long pot = 1;//刚开始的目标球就是W【POT】 memset(num,0,sizeof(num));while(m--){long long len_hit,len_in;cin >> len_hit;long long sum=0;bool flag1=0;bool flag2 = 0;for(int i=0;i<len_hit;i++){cin >> hit[i];if(hit[i]==w[pot] && len_hit==1)flag1 = 1;}cin >> len_in;for(int i=0;i<len_in;i++){cin >> in[i];if(in[i]==0)flag2 = 1;num[in[i]]=1;sum+=in[i];}sort(hit,hit+len_hit);sort(in,in+len_in);if(len_hit==0) ans[1-now]+=w[pot];else if(flag2==0&&flag1==0){ans[1-now] +=sum;ans[1-now]+=hit[len_hit-1];}else if(flag2&&len_hit){ans[1-now] +=sum;ans[1-now]+=hit[len_hit-1];}//以上是犯规的处理。 else if(num[w[pot]]==0) ans[1-now]+=sum;//如果不犯规而且目标球进洞了,如下else else {ans[now]+=sum;now = 1-now;}while(num[w[pot]])pot++;now = 1-now;} cout<<ans[0]<<" : "<<ans[1]<<endl;}return 0;} 


0 0
原创粉丝点击