版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1000 A + B ProblemProblem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file. OutputFor each case, output A + B in one line.Sample Input1 1 Sample Output2 AuthorHDOJ代码:#include<stdio.h>int main() int a,b; while(scanf("%d %d&q
2、uot;,&a,&b)!=EOF) printf("%dn",a+b);1001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + . + n.InputThe input will consist of a series of integers n, one integer per line.Out
3、putFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer. Sample Input1100Sample Output15050 AuthorDOOM III解答:#include<stdio.h>main() int n,i,sum; sum=0; while(scanf("%d",&n)!=-1) sum=
4、0; for(i=0;i<=n;i+) sum+=i; printf("%dnn",sum);1002 A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the numbe
5、r of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000. OutputFor each test case, you shou
6、ld output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2Sample O
7、utputCase 1:1 + 2 = 3Case 2:Author代码:#include <stdio.h>#include <string.h>int main() char str11001, str21001; int t, i, len_str1, len_str2, len_max, num = 1, k; scanf("%d", &t); getchar(); while(t-) int a1001 = 0, b1001 = 0, c1001 = 0; scanf("%s", str1); len_str1
8、= strlen(str1); for(i = 0; i <= len_str1 - 1; +i) ai = str1len_str1 - 1 - i - '0' scanf("%s",str2); len_str2 = strlen(str2); for(i = 0; i <= len_str2 - 1; +i) bi = str2len_str2 - 1 - i - '0' if(len_str1 > len_str2) len_max = len_str1; else len_max = len_str2; k = 0
9、; for(i = 0; i <= len_max - 1; +i) ci = (ai + bi + k) % 10; k = (ai + bi + k) / 10; if(k != 0) clen_max = 1; printf("Case %d:n", num); num+; printf("%s + %s = ", str1, str2); if(clen_max = 1) printf("1"); for(i = len_max - 1; i >= 0; -i) printf("%d", ci)
10、; printf("n"); if(t >= 1) printf("n"); return 0;1005 Number SequenceProblem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of mul
11、tiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.OutputFor each test case, print the value of f(n) on a single line. Sample Input
12、1 1 31 2 100 0 0 Sample Output25AuthorCHEN, Shunbao SourceZJCPC2004 RecommendJGShining代码:#include<stdio.h>int f200;int main() int a,b,n,i; while(scanf("%d%d%d",&a,&b,&n)&&a&&b&&n) if(n>=3) f1=1;f2=1; for(i=3;i<=200;i+) fi=(a*f
13、i-1+b*fi-2)%7; if(fi-1=1&&fi=1) break; i-=2; n=n%i; if(n=0) printf("%dn",fi); else printf("%dn",fn); else printf("1n"); return 0;1008 ElevatorProblem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive num
14、bers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.For a given request list, you are to compute the total time spent to fulf
15、ill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled. InputThere are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the in
16、put are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed. OutputPrint the total time on a single line for each test case. Sample Input1 23 2 3 10Sample Output1741AuthorZHENG, JianqiangSourceZJCPC2004 RecommendJGShining代码:#include<std
17、io.h>int a110;int main() int sum,i,n; while(scanf("%d",&n)&&n!=0) for(i=1;i<=n;i+) scanf("%d",&ai); sum=0; a0=0; for(i=1;i<=n;i+) if(ai>ai-1) sum+=6*(ai-ai-1); else sum+=4*(ai-1-ai); sum+=5; printf("%dn",sum); return 0;1009 FatMouse' Trad
18、eProblem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains Ji pounds of JavaBeans and requires Fi pounds of cat food. FatMouse does not have to trade for all
19、the JavaBeans in the room, instead, he may get Ji* a% pounds of JavaBeans if he pays Fi* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.InputThe input consists of multiple test cases. Each test case beg
20、ins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers Ji and Fi respectively. The last test case is followed by two -1's. All integers are not greater than 1000.OutputFor each test case, print in a single line a real number acc
21、urate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.Sample Input5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1Sample OutputAuthorCHEN, YueSourceZJCPC2004RecommendJGShining代码:#include<stdio.h>#define MAX 1000int main() int i,j,m,n,temp; int JMAX,FMAX; d
22、ouble PMAX; double sum,temp1; scanf("%d%d",&m,&n); while(m!=-1&&n!=-1) sum=0; memset(J,0,MAX*sizeof(int); memset(F,0,MAX*sizeof(int); memset(P,0,MAX*sizeof(double); for(i=0;i<n;i+) scanf("%d%d",&Ji,&Fi); Pi=Ji*1.0/(double)Fi); for(i=0;i<n;i+) for(j=i
23、+1;j<n;j+) if(Pi<Pj) temp1=Pi; Pi=Pj; Pj=temp1; temp=Ji; Ji=Jj; Jj=temp; temp=Fi; Fi=Fj; Fj=temp; for(i=0;i<n;i+) if(m<Fi) sum+=m/(double)Fi)*Ji; break; else sum+=Ji; m-=Fi; printf("%.3lfn",sum); scanf("%d%d",&m,&n); return 0;1021 Fibonacci AgainProblem Descri
24、ptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).InputInput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).OutputPrint the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.
25、Sample Input012345Sample OutputnonoyesnononoAuthorLeojayRecommendJGShining#include<stdio.h>int main() long n; while(scanf("%ld",&n) != EOF) if (n%8=2 | n%8=6) printf("yesn"); else printf("non"); return 0;1089 A+B for Input-Output Practice (I)Problem Descriptio
26、nYour task is to Calculate a + b.Too easy?! Of course! I specially designed the problem for acm beginners. You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim. InputThe input will consist of a series of pairs of integers a
27、 and b, separated by a space, one pair of integers per line. OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input. Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h> m
28、ain() int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%dn",a+b);1090 A+B for Input-Output Practice (II)Problem DescriptionYour task is to Calculate a + b. InputInput contains an integer N in the first line, and then N lines follow. Each line consists of a pair of in
29、tegers a and b, separated by a space, one pair of integers per line. OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input. Sample Input21 510 20Sample Output630 Authorlcy RecommendJGShining解答:#inc
30、lude<stdio.h>#define M 1000void main() int a ,b,n,jM,i; /printf("please input n:n"); scanf("%d",&n); for(i=0;i<n;i+) scanf("%d%d",&a,&b); /printf("%d %d",a,b); ji=a+b; i=0; while(i<n) printf("%d",ji); i+; printf("n")
31、;1091 A+B for Input-Output Practice (III)Problem DescriptionYour task is to Calculate a + b.InputInput contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be proc
32、essed.OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input. Sample Input1 510 200 0 Sample Output630Authorlcy RecommendJGShining解答:#include<stdio.h> main() int a,b; scanf("%d %d&q
33、uot;,&a,&b); while(!(a=0&&b=0) printf("%dn",a+b); scanf("%d %d",&a,&b);1092 A+B for Input-Output Practice (IV)Problem DescriptionYour task is to Calculate the sum of some integers. InputInput contains multiple test cases. Each test case contains a int
34、eger N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input. Sample Input4 1 2 3 45 1
35、 2 3 4 50 Sample Output1015 AuthorlcyRecommendJGShining解答:#include <stdio.h>int main() int n,sum,i,t; while(scanf("%d",&n)!=EOF&&n!=0) sum=0; for(i=0;i<n;i+) scanf("%d",&t); sum=sum+t; printf("%dn",sum);1093 A+B for Input-Output Pract
36、ice (V)Problem DescriptionYour task is to calculate the sum of some integers.InputInput 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. OutputFor each group of input integers you should output their sum
37、 in one line, and with one line of output for each line in input. Sample Input24 1 2 3 45 1 2 3 4 5 Sample Output1015 Authorlcy解答:#include<stdio.h>main() int n,a,b,i,j,sum; sum=0; while(scanf("%dn",&n)!=-1) for(i=0;i<n;i+) scanf("%d",&b); for(j=0;
38、j<b;j+) scanf("%d",&a); sum+=a; printf("%dn",sum); sum=0;1094 A+B for Input-Output Practice (VI)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and the
39、n N integers follow in the same line. OutputFor each test case you should output the sum of N integers in one line, and with one line of output for each line in input. Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015 Authorlcy RecommendJGShining解答:#include<stdio.h>main() int n
40、,a,b,i,j,sum; sum=0; while(scanf("%dn",&n)!=-1) for(j=0;j<n;j+) scanf("%d",&a); sum+=a; printf("%dn",sum); sum=0; Copy to Clipboard Save to File1095 A+B for Input-Output Practice (VII)Problem DescriptionYour task is to Calculate a + b
41、.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line. OutputFor each pair of input integers a and b you should output the sum of a and b, and followed by a blank line. Sample Input1 510 20 Sample Output630 Au
42、thorlcyRecommendJGShining解答:#include<stdio.h> main() int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%dnn",a+b);1096 A+B for Input-Output Practice (VIII)Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains an integer N in
43、the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line. OutputFor 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 Input34 1 2 3 45 1 2 3 4
44、53 1 2 3 Sample Output10156 AuthorlcyRecommendJGShining解答:int main() int a,b,i,j,l1000,k; scanf("%d",&i); getchar(); for(j=1;j<=i;j+) lj=0; for(j=1;j<=i;j+) scanf("%d",&a); getchar(); for(k=1;k<=a;k+) scanf("%d",&b); getchar(); lj+=b; for(
45、j=1;j<=i-1;j+) printf("%dnn",lj); printf("%dn",li);1176 免费馅饼Problem Description都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,突然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别
46、迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开场时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?假设他的背包可以容纳无穷多个馅饼Input输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅
47、饼。n=0时输入完毕。Output每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。提示:此题的输入数据量比拟大,建议用scanf读入,用cin可能会超时。Sample Input6 5 1 4 1 6 1 7 2 7 2 8 3 0Sample Output4Authorlwg代码:#include<stdio.h>#include<string.h>#define MAX 100001int arrMAX13;int Max(int n1,int n2,int n3) int max; max=(n1>n2)?n1:n2; m
48、ax=(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<num;i+) scanf("%d%d",&n,&m); arrmn+1+; if(count<m) count=m; for(i=count-1;i>=0;i-) for(j=1;j<=11;j+) arrij+=Max(arri+1j-1,arri+1j,arri+1j+1); printf
49、("%dn",arr06);int main() int num; scanf("%d",&num); while(num) res(num); scanf("%d",&num); return 0;1204 糖果大战Problem Description生日Party完毕的那天晚上,剩下了一些糖果,Gandon想把所有的都统统拿走,Speakless于是说:“可以是可以,不过我们来玩24点,你不是已经拿到了一些糖果了吗?这样,如果谁赢一局,就拿走对方一颗糖,直到拿完对方所有的糖为止。如果谁能算出来而对方算不出来,谁就
50、赢,但是如果双方都能算出或者都不能,就算平局,不会有任何糖果的得失。Speakless是个喜欢提前想问题的人,既然他发起了这场糖果大战,就自然很想赢啦不然可就要精光了-_-。现在他需要你的帮助,给你他每局赢的概率和Gardon每局赢的概率,请你给出他可能获得这场大战胜利的概率。Input每行有四个数,Speakless手上的糖果数N、Gardon手上的糖果数M(0<=N,M<=50)、一局Speakless能解答出来的概率p、一个问题Gardon能解答出来的概率q(0<=p,q<=1)。Output每行一个数,表示Speakless能赢的概率用百分比计算,保存到小数点后
51、2位。Sample InputSample OutputAuthorSpeaklessSourceGardon-DYGG Contest 2RecommendJGShining代码:#include <stdio.h>#include <math.h>const double EPS = 1e-12;inline void solve(int n, int m, double p, double q) if(n=0) printf("0.00n"); else if(m=0) printf("1.00n"); else if(p=
52、0.0|q=1.0) printf("0.00n"); else double lamda = q*(1-p)/(p*(1-q); if(fabs(lamda-1.0)<EPS) printf("%.2lfn", double(n)/(m+n); else double res = (1-pow(lamda, n)/(1-pow(lamda, m+n); printf("%.2lfn", res);int main() int n, m; double p, q; while(scanf("%d%d%lf%lf&quo
53、t;, &n, &m, &p, &q)!=EOF) solve(n, m, p, q); return 0;1213 How Many TablesProblem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strangers.One important rule for this p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 圆锥曲线热点问题(二)位置关系类+课件-2026届高三数学二轮专题复习
- 医院科室主任考试题库及答案
- 2026五年级数学下册 观察物体学习方法
- 智能物业设备监控运维管理平台解决方案
- 英语单词听力试卷及答案
- 新编应用写作试题及答案
- 行车工初级试题及答案
- 2025 高中信息技术数据与计算在通信网络课件
- 车辆运输安全奖惩制度
- 太湖游客中心奖惩制度
- 2024-2025学年度无锡商业职业技术学院单招《语文》试卷及完整答案详解(网校专用)
- T-CASMES 428-2024 商业卫星太阳电池阵通.用规范
- 无领导小组讨论ppt
- GB/T 15237.1-2000术语工作词汇第1部分理论与应用
- 立法建议书6篇
- 2023年苏州工业职业技术学院单招综合素质考试笔试模拟试题及答案解析
- 院前急救护士职责及流程
- 医院压缩感知磁共振快速成像应用培训
- 饲料厂常见安全隐患100条
- 心肌缺血与心肌梗死心电图课件
- 光伏发电项目并网调试方案
评论
0/150
提交评论