ZOJ 3757 Alice and Bob and Cue Sports
来源:互联网 发布:水化学分析软件 编辑:程序博客网 时间:2024/06/05 17:06
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.
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;}
- zoj 3757 Alice and Bob and Cue Sports
- zoj 3757 Alice and Bob and Cue Sports 模拟
- zoj 3757 Alice and Bob and Cue Sports
- ZOJ 3757 Alice and Bob and Cue Sports [模拟]
- ZOJ 3757 Alice and Bob and Cue Sports
- ZOJ 3757 Alice and Bob and Cue Sports(模拟题)
- ZOJ3757:Alice and Bob and Cue Sports(模拟)
- ZOJ Problem Set - 3655 Alice and Bob
- ZOJ 3666 Alice and Bob(博弈)
- zoj 3666 Alice and Bob , SG函数
- ZOJ 3666 Alice and Bob 基础博弈
- Alice and Bob
- 2683. Alice and Bob
- 1798. Alice and Bob
- hdu4268 Alice and Bob
- HDU4268 Alice and Bob
- Alice, Bob and Chocolate
- hdu4268 Alice and Bob
- HDOJ-1667/TJU4106 The Rotation Game(IDA*搜索)
- 笔记1:MATLAB语言基础
- c编程心得
- Nginx安装及配置文件nginx.conf详解
- aircrack和reaver破解路由器PIN码
- ZOJ 3757 Alice and Bob and Cue Sports
- 网站流量统计,java+jsp 获取访客浏览器,真实ip,操作系统,来源
- 懒人必备 之 Android效率开发框架
- Java中序列化的serialVersionUID作用
- 数的长度
- [Mac] mac linux 多线程下载利器 axel
- 除法表达式
- Java tutorial 5
- 闭包的概念、形式与应用