All Posts

hdoj1009解题报告

Problem Description FatMouse 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 J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of

hdoj2012解题报告

Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39  Input 输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。   Output 对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。   #include bool isprime(int n) { for (int i = 2; i

hdoj2011解题报告

Problem Description 多项式的描述如下: 1 – 1/2 + 1/3 – 1/4 + 1/5 – 1/6 + … 现在请你求出该多项式的前n项的和。   Input 输入数据由2行组成,首先是一个正整数m(m  Output 对于每个测试实例n,要求输出多项式前n项的和。每个测试实例的输出占一行,结果保留2位小数。   #include int main() { int m; scanf("%d", &m); while (m--) { int n; scanf("%d", &n); double res = 0; int tmp = -1; for (int i = 1; i

hdoj2010解题报告

Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: “水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。   Input 输入数据有多组,每组占一行,包括两个整数m和n(100  Output 对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开; 如果给定的范围内不存在水仙花数,则输出no; 每个测试实例的输出占一行。   #include bool issxh(int n) { int sum = 0; int m = n; while (n 0) { int tmp = n % 10; sum += tmp * tmp * tmp; n /= 10; } return (sum == m); } int main() { int x, y; while (scanf("

hdoj2009解题报告

Problem Description 数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。   Input 输入数据有多组,每组占一行,由两个整数n(n  Output 对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。   #include <cstdio> #include <cmath> intmain() {int n, m;while(scanf("%d %d", &n, &m) != EOF) {double res=0;double x= n;for(int i=0; i< m; i++) { res+= x; x= sqrt(x); } printf("%.2lfn", res); }return0; }

hdoj2008解题报告

Problem Description 统计给定的n个数中,负数、零和正数的个数。   Input 输入数据有多组,每组占一行,每行的第一个数是整数n(n  Output 对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。   #include #include int main() { int n, m; while (scanf("%d %d", &n, &m) != EOF) { double res = 0; double x = n; for (int i = 0; i

hdoj2007解题报告

Problem Description 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。   Input 输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。   Output 对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。 你可以认为32位整数足以保存结果。   #include int main() { while (true) { int n; scanf("%d", &n); if (n == 0)break; int z = 0, f = 0, l = 0; for (int i = 0; i 0) z++; else if (x

hdoj2006解题报告

Problem Description 给你n个整数,求他们中所有奇数的乘积。   Input 输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。   Output 输出每组数中的所有奇数的乘积,对于测试实例,输出一行。   废话不说,上代码: #include int main() { int n; while (scanf("%d", &n) != EOF) { int res = 1; for (int i = 0; i

hdoj2005解题报告

Problem Description 给定一个日期,输出这个日期是该年的第几天。   Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。   Output 对于每组输入数据,输出一行,表示该日期是该年的第几天。   首先要知道该年是不是闰年,然后再计算 代码: #include int main() { int y, m, d; while (scanf("%d/%d/%d", &y, &m, &d) != EOF) { int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if ((y % 4 == 0 && y % 100 !

hdoj2004解题报告

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!”。   #include int main() {     int x;     while (scanf("%d", &x) != EOF)     {         if (x = 0 && x = 60 && x = 70 && x = 80 && x = 90 && x return 0;