{
if(d!=0)
printf(\); printf(\,i); d=d+1; j=j+1; }
}
if(j==1)
printf(\); else
printf(\); } }
2011 多项式求和
Problem Description
多项式的描述如下:
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...
现在请你求出该多项式的前n项的和。
Input
输入数据由2行组成,首先是一个正整数m(m<100),表示测试实例的个数,第二行包含m个正整数,对于每一个整数(不妨设为n,n<1000),求该多项式的前n项的和。
Output
对于每个测试实例n,要求输出多项式前n项的和。每个测试实例的输出占一行,结果保留2位小数。
Sample Input
2 1 2
Sample Output
1.00 0.50
Author
lcy
46
Source
C语言程序设计练习(二)
Recommend
JGShining
解答:
#include
double m,n,i,s,j,k,a;
while(scanf(\,&m)!=EOF) {
for(i=0;i s=0; scanf(\,&n); for(j=1;j<=n;j++) s=s+1/j*pow(-1,j+1); printf(\,s); } } } 2012 素数判定 Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x Input 输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。 Output 对于每个给定范围内的取值,如果表达式的值都为素数,则输出\否则请输出―Sorry‖,每组输出占一行。 47 Sample Input 0 1 0 0 Sample Output OK Author lcy Source C语言程序设计练习(二) Recommend JGShining 解答: #include int x,y,i,j,s,k,w,d; while(scanf(\,&x,&y)==2&&(x!=0||y!=0)) { w=0; for(i=x;i<=y;i++) { k=i*i+i+41; for(j=2;j d=k%j; if(d==0) w++; } } if(w==0) printf(\); else printf(\); } 48 } 2014 青年歌手大奖赛_评委会打分 Problem Description 青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。 Input 输入数据有多组,每组占一行,每行的第一个数是n(2 Output 对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。 Sample Input 3 99 98 97 4 100 99 98 97 Sample Output 98.00 98.50 Author lcy Source C语言程序设计练习(三) Recommend lcy 解答: #include int n,s,a[100],i,k,b; double w; while(scanf(\,&n)!=EOF) { k=0; w=0; s=0; for(i=0;i 49 { scanf(\,&a[i]); k++; b=a[0]; w=w+a[i]; } for(i=0;i if(a[i]>s) s=a[i]; } for(i=1;i if(b>a[i]) b=a[i]; } w=(w-s-b)/(k-2); printf(\,w); } } 2015 偶数求和 Problem Description 有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。 Input 输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。 Output 对于每组输入数据,输出一个平均值序列,每组输出占一行。 Sample Input 3 2 4 2 Sample Output 3 6 3 7 Author lcy 50 杭电: 1000 A + B Problem .......................................................... 4 1001 Sum Problem ............................................................ 5 1002 A + B Problem II ....................................................... 6 1005 Number Sequence ........................................................ 8 1008 Elevator ............................................................... 9 1009 FatMouse' Trade ....................................................... 11 1021 Fibonacci Again ....................................................... 13 1089 A+B for Input-Output Practice (I) ..................................... 14 1090 A+B for Input-Output Practice (II) .................................... 15 1091 A+B for Input-Output Practice (III) ................................... 16 1092 A+B for Input-Output Practice (IV) .................................... 17 1093 A+B for Input-Output Practice (V) ..................................... 18 1094 A+B for Input-Output Practice (VI) .................................... 20 1095 A+B for Input-Output Practice (VII) ................................... 21 1096 A+B for Input-Output Practice (VIII) .................................. 22 1176 免费馅饼 .............................................................. 23 1204 糖果大战 .............................................................. 25 1213 How Many Tables ....................................................... 26 2000 ASCII码排序 ........................................................... 32 2001 计算两点间的距离 ...................................................... 34 2002 计算球体积 ............................................................ 35 2003 求绝对值 .............................................................. 36 2004 成绩转换 .............................................................. 37 2005 第几天? .............................................................. 38 2006 求奇数的乘积 .......................................................... 40 2007 平方和与立方和 ........................................................ 41 2008 数值统计 .............................................................. 42 2009 求数列的和 ............................................................ 43 2010 水仙花数 .............................................................. 44 2011 多项式求和 ............................................................ 46 2012 素数判定 .............................................................. 47 2014 青年歌手大奖赛_评委会打分 ............................................. 49 2015 偶数求和 .............................................................. 50 2016 数据的交换输出 ........................................................ 52 2017 字符串统计 ............................................................ 54 2019 数列有序! ............................................................. 55 2020 绝对值排序 ............................................................ 56 2021 发工资咯:) .......................................................... 58 2033 人见人爱A+B ........................................................... 59 2037 今年暑假不AC .......................................................... 61 2039 三角形 ................................................................ 63 2040 亲和数 ................................................................ 64 1 2045 不容易系列之(3)—— LELE的RPG难题 .................................... 65 2049 不容易系列之(4)——考新郎 ............................................. 66 2056 Rectangles ............................................................ 68 2073 无限的路 .............................................................. 69 2084 数塔 .................................................................. 71 2201 熊猫阿波的故事 ........................................................ 72 2212 DFS ................................................................... 73 2304 Electrical Outlets .................................................... 74 2309 ICPC Score Totalizer Software ......................................... 75 2317 Nasty Hacks ........................................................... 77 2401 Baskets of Gold Coins ................................................. 78 2500 做一个正气的杭电人 .................................................... 79 2501 Tiling_easy version ................................................... 80 2502 月之数 ................................................................ 81 2503 a/b + c/d ............................................................. 82 2504 又见GCD ............................................................... 83 2519 新生晚会 .............................................................. 84 2520 我是菜鸟,我怕谁 ...................................................... 85 2521 反素数 ................................................................ 86 2522 A simple problem ...................................................... 88 2523 SORT AGAIN ............................................................ 89 2524 矩形A + B ............................................................. 90 2535 Vote .................................................................. 91 2537 8球胜负 ............................................................... 93 2539 点球大战 .............................................................. 95 2547 无剑无我 .............................................................. 98 2548 两军交锋 .............................................................. 99 2549 壮志难酬 ............................................................. 100 2550 百步穿杨 ............................................................. 101 2551 竹青遍野 ............................................................. 103 2552 三足鼎立 ............................................................. 104 2553 N皇后问题 ............................................................ 105 2554 N对数的排列问题 ...................................................... 106 2555 人人都能参加第30届校田径运动会了 .................................... 107 2560 Buildings ............................................................ 110 2561 第二小整数 ........................................................... 112 2562 奇偶位互换 ........................................................... 113 2563 统计问题 ............................................................. 114 2564 词组缩写 ............................................................. 115 2565 放大的X .............................................................. 117 2566 统计硬币 ............................................................. 118 2567 寻梦 ................................................................. 119 2568 前进 ................................................................. 121 2569 彼岸 ................................................................. 123 2 2700 Parity ............................................................... 124 2577 How to Type .......................................................... 126 北京大学: 1035 Spell checker ........................................................ 129 1061 青蛙的约会 ........................................................... 133 1142 Smith Numbers ........................................................ 136 1200 Crazy Search ......................................................... 139 1811 Prime Test ........................................................... 141 2262 Goldbach's Conjecture ................................................ 146 2407 Relatives ............................................................ 150 2447 RSA .................................................................. 152 2503 Babelfish ............................................................ 156 2513 Colored Sticks ....................................................... 159 ACM算法: kurXX最小生成树 ............................................................ 163 Prim ....................................................................... 164 堆实现最短路 ............................................................... 166 最短路DIJ普通版 ........................................................... 167 floyd ...................................................................... 168 BELL_MAN ................................................................... 168 拓扑排序 ................................................................... 169 DFS强连通分支 .............................................................. 170 最大匹配 ................................................................... 172 还有两个最大匹配模板 ....................................................... 173 最大权匹配,KM算法 .......................................................... 175 两种欧拉路 ................................................................. 177 无向图: ............................................................... 177 有向图: ............................................................... 178 【最大流】Edmonds Karp ..................................................... 178 dinic ...................................................................... 179 【最小费用最大流】Edmonds Karp对偶算法 ..................................... 181 ACM题目: 【题目】排球队员站位问题 ................................................... 182 【题目】把自然数N分解为若干个自然数之和。 ................................. 184 【题目】把自然数N分解为若干个自然数之积。 ................................. 185 【题目】马的遍历问题。 ..................................................... 185 【题目】加法分式分解。 ..................................................... 186 【题目】地图着色问题 ....................................................... 189 3 【题目】放置方案 ........................................................... 191 【题目】找迷宫的最短路径。 ................................................. 194 【题目】火车调度问题 ....................................................... 195 【题目】农夫过河。 ......................................................... 197 【题目】七段数码管问题。 ................................................... 199 【题目】 求相邻的格的数不连续 .............................................. 200 【题目】 棋盘上放棋子 ...................................................... 202 【题目】迷宫问题. .......................................................... 204 【题目】一笔画问题 ......................................................... 205 【题目】城市遍历问题. ...................................................... 207 【题目】棋子移动问题 ....................................................... 208 【题目】求集合元素问题(1,2x+1,3X+1类) ..................................... 209 杭电: 1000 A + B Problem Problem Description Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For each case, output A + B in one line. Sample Input 1 1 Sample Output 2 Author HDOJ 代码: #include int a,b; 4 while(scanf(\,&a,&b)!=EOF) printf(\,a+b); } 1001 Sum Problem Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For 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 Input 1 100 Sample Output 1 5050 Author DOOM III 解答: #include int n,i,sum; sum=0; while((scanf(\,&n)!=-1)) { 5 for(i=0;i scanf(\,&a); if(a%2==1) s=s*a; else ; } printf(\,s); } } 2007 平方和与立方和 Problem Description 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。 Input 输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。 Output 对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。 你可以认为32位整数足以保存结果。 Sample Input 1 3 2 5 Sample Output 4 28 20 152 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include 41 { int sum1,sum2,n,i,m,t; while(scanf(\,&m,&n)!=EOF) { sum1=sum2=0; if(m>n){t=m;m=n;n=t;} for(i=m;i<=n;i++) { if(i%2==0) sum1+=(i*i); else sum2+=(i*i*i); } printf(\,sum1,sum2); } return 0; } 2008 数值统计 Problem Description 统计给定的n个数中,负数、零和正数的个数。 Input 输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。 Output 对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。 Sample Input 6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0 Sample Output 1 2 3 0 0 5 Author lcy Source C语言程序设计练习(二) 42 Recommend JGShining 解答: #include int main() { int n,i,b1,b2,b3; double a[101]; while(scanf(\,&n)!=EOF && n!=0) { for(i=0;i for(i=0;i if(a[i]<0) b1++; else if(a[i]==0) b2++; else b3++; } printf(\,b1,b2,b3); } } 2009 求数列的和 Problem Description 数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。 Input 输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。 Output 对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。 Sample Input 81 4 2 2 Sample Output 94.73 43 3.41 Author lcy Source C语言程序设计练习(二) Recommend JGShining 解答: #include double n,m,s,w,i; while(scanf(\,&n,&m)!=EOF) { s=n; for(i=1;i n=sqrt(n); s=s+n; } printf(\,s); } } 2010 水仙花数 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: ―水仙花数‖是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。 Input 输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。 Output 对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开; 44 如果给定的范围内不存在水仙花数,则输出no; 每个测试实例的输出占一行。 Sample Input 100 120 300 380 Sample Output no 370 371 Author lcy Source C语言程序设计练习(二) Recommend JGShining 解答: #include int m,n,i,w,a,b,c,j,s,d; while(scanf(\,&n,&m)!=EOF) { d=0; j=1; if(m>n) { w=m; m=n; n=w; } else ; for(i=m;i<=n;i++) { a=i/100; b=i/10; c=i; s=a*a*a+b*b*b+c*c*c; if(i==s) 45 Output 对每个测试用例,在1行里输出最少还需要建设的道路数目。 Sample Input 4 2 1 3 4 3 3 3 1 2 1 3 2 3 5 2 1 2 3 5 999 0 0 Sample Output 1 0 2 998 Hint Hint Huge input, scanf is recommended. Source 浙大计算机研究生复试上机考试-2005年 Recommend JGShining 代码:#include #include int i,j; int rest; set=1; //用来统计集合个数 memset(res,0,(n+1)*sizeof(int)); res[arr[0][0]]=res[arr[0][1]]=1; for(i=1;i<=set;i++) { for(j=0;j { if(res[arr[j][0]]*res[arr[j][1]]) continue; //当前数据已经归类,则不进行任何操作 if(res[arr[j][0]]==i||res[arr[j][1]]==i) { res[arr[j][0]]=res[arr[j][1]]=i; //对数据进行集合划分 j=-1; //从第一组元素开始继续遍历 } } 31 for(j=0;j if(res[arr[j][0]]*res[arr[j][1]]==0) break; //遇到首或尾没有归类的情况的时候跳出 if(j if(res[arr[j][0]]*res[arr[j][1]]==0){ res[arr[j][0]]=res[arr[j][1]]=set; break; } } } rest=0; for(i=1;i<=n;i++) if(res[i]==0) rest++; if(m==0) printf(\ else if(rest==0) { if(set==1) printf(\ else printf(\ } else printf(\} int main() { int i; scanf(\ while(n) { scanf(\ for(i=0;i scanf(\ } return 0; } 2000 ASCII码排序 Problem Description 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。 Input 输入数据有多组,每组占一行,有三个字符组成,之间无空格。 Output 对于每组输入数据,输出一行,字符中间用一个空格分开。 32 Sample Input qwe asd zxc Sample Output e q w a d s c x z Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include char a,b,c,d; while(scanf(\,&a,&b,&c)!=EOF) { getchar(); if(a>=b) { if(c>=a) printf(\,b,a,c); else if(b>=c) printf(\,c,b,a); else if(b printf(\,b,c,a); } else { if(c>=b) printf(\,a,b,c); else if(c>=a) printf(\,a,c,b); else if(a>c) 33 printf(\,c,a,b); } } } 2001 计算两点间的距离 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。 Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。 Output 对于每组输入数据,输出一行,结果保留两位小数。 Sample Input 0 0 0 1 0 1 1 0 Sample Output 1.00 1.41 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include double a,b,c,d,s; 34 while(scanf(\%lf %lf %lf\,&a,&b,&c,&d)!=EOF) { s=sqrt((a-c)*(a-c)+(b-d)*(b-d)); printf(\,s); } } 2002 计算球体积 Problem Description 根据输入的半径值,计算球的体积。 Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。 Output 输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。 Sample Input 1 1.5 Sample Output 4.189 14.137 Hint #define PI 3.1415927 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include double a,v; 35 while(scanf(\,&a)!=EOF) { v=4*PI*a*a*a/3; printf(\,v); } } 2003 求绝对值 Problem Description 求实数的绝对值。 Input 输入数据有多组,每组占一行,每行包含一个实数。 Output 对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。 Sample Input 123 -234.00 Sample Output 123.00 234.00 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include double a; while(scanf(\,&a)!=EOF) { if(a<0) a=-a; 36 printf(\,a); } } 2004 成绩转换 Problem Description 输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下: 90~100为A; 80~89为B; 70~79为C; 60~69为D; 0~59为E; Input 输入数据有多组,每组占一行,由一个整数组成。 Output 对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:―Score is error!‖。 Sample Input 56 67 100 123 Sample Output E D A Score is error! Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include 37 int main() { int n; while(scanf(\,&n)!=EOF) { if(n>100||n<0)printf(\error!\\n\); else if(n>=90)printf(\); else if(n>=80)printf(\); else if(n>=70)printf(\); else if(n>=60)printf(\); else printf(\); } return 0; } 2005 第几天? Problem Description 给定一个日期,输出这个日期是该年的第几天。 Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。 Output 对于每组输入数据,输出一行,表示该日期是该年的第几天。 Sample Input 1985/1/20 2006/3/12 Sample Output 20 71 Author lcy Source C语言程序设计练习(一) Recommend JGShining 38 解答: #include int a,b,c,d,e,f,g; while(scanf(\,&a,&b,&c)!=EOF) { if(b==1) d=c; else if(b==2) d=31+c; else if(b==3) d=31+28+c; else if(b==4) d=31+28+31+c; else if(b==5) d=31+31+28+30+c; else if(b==6) d=31+28+31+30+31+c; else if(b==7) d=31+28+31+30+31+30+c; else if(b==8) d=31+28+31+30+31+30+31+c; else if(b==9) d=31+28+31+30+31+30+31+31+c; else if(b==10) d=31+28+31+30+31+30+31+31+30+c; else if(b==11) d=31+28+31+30+31+30+31+31+30+31+c; else if(b==12) d=31+28+31+30+31+30+31+31+30+31+c+30; e=a0; f=a@0; g=a%4; if(e==0) { if(f==0) d=1+d; else d=d; } else if(g=0) d=d+1; 39 else d=d; printf(\,d); } } 2006 求奇数的乘积 Problem Description 给你n个整数,求他们中所有奇数的乘积。 Input 输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。 Output 输出每组数中的所有奇数的乘积,对于测试实例,输出一行。 Sample Input 3 1 2 3 4 2 3 4 5 Sample Output 3 15 Author lcy Source C语言程序设计练习(一) Recommend JGShining 解答: #include int n,s,i,a; while(scanf(\,&n)!=EOF) { s=1; 40 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库整理的-----ACM题目及答案在线全文阅读。
相关推荐: