CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY
#include<cstdio>
#include<algorithm> using namespace std; char s[]; int main()
{
int sumA,sumB;
while(scanf("%s",s+)!=EOF)
{
sumA=sumB=;
int i;
for(i=;i<=;++i)
{
if(i&)
{
if(s[i]=='')
{
sumA++;
if(sumA-sumB>(-i+)/) break;
}
else
{
if(sumB-sumA>(-i)/) break;
}
}
else
{
if(s[i]=='')
{
sumB++;
if(sumB-sumA>(-i)/) break;
}
else
{
if(sumA-sumB>(-i)/) break;
}
}
}
if(i!=)
{
printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
printf(" %d\n",i);
continue;
}
for(;i<=;i+=)
{
if(s[i]=='') sumA++;
if(s[i+]=='') sumB++;
if(sumA!=sumB) break;
}
if(i!=)
{
printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
printf(" %d\n",i+);
continue;
}
puts("TIE");
}
}
Read problems statements in Mandarin chinese, Russian andVietnamese as well.
Chef likes to play football with his friends. They played a number of matches and surprisingly, every match was a tie, so they decided to declare the winner with penalty shoot-out. As they didn't know the penalty shoot-out rules, they just decided to take 20 shots alternatively (each team takes 10 shots).
One day, Chef's friend Shivam heard about the matches and got confused. Later Shivam went to Chef and his friends and explained the shoot-out rules. Then, they all decided to calculate and once again declare the winner of each match as per the standard football penalty shoot-out rules.
The standard rules are:
- The teams will take shots alternatively.
- At first, each team will take five penalty shots.
- If one team does not have more goals than the other after these five shots, the shoot-out will proceed to sudden death.
- In between of first 10 kicks, If one team has an advantage over other which can't be compensated, then the team with the advantage will be declared winner at that instant i.e. before the completion of 10 kicks.
- In sudden death, each team will take at most five more shots. Everytime after both teams take a shot, the following rule is used: if one team has scored more goals than the other, that team is the winner.
- If each team has taken 10 shots and the winner still cannot be decided, the result will be a tie.
The result of the shoot-out for each game is given as a binary string where '1' represents GOAL and '0' represents MISS. Chef's team always starts first. Keep in mind that the teams alternate when taking the shots — the first character corresponds to the first shot of Chef's team, the second character to the first shot of the opposing team, the third character to the second shot of Chef's team etc.
As there are many matches to evaluate, Chef and his friends are unable to do so and they require your help. You have to tell them the winner of each match.
If a match ended in a tie, print "TIE". If Chef's team won, print "TEAM-A", otherwise print "TEAM-B". Also, if the match didn't end in a tie, print the minimum number of kicks required to decide the result, so that they can also know how much times they shot in vain.
Note: Input/Output files are large, use fast reading/writing methods
Input
- The input consists of several lines.
- Each line contains the record of the shoot-out for a single match in the form of a binary string where '1' represents GOAL and '0' represents MISS, starting from Chef's team alternatively.
Output
On each line, print the winner of the corresponding match ("TEAM-A" or "TEAM-B") and the number of shots required to decide the result, separated by a space. If there is no winner, print "TIE" instead.
Constraints
- each line contains a 20-bit binary string
- number of matches ≤ 106
Subtasks
Subtask 1 (20 points):
- the first 10 kicks always result in a tie, i.e. the shoot-out will always go to sudden death
- number of matches ≤ 103
Subtask 2 (80 points): original constraints
Example
Input: 10100101111011111111
00000000000000000000
01011101110110101111 Output: TEAM-A 12
TIE
TEAM-B 7
Explanatio
CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out的更多相关文章
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
随机推荐
- 微服务注册与发现 —— eureka
基础概念 在微服务系统中,服务的注册和发现是第一步,常用的有: Eureka:https://github.com/Netflix/eureka Zookeeper:https://zookeeper ...
- 09_Java面向对象_第9天(类、封装)_讲义
今日内容介绍 1.面向对象思想 2.类与对象的关系 3.局部变量和成员变量的关系 4.封装思想 5.private,this关键字 6.随机点名器 01面向对象和面向过程的思想 A: 面向过程与面向对 ...
- [二叉树建树]1119. Pre- and Post-order Traversals (30) (前序和后序遍历建立二叉树)
1119. Pre- and Post-order Traversals (30) Suppose that all the keys in a binary tree are distinct po ...
- redux相关专业名词及函数提要
redux: 用来管理react app 状态(state)的一个架构. store: 通过createStore()创建,用来存放state,与react app是完全分离的.createStore ...
- css border 制作三角形
border 边框 上三角 是只有上面的border 有颜色,其余的边框都是tranparents,下三角只有下面的border 有颜色,其余的边框都是tranparents,左三角只有左面的bord ...
- MYSQLD_OPTS修改
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables";
- go 面试题总结
1.什么是goroutine,他与process, thread有什么区别? 2. 什么是channel,为什么它可以做到线程安全? 3. 了解读写锁吗,原理是什么样的,为什么可以做到? 4. 如何用 ...
- ByValue和ByPropertyName的区别
ByValue 以Get-Service命令为例,它的帮助文件中关于-Name参数是这样解释的: 1. "WinRM" | Get-Service 2. "Trusted ...
- Art & Material
Art(Android runtime)模式伴随Android 4.4发布.相对于Dalvik模式来说,Art模式改善了Android程序的性能. Material Design伴随Android 5 ...
- C# 抽签小程序
设计背景 设置一个Excel名单表,对名单进行随机抽取. 设计思路 使用Timer定时器,运行定时器进行名单随机滚动,停止定时器获得抽签结果 相关技术 随机数 Excel读取/导出 XML文档读写 相 ...