CSU 1268 1268: Pingpang Balls(数学啊 )
来源:互联网 发布:软件架构设计图 工具 编辑:程序博客网 时间:2024/05/18 01:16
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1268
Description
在双鱼的乒乓球上一般都会标有三星,二星,或者一星的字样,星级越高就表示球的质量越好。
星级的评定和球的重量,直径,硬度等很多因素有关,不过在这里,我们只考虑球的重量对星级评定产生的影响。
乒乓球有一个标准的重量S,如果球的重量和标准越接近,星级就会越高。具体来讲,对于球的重量和S的差的绝对值,如果小于或等于D1,那么这个球就会被标为三星,如果大于D1且小于或等于D2,那么就会被标为二星,如果大于D2且小于或等于D3就会被标为一星,如果大于D3则不对其标星(D1 < D2 < D3)。
现在给你N个乒乓球,你需要计算其中各个星级的乒乓球各有多少个。
Input
输入的第一行包含一个整数T (1 <= T <= 20),表示接下来一共有T组测试数据。
对于每组数据,第一行包含5个整数N (1 <= N <= 10), S (1 <= S <= 20), D1, D2, D3 (1 <= D1 < D2 < D3 <= 20),含义同上。接下来一行包含N个不大于20的正整数,依次描述了各个乒乓球的重量。
Output
对于每组数据,用一行输出三个整数,中间用空格隔开,分别表示N个球中三星,二星和一星的球各有多少个。
Sample Input
25 10 1 2 36 7 9 9 106 10 1 2 311 12 12 13 14 8
Sample Output
3 0 11 3 1
HINT
Source
中南大学第七届大学生程序设计竞赛
代码如下:
#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;#include <iostream>#include <string>string ss;int main(){ int n; int f[27]; char s[10]; while(~scanf("%d",&n)) { memset(f,0,sizeof(f)); memset(s,0,sizeof(s)); char a, b; for(int i = 0; i < n; i++) { cin>>ss; if(ss == "print") { cin>>a; printf("%d\n",f[a-'a']); } else if(ss == "mov") { cin>>a>>b>>s; if(s[0]>='0' && s[0] <= '9') { int num = 0; int len = strlen(s); for(int j = 0; j < len; j++) { num = num*10+s[j]-'0'; } f[a-'a'] = num; } else f[a-'a'] = f[s[0]-'a']; } else if(ss == "add") { cin>>a>>b>>s; if(s[0]>='0' && s[0] <= '9') { int num = 0; int len = strlen(s); for(int j = 0; j < len; j++) { num = num*10+s[j]-'0'; } f[a-'a'] += num; } else f[a-'a'] += f[s[0]-'a']; } else if(ss == "sub") { cin>>a>>b>>s; if(s[0]>='0' && s[0] <= '9') { int num = 0; int len = strlen(s); for(int j = 0; j < len; j++) { num = num*10+s[j]-'0'; } f[a-'a'] -= num; } else f[a-'a'] -= f[s[0]-'a']; } } } return 0;}
1 0
- CSU 1268 1268: Pingpang Balls(数学啊 )
- coj 1268:Pingpang Balls
- Pingpang Balls
- CSU 1407: 最短距离(数学啊 )
- CSU 1410: 整数转换(数学啊 )
- CSU 1265: Dice (数学啊 )
- CSU 1270: Swap Digits(数学啊 )
- CSU 1271: Brackets Sequence(数学啊 )
- csu 1759 Triangle(数学)
- CSU 1505: 酷酷的单词(数学啊)
- CSU 1507: 超大型LED显示屏(数学啊)
- CSU 1409: 集合的并(数学啊 )
- CSU 1266: Divisible by 11 (数学啊 )
- CSU-1268
- Balls Rearrangement(hdu4611,模拟+数学)
- HDU 4710 Balls Rearrangement (纯数学)
- hdu 5810 Balls and Boxes (数学)
- hdu5810 Balls and Boxes(数学)
- CSU 1267: Operation(模拟啊 )
- 【大话】之观察者模式
- hge 的一些笔记
- linux下mysql连接异常
- thrift总结(python)
- CSU 1268 1268: Pingpang Balls(数学啊 )
- unity3d NGUI 按钮的图片未点击却跳回默认的问题
- Transformer入门教程(四)Generate Categories报错TR2703
- 自己做的一个后台管理员登陆界面 .cshtml
- 错误: 隐式声明函数‘kmalloc’ [-Werror=implicit-function-declaration]
- Android和java的Post请求
- ubuntu 14.10+gitweb配置
- 前端网页性能优化最佳实践
- struct pollfd