博文

functions(2007-04-11 14:01:00)

摘要:Problem description Recurrence relations are where a function is defined in terms of itself and maybe other functions as well. in this problem, we have two functions of interest: F (N) = F (N - 1) + G (N - 1) ; F (1) = 1 G (N) = G (N - 1) + G (N - 3) ; G (1) = 1, G (2) = 0, G (3) = 1 For a given value of N, compute F (N).  Input Each line of input will have exactly one integer, 57 > = N > 0.  Output For each line of input, output F(N).  Sample Input 1457 Sample Output 132035586497    #include <stdio.h> unsigned long getfn(unsigned long n);void getgn(); unsigned long   a[60]; unsigned long getfn(unsigned long n){ unsigned long i = 0,j = 0,k = 0;   if(n == 1) i = 1;   else  { j = getfn(n - 1);   k = a[n - 1];   i = j + k; }  return i;} void getgn(){ int n,m,i,j;   a[1] = 1;  a[2] = 0;  a[3] = 1;  for(n = 4,i = 0,j = 0; n <......

阅读全文(2551) | 评论:0

self-number(2007-04-11 14:00:00)

摘要:Problem description In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. There are thirteen self-numbers less tha......

阅读全文(4006) | 评论:0

区间(2007-04-11 13:57:00)

摘要:区间    Problem description 现给定n个闭区间[ai, bi],1<=i<=n。这些区间的并可以表示为一些不相交的闭区间的并。你的任务就是在这些表示方式中找出包含最少区间的方案。你的输出应该按照区间的升序排列。这里如果说两个区间[a, b]和[c, d]是按照升序排列的的,那么我们有a<=b 请写一个程序:读入这些区间;计算满足给定条件的不相交闭区间;把这些区间按照升序输出.  Input 第一行包含一个整数n,3<=n<=50000,为区间的数目。以下n行为对区间的描述,第i行为对第i个区间的描述,为两个整数1<=ai<=bi<=1000000,表示一个区间[ai, bi]。  Output 你应该输出计算出来的不相交的区间。每一行都是对一个区间的描述,包括两个用空格分开的整数,为区间的上下界。你应该把区间按照升序排序。  Sample Input 55 61 410 106 98 10 Sample Output 1 45 10 Problem Source SDOI  #include <stdio.h>#include <malloc.h> typedef struct Node{ int i;  int j;  struct Node *next;}QNODE;QNODE *head = NULL,*temp = NULL,*ahead = NULL; int enter(){ int n,m,max;  QNODE *qtemp;   head = temp = (QNODE*)malloc(sizeof(QNODE));  head -> next = NULL;  scanf("%d",&m);  for(max = 0,n = 0; n < m; n ++) { scanf("%d %d",&temp -> i,&temp -> j);   if( temp ->......

阅读全文(3497) | 评论:1

最大公约数(2007-04-11 13:56:00)

摘要:求最大公约数,1<=a,b<=100000000;   #include <stdio.h> long test(long a,long b){ long  m,i,j,n;    if ( !(a % b) ) m = b;   else { for( n = 2,i = b / 2 + 2; n < i; n ++)  if( !(b % n) )     { j = b / n;       if( !(a % j ) )   { m = j ;     break;   }    }    }   return m;}   int main(){ int   n,m;  long  a,b;   scanf("%d",&m);  for(n = 0; n < m; n ++) { scanf("%ld %ld",&a,&b);   if( a > b )      printf("%ld\n",test(a,b));   else      printf("%ld\n",test(b,a));        } return 0;}   ......

阅读全文(2559) | 评论:0

奖学金(2007-04-11 13:55:00)

摘要:谁拿了最多奖学金   Problem description 某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得; 2) 五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得; 3) 成绩优秀奖,每人2000元,期末平均成绩高于90分(>90)的学生均可获得; 4) 西部奖学金,每人1000元,期末平均成绩高于85分(>85)的西部省份学生均可获得; 5) 班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得; 只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。 现在给出若干学生的相关数据,请计算哪些同学获得的奖金总数最高(假设总有同学能满足获得奖学金的条件)。  Input 输入的第一行是一个整数N(1 <= N <= 100),表示学生的总数。接下来的N行每行是一位学生的数据,从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是否是西部省份学生,以及发表的论文数。姓名是由大小写英文字母组成的长度不超过20的字符串(不含空格);期末平均成绩和班级评议成绩都是0到100之间的整数(包括0和100);是否是学生干部和是否是西部省份学生分别用一个字符表示,Y表示是,N表示不是;发表的论文数是0到10的整数(包括0和10)。每两个相邻数据项之间用一个空格分隔。  Output 输出包括三行,第一行是获得最多奖金的学生的姓名,第二行是这名学生获得的奖金总数。如果有两位或两位以上的学生获得的奖金最多,输出他们之中在输入文件中出现最早的学生的姓名。第三行是这N个学生获得的奖学金的总数。  Sample Input 4YaoLin 87 82 Y N 0ChenRuiyi 88 78 N Y 1LiXin 92 88 N N 0ZhangQin 83......

阅读全文(2745) | 评论:0

行编辑器(2007-04-11 13:54:00)

摘要:行编辑器  Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB  Total submit users: 80, Accepted users: 77  Problem 10428 : No special judgement  Problem description 一个简单的行编辑程序的功能是:接受用户从终端输入的程序或数据,并存入用户的数据区。 由于用户在终端上进行输入时,不能保证不出差错,因此,若在编辑程序中,“每接受一个字符即存入用户数据区”的做法显然不是最恰当的。较好的做法是,设立一个输入缓冲区,用以接受用户输入的一行字符,然后逐行存入用户数据区。允许用户输入出差错,并在发现有误时可以及时更正。例如,当用户发现刚刚键入的一个字符是错的时,可补进一个退格符"#",以表示前一个字符无效; 如果发现当前键入的行内差错较多或难以补救,则可以键入一个退行符"@",以表示当前行中的字符均无效。 如果逻辑上的位置已经在行首,则继续输入'#'符号无效。  Input 输入一个多行的字符序列。但行字符总数(包含退格符和退行符)不大于250。  Output 按照上述说明得到的输出。  Sample Input whli##ilr#e(s#*s)   outcha@putchar(*s=#++); Sample Output while(*s)putchar(*s++); Problem Source HNU Contest    #include <stdio.h>#include <string.h>#include <malloc.h> struct str{ char *str;  struct str *next;} *head,*temp; void deal(char a[],char b[]){ int i,j,len;    len = strlen(a);  for(i = 0,j = 0; i < len; i ......

阅读全文(2304) | 评论:0