




已阅读5页,还剩203页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 1Sample Output2AuthorHDOJ代码:#includeint main() int a,b; while(scanf(%d %d,&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.OutputFor 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 Output15050AuthorDOOM III解答:#includemain() int n,i,sum; sum=0; while(scanf(%d,&n)!=-1) sum=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 number 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 should 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 2112233445566778899 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110AuthorIgnatius.L代码:#include #include 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 = 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) len_max = len_str1; else len_max = len_str2; k = 0; for(i = 0; i = 0; -i) printf(%d, ci); 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 multiple 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 Input1 1 31 2 100 0 0Sample Output25AuthorCHEN, ShunbaoSourceZJCPC2004 RecommendJGShining代码:#includeint 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*fi-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 numbers. 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 fulfill 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 input 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代码:#includeint 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;iai-1) sum+=6*(ai-ai-1); else sum+=4*(ai-1-ai); sum+=5; printf(%dn,sum); return 0;1009 FatMouse TradeProblem 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 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 begins 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 -1s. All integers are not greater than 1000.OutputFor each test case, print in a single line a real number accurate 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 Output13.333 31.500AuthorCHEN, YueSourceZJCPC2004RecommendJGShining代码:#include#include#define MAX 1000int main() int i,j,m,n,temp; int JMAX,FMAX; double 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;in;i+) scanf(%d%d,&Ji,&Fi); Pi=Ji*1.0/(double)Fi); for(i=0;in;i+) for(j=i+1;jn;j+) if(PiPj) temp1=Pi; Pi=Pj; Pj=temp1; temp=Ji; Ji=Jj; Jj=temp; temp=Fi; Fi=Fj; Fj=temp; for(i=0;in;i+) if(m=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.Sample Input012345Sample OutputnonoyesnononoAuthorLeojayRecommendJGShining#includeint 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 DescriptionYour 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 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 main() 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 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 in one line, and with one line of output for each line in input. Sample Input21 510 20Sample Output630AuthorlcyRecommendJGShining 解答:#include#define M 1000void main() int a ,b,n,jM,i; /printf(please input n:n); scanf(%d,&n); for(i=0;in;i+) scanf(%d%d,&a,&b); /printf(%d %d,a,b); ji=a+b; i=0; while(in) printf(%d,ji); i+; printf(n); 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 processed.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 0Sample Output630AuthorlcyRecommendJGShining解答:#include main() int a,b; scanf(%d %d,&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 integer 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 2 3 4 50 Sample Output1015AuthorlcyRecommendJGShining解答:#include int main() int n,sum,i,t; while(scanf(%d,&n)!=EOF&n!=0) sum=0; for(i=0;in;i+) scanf(%d,&t); sum=sum+t; printf(%dn,sum); 1093 A+B for Input-Output Practice (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 in one line, and with one line of output for each line in input. Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#includemain() int n,a,b,i,j,sum; sum=0; while(scanf(%dn,&n)!=-1) for(i=0;in;i+) scanf(%d,&b); for(j=0;jb;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 then 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 Output1015AuthorlcyRecommendJGShining解答:#includemain() int n,a,b,i,j,sum; sum=0; while(scanf(%dn,&n)!=-1) for(j=0;jn;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.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 20Sample Output630AuthorlcyRecommendJGShining解答:#include 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 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 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答: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(j=1;j=i-1;j+) printf(%dnn,lj); printf(%dn,li); 1176 免费馅饼Problem Description都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)Input输入数据有多组。每组数据的第一行为以正整数n(0n100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0T100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。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#include#define MAX 100001int arrMAX13;int Max(int n1,int n2,int n3) int max; max=(n1n2)?n1:n2; max=(maxn3)?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;inum;i+) scanf(%d%d,&n,&m); arrmn+1+; if(count=0;i-) for(j=1;j=11;j+) arrij+=Max(arri+1j-1,arri+1j,arri+1j+1); printf(%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点,你不是已经拿到了一些糖果了吗?这样,如果谁赢一局,就拿走对方一颗糖,直到拿完对方所有的糖为止。”如果谁能算出来而对方算不出来,谁就赢,但是如果双方都能算出或者都不能,就算平局,不会有任何糖果的得失。Speakless是个喜欢提前想问题的人,既然他发起了这场糖果大战,就自然很想赢啦(不然可就要精光了-_-)。现在他需要你的帮忙,给你他每局赢的概率和Gardon每局赢的概率,请你给出他可能获得这场大战胜利的概率。Input每行有四个数,Speakless手上的糖果数N、Gardon手上的糖果数M(0=N,M=50)、一局Speakless能解答出来的概率p、一个问题Gardon能解答出来的概率q(0=p,q=1)。Output每行一个数,表示Speakless能赢的概率(用百分比计算,保留到小数点后2位)。Sample Input50 50 0.5 0.5 10 10 0.51 0.5 50 50 0.51 0.5Sample Output0.50 0.60 0.88AuthorSpeaklessSourceGardon-DYGG Contest 2RecommendJGShining代码:#include #include 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=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);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业园区的物业管理及服务创新
- 工业排放控制技术分析
- 工业污染治理的新技术与成果
- 工业建筑设计及其安全防护措施
- 工业废水零排放技术研究与应用推广
- 工业污染防治与环保技术探讨
- 工业污染的防治与绿色生产
- 工业机器人编程与调试技术研究
- 工业设计中的智能产品创新
- 工业自动化在白水泥生产中的应用研究
- 北师大版四年级下册小数乘法竖式计算200题及答案
- 【小升初】2023-2024学年贵州遵义市六年级下学期数学期末试题2套(含解析)
- 烟草物理检验竞赛考试题库及答案附有答案
- 教科版科学三年级下册期末测试卷【满分必刷】
- 24春国家开放大学《行政管理学#》形考任务1-4参考答案
- 高三一轮复习语文教学计划
- 可可西里守护神杰桑·索南达杰事迹学习
- 机房施工方案及技术措施
- 员工培训矩阵表
- 精编人教版小学数学1-6年级期末试题汇总(带答案)
- 掼蛋大赛招商方案
评论
0/150
提交评论