ZOJ 3757 Alice and Bob and Cue Sports

原创 2015年07月10日 19:41:47
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 these m 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 of n 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 integer p, 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 are q 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", where AP 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

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;
	
} 


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

相关文章推荐

ZOJ3757: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 Poo...

ZOJ 3757 Alice and Bob and Cue Sports(模拟题)

A - Alice and Bob and Cue Sports Time Limit:2000MS     Memory Limit:65536KB     64bit IO Forma...

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

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

ZOJ - 3529 K - A Game Between Alice and Bob sg函数~

sg函数打表。一开始我是这么打的表。天真以为nlogn应该可以。但是跑了很久。。。。 void gsg() { memset(sg, 0, sizeof(sg)); sg[0]=0; for ...

zoj3529 A Game Between Alice and Bob 质因子个数NIM

A Game Between Alice and Bob Time Limit: 5 Seconds      Memory Limit: 262144 KB Alice and B...

ZOJ 3529 A Game Between Alice and Bob (数论+SG博弈)

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 题意:有N堆石头,...

ZOJ 3666 Alice and Bob 基础博弈

题意: 在一个DAG上的一些din点,每次轮流移动

ZOJ Problem Set - 3666 Alice and Bob(SG)

Alice and Bob Time Limit: 2 Seconds      Memory Limit: 65536 KB "Alice and Bob take turns ch...

ZOJ Problem Set - 3655 Alice and Bob

The 2012 ACM-ICPC Asia Changchun Regional Contest-A 题目大意就是 选出长度为A的一段,是的其中所有长度为A-B的子段的最小值最大。 参见...

HDU 4111Alice and Bob(博弈+记忆化)

题意:有n堆石子,一次可以拿走一个石子,或者把一堆石子放在另一个石子上。不能再次操作的人输Alice先拿。问谁赢 思路:当石子个数大于1时,可以把他们放到一堆里+1次的操作数。石子数为1时,单独考虑...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)