华中农业大学校赛--c The Same Color
Problem C: The Same Color
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 993 Solved: 595
[Submit][Status][Web Board]
Description
Diao Yang has many balls with different colors. Today he wants to divide his balls into two groups. But he does not know how to divide. Then Diao Ze gives him a suggestion: first you choose a ball and put it into the first group. Then from the second ball, if the color of the ball is same to the last ball you has chosen, then you put the ball into the other group. Otherwise you put the ball into the same group with the last ball. Diao Yang thinks it is OK.
Then the problem is, Diao Yang wants to know the product of the number of two groups’ balls. Can you help him?
Input
The first line contains an integer T, indicating the number of test cases.
In each test case, there are several lines, each line contains only one string with lowercas, indicating the color of the ball Diao Yang has chosen currently. Diao Yang will stop choosing when the string is equal to “END”. Note that the string “END” does not mean a color.
You can assume that there are at most 100 lines in each test case and each string has at most 10 letters.
Output
For each test case, output the answer in a line.
Sample Input
3
yellow
yellow
pink
red
red
green
END
blue
black
purple
purple
END
rose
orange
brown
white
END
Sample Output
9
3
0
HINT
In the first test case, the color of the first group’s balls are yellow, red, green, 3 balls in total. The color of the second group’s balls are yellow, pink, red, 3 balls in total too. So the product is 3×3=9.
In the second test case, the answer is 3×1=3 and in the third test case the answer is 4×0=0.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int g[];
g[]=;
g[]=;
char a[];
char b[];
scanf("%s",b);
int t=;
if(strcmp(b,"END")==)
{
printf("0\n");
continue;
}
scanf("%s",a);
while(strcmp(a,"END")!=)
{
if(strcmp(a,b)==)
{
t=-t;
g[t]++;
}
else
{ g[t]++;
}
strcpy(b,a);
scanf("%s",a);
}
printf("%d\n",g[]*g[]);
}
return ;
}
水题,只是考虑第一个颜色就是END就可以了。wa惨了
华中农业大学校赛--c The Same Color的更多相关文章
- 华中农业大学校赛 I Catching Dogs
Catching Dogs Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1140 Solved: 298[Submit][Status][Web B ...
- A喝酒(北京林业大学校赛)
http://www.jisuanke.com/contest/1410 王大钉喜欢喝酒,存货都喝完了,他就去楼下买,正好楼下的商店为了响应学校的 ACM 校赛推出了优惠活动:凡是在本店买的啤酒,喝完 ...
- NOI.ac模拟赛20181021 ball sequence color
T1 ball 可以发现每次推动球时,是将每个球的位置 −1-1−1 ,然后把最左边的球放到 P−1P-1P−1 处. 记个 −1-1−1 次数,再用set维护就好了. #include <bi ...
- 北京师范大学校赛C
https://www.nowcoder.com/acm/contest/submit/0dff89ad7b8444719df155d507f3e1dd?ACMContestId=3&tagI ...
- Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)
Problem H: Heaps Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 48 Solved: 9[Submit][Status][Web Bo ...
- 浙江工业大学校赛 小M和天平
小M和天平 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 浙江工业大学校赛 XiaoWei的战斗力
XiaoWei的战斗力 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 浙江工业大学校赛 画图游戏 BugZhu抽抽抽!!
BugZhu抽抽抽!! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 2016广东工业大学校赛 E题 GDUT-oj1173
Problem E: 积木积水 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元 ...
随机推荐
- GPGPU OpenCL 获取设备信息
在使用OpenCL编程中,需要对GPU设备的底层理解,这样才能更好的进行代码优化. 比如计算单元CU数量,每个CU的执行单元PE数量,每个CU中的共享内存大小等等.只有了解了这些才能更好的使用共享内存 ...
- 缩进与对齐——正确地使用Tab和空格
写代码时大家都会使用缩进(indentation)和对齐(alignment),这是两个相关而又不同的概念,两者都是为了提高代码的可读性.缩进出现在一行的最左边,目的是明显地区分开包含与被包含的代码: ...
- (1)风色从零单排《C++ Primer》 一个简单的c++程序
从零单排<C++ Primer> --(1)一个简单的c++程序 本次学习收获 0.写在前面 风色以前上过C++的课程,然而当时并没有认真去学,基本不能使用c++来作项目开发. 这次又一次 ...
- (算法)二叉树的第m层第k个节点
题目: 给定以下二叉树: struct node { node *left, *right; int value; }; 要求编写函数 node* foo(node *node, unsigned i ...
- cscope无法索引代码树之外的软链接
http://blog.csdn.net/sudolee/article/details/9052291 背景:为什么非要使用cscope?不用ctags? 尽管ctags可以索引软链接,但是,cta ...
- js正则表达式test方法、exec方法与字符串search方法区别
1.正则表达式test方法 test() 方法用于检测一个字符串是否匹配某个模式 返回值: 如果字符串 string 中含有与 RegExpObject 匹配的文本,则返回 true,否则返回 fal ...
- OpenERP Web Client设置闲置有效时间
在Web Client端使用OpenERP时,默认的cookie有效时间是浏览器的当前作业窗口,这样就是说只要你不关闭浏览器,不管闲置多长时间,当前的连线都是有效的.这样就会有安全问题,如果你忘了登出 ...
- 数据库选型之MySQL(固态硬盘)
刘勇 Email: lyssym@sina.com 本博客记录作者在工作与研究中所经历的点滴,一方面给自己的工作与生活留下印记,另一方面若是能对大家有所帮助,则幸甚至哉矣! 简介 鉴于高频中心库 ...
- asp.net MVC 视图文件(cshtml/vbhtml)变更编译过程示范
更改cshtml文件的时候 并不会触发程序重新启动,而是进入了编译状态 csc.exe进程启动. 非阻塞的方式进行等待,延时等待. 示范程序:http://pan.baidu.com/s/1skDY ...
- 多语言 SEO
https://productforums.google.com/forum/?hl=zh-CN#!topic/webmaster-zh-cn/I0MMsm737pc