printf(\,sum); sum=0; } }
[ Copy to Clipboard ] [ Save to File]
1095 A+B for Input-Output Practice
(VII)
Problem Description
Your task is to Calculate a + b.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
Sample Input
1 5 10 20
Sample Output
6 30
Author
lcy
Recommend
JGShining
解答:
#include
int a,b;
21
while(scanf(\,&a,&b)!=EOF) printf(\,a+b); }
1096 A+B for Input-Output Practice
(VIII)
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
Sample Input
3
4 1 2 3 4 5 1 2 3 4 5 3 1 2 3
Sample Output
10 15 6
Author
lcy
Recommend
JGShining
解答:
int main() {
int a,b,i,j,l[1000],k; scanf(\,&i); getchar();
for(j=1;j<=i;j++)
22
l[j]=0;
for(j=1;j<=i;j++) {
scanf(\,&a); getchar();
for(k=1;k<=a;k++) {
scanf(\,&b); getchar(); l[j]+=b; }
}
for(j=1;j<=i-1;j++)
printf(\,l[j]); printf(\,l[i]); }
1176 免费馅饼
Problem Description
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:
为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
Input
输入数据有多组。每组数据的第一行为以正整数n(0 Output 每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。 提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。 Sample Input 6 5 1 4 1 6 1 7 2 7 2 8 3 0 23 Sample Output 4 Author lwg 代码: #include int Max(int n1,int n2,int n3) { int max; max=(n1>n2)?n1:n2; max=(max>n3)?max:n3; return max; } void res(int num) { int i,j; int n,m,count=-1; memset(arr,0,MAX*13*sizeof(int)); for(i=0;i scanf(\ arr[m][n+1]++; if(count for(i=count-1;i>=0;i--) for(j=1;j<=11;j++) arr[i][j]+=Max(arr[i+1][j-1],arr[i+1][j],arr[i+1][j+1]); printf(\} int main() { int num; scanf(\ while(num) { res(num); scanf(\ } 24 return 0; } 1204 糖果大战 Problem Description 生日Party结束的那天晚上,剩下了一些糖果,Gandon想把所有的都统统拿走,Speakless于是说:―可以是可以,不过我们来玩24点,你不是已经拿到了一些糖果了吗?这样,如果谁赢一局,就拿走对方一颗糖,直到拿完对方所有的糖为止。‖如果谁能算出来而对方算不出来,谁就赢,但是如果双方都能算出或者都不能,就算平局,不会有任何糖果的得失。 Speakless是个喜欢提前想问题的人,既然他发起了这场糖果大战,就自然很想赢啦(不然可就要精光了-_-)。现在他需要你的帮忙,给你他每局赢的概率和Gardon每局赢的概率,请你给出他可能获得这场大战胜利的概率。 Input 每行有四个数,Speakless手上的糖果数N、Gardon手上的糖果数M(0<=N,M<=50)、一局Speakless能解答出来的概率p、一个问题Gardon能解答出来的概率q(0<=p,q<=1)。 Output 每行一个数,表示Speakless能赢的概率(用百分比计算,保留到小数点后2位)。 Sample Input 50 50 0.5 0.5 10 10 0.51 0.5 50 50 0.51 0.5 Sample Output 0.50 0.60 0.88 Author Speakless Source Gardon-DYGG Contest 2 Recommend JGShining 代码: #include const double EPS = 1e-12; inline void solve(int n, int m, double p, double q) { if(n==0) printf(\ else if(m==0) printf(\ else if(p==0.0||q==1.0) printf(\ else { double lamda = q*(1-p)/(p*(1-q)); 25