| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9891 人关注过本帖
标题:[讨论]第一期题目
只看楼主 加入收藏
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
结帖率:50%
收藏
 问题点数:0 回复次数:101 
[讨论]第一期题目

Number Sequence

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 3359 Accepted Submit: 719

--------------------------------------------------------------------------------

A 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).


Input

The 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.


Output

For each test case, print the value of f(n) on a single line.


/*翻译如下,大家对照一下,不一定翻译的正确.*/

定义一个数序列如下:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
给定A,B,n,请你计算f(n)的值。
输入:包括多组测试,每组测试包括一行3个整数A,B,n(1 <= A, B <=1000, 1 <= n <=100,000,000).以输入3个0表示结束测试,并且不用处理这组。
输出:对每一组测试,每行输出一个f(n)的值。


Sample Input

1 1 3
1 2 10
0 0 0


Sample Output

2
5

搜索更多相关主题的帖子: sequence Memory number 
2006-11-12 13:08
guzhou
Rank: 1
等 级:新手上路
威 望:1
帖 子:247
专家分:0
注 册:2006-11-4
收藏
得分:0 
支持,马上就做!

2006-11-12 13:18
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

Steps

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 1164 Accepted Submit: 455

--------------------------------------------------------------------------------
One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the previous step.

What is the minimum number of steps in order to get from x to y? The length of the first and the last step must be 1.

Input

For each test case, a line follows with two integers: 0 <= x <= y < 2^31.


Output

For each test case, print a line giving the minimum number of steps to get from x to y.


Sample Input

45 48
45 49
45 50


Sample Output

3
3
4

/*翻译*/

步长。
用直线上的点来表示一个单位步长,一个步长是个非负数,且只和前一个步长的差值(绝对值)不大于1。
现在要求从X到Y的最小步长数。第一步和最后一步的步长一定要是1。
输入:对每组测试,输入两个整数:0 <= x <= y < 2^31.
输出:对每组测试,一行输出一个要求的从X到Y的最小步长数。

[此贴子已经被作者于2006-11-12 14:03:27编辑过]


倚天照海花无数,流水高山心自知。
2006-11-12 13:19
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
有看的不太懂的对照E文看,我自己E文太烂了,英语好的可以翻译出来.
还有,每次题目会置顶一个星期,大家感兴趣就做.
大家注意一下输入输出格式和时间的限制(对算法的要求).

倚天照海花无数,流水高山心自知。
2006-11-12 13:22
C语言学习者
Rank: 4
等 级:贵宾
威 望:13
帖 子:1278
专家分:0
注 册:2006-9-26
收藏
得分:0 
第一题是函数题,这个慢慢想.

谁有强殖装甲第二部,可以Q我460054868
2006-11-12 13:23
guzhou
Rank: 1
等 级:新手上路
威 望:1
帖 子:247
专家分:0
注 册:2006-11-4
收藏
得分:0 
第一题是连续输入,还是输入一组输出个结果?

2006-11-12 13:44
guzhou
Rank: 1
等 级:新手上路
威 望:1
帖 子:247
专家分:0
注 册:2006-11-4
收藏
得分:0 
第二题
by one bigger than, equal to, or by one smaller than the length of the previous step
应译为
且可以比前一个步长大1或小1或与前一个步长相等!

2006-11-12 13:51
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
对对对,是这样.呵呵..是每走一步可以比前一个步长大1或小1或与前一个步长相等

一组测试就输出一组结果.

倚天照海花无数,流水高山心自知。
2006-11-12 14:01
shuaiye
Rank: 1
等 级:新手上路
帖 子:445
专家分:0
注 册:2006-5-15
收藏
得分:0 

#include <stdio.h>

int A,B;

long Func(int n){

if(1==n||2==n)

return 1;

else

return (A*Func(n-1)+B*Func(n-2))%7;

}

int main(void){

int n;

printf("input:);

while(3==scanf("%d%d%d",&A,&B,&n)&&A!=0&&B!=0&&n!=0){

printf("Output:%ld\n",Func(n));

printf("input:);

}

return 0;

}



由于工作,N久都没来了!
2006-11-12 14:22
shuaiye
Rank: 1
等 级:新手上路
帖 子:445
专家分:0
注 册:2006-5-15
收藏
得分:0 

[QUOTE]#include <stdio.h>

int A,B;

long Func(int n){

if(1==n||2==n)

return 1;

else

return (A*Func(n-1)+B*Func(n-2))%7;

}

int main(void){

int n;

printf("input:");

while(3==scanf("%d%d%d",&A,&B,&n)&&A!=0&&B!=0&&n!=0){

printf("Output:%ld\n",Func(n));

printf("input:");

}

return 0;

}

晕!上面的忘了加分号。

[/QUOTE]


由于工作,N久都没来了!
2006-11-12 14:25
快速回复:[讨论]第一期题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016417 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved