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> # ...
随机推荐
- Gradle入门(2):构建简介
基本概念 在Gradle中,有两个基本概念:项目和任务.请看以下详解: 项目是指我们的构建产物(比如Jar包)或实施产物(将应用程序部署到生产环境).一个项目包含一个或多个任务. 任务是指不可分的最小 ...
- 安装mysql后遇到的一些问题
我们安装好了mysql(cnetos7上是安装mariadb)后,出现如下图所示的问题,我们可以用netstat -lntup查看以下服务器的端口,mysql的端口一般默认为 3306,查看服务是否启 ...
- PHP 多进程开发
pcntl_fork(); https://blog.csdn.net/wujiangwei567/article/details/77006724 https://blog.csdn.net/qq_ ...
- 二叉树 Java 实现 前序遍历 中序遍历 后序遍历 层级遍历 获取叶节点 宽度 ,高度,队列实现二叉树遍历 求二叉树的最大距离
数据结构中一直对二叉树不是很了解,今天趁着这个时间整理一下 许多实际问题抽象出来的数据结构往往是二叉树的形式,即使是一般的树也能简单地转换为二叉树,而且二叉树的存储结构及其算法都较为简单,因此二叉树显 ...
- Java多线程(五) —— 线程并发库之锁机制
参考文献: http://www.blogjava.net/xylz/archive/2010/07/08/325587.html 一.Lock与ReentrantLock 前面的章节主要谈谈原子操作 ...
- 记一次java程序out of memory问题
在一个比较大批量的pdf转String项目中遇到了:java.lang.OutOfMemoryError: Java heap space错误 第一反应肯定是程序没有写好,大量循环时没有把程序中没有用 ...
- PHP-从零开始使用Solr搜索引擎服务(下)
前言: 原文地址: http://www.cnblogs.com/JimmyBright/p/7156085.html 前面在配置完成Solr服务之后,在浏览器上可以打开Solr的管理界面,这个界面几 ...
- Timus 1005 解题报告
题目链接 http://acm.timus.ru/problem.aspx?space=1&num=1005 题目大意 给你一堆石头,现在需要你将这堆石头分成两堆,要求两堆石头的重量相差最小, ...
- CF662C Binary Table 【状压 + FWT】
题目链接 CF662C 题解 行比较少,容易想到将每一列的状态压缩 在行操作固定的情况下,容易发现每一列的操作就是翻转\(0\)和\(1\),要取最小方案,方案唯一 所以我们只需求出每一种操作的答案 ...
- 退出Android程序时清除所有activity的实现方法
思路: 1. 自定义ActivityList管理类,添加删除维护该list; 2.Activity Stack 类似上面: 3.singleTask定义一个Activity为该启动模式,然后当返回时, ...