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> # ...
随机推荐
- NABCD(网上投票系统)
网上投票系统 N(need) 投票这件事情,在所有事情上都可能用得到,在互联网的影响下,投票的范围变得越来越广,比如在商业的里,往往要做市场分析,那么在互联网这个大的前提下,用网上投票系统来获取用户的 ...
- 《TCP/IP 详解 卷1:协议》第 10 章:用户数据报协议
引言 UDP 稍微扩展了IP协议,使得包可以在进程间传送,而不仅仅是在主机件.--<CSAPP> IP 数据报是指 IP 层端到端的传输单元.分组(packet)是 IP 层和链路层的传输 ...
- Xcode7~8版本过渡导致的问题
现有项目是早期Xcode7编写的,一直到现在还是使用Xcode7编写.近期一位用户手机下载App出现闪退现象,该用户手机系统(iPhone 6 iOS8.1.2)经查实是由于CoreFoundatio ...
- T4模板_T4基本结构
T4文本模板由 指令块.文本块.控制块 组成. 一. 指令块(MSDN文本模板指令) 指令块以@开头,基本的指令块包括<#@ template #> .<#@ parameter# ...
- 定时任务中的备份不同的数据库中的所有的表,每个表使用单独的sql备份文件
#! /bin/bash # 指定用户 USER=root # 指定密码 PASS=123456 # 指定主机地址 HOST=localhost # 指定备份的目录 BACKUP=/backup/sq ...
- 关于.net服务启动注册到zookeeper,但是注册节点20分钟自动消失解决办法
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,作用简单描述就是相当于一个中介,服务提供者将服务注册到zk,服务调用者直接从zk获取,zk的作用就是协调 最近碰到公 ...
- 如何修改eclipse下注释的颜色
修改注释颜色:window -- preferences -- java --editor --syntax coloring -- comments 中的前两个就是修改注释颜色的.点击右边的colo ...
- Windows下获取文件的md5码的方法
1.certutil 命令简介 本来想找一个工具 算一个文件的md5 或者是sha 值来着. 找到一个说法是 可以使用 windows 自带的命令行来处理 具体命令 certutil -hashfil ...
- [转帖学习]Howto Shrink a Thin Provisioned Virtual Disk (VMDK)
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) Posted by fgrehl on November 24, 2014Leave a com ...
- 【Nginx笔记】 fastcgi_param解释
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径 fastcgi_param QUERY_STRI ...