ACM第三次课件.ppt2017/11/23
1
第一类
技巧型
2017/11/23
2
1021 i Again
2017/11/23
3
Problem Description
There are another kind of i numbers:
F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
2017/11/23
4
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
Output
Print the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.
2017/11/23
5
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
2017/11/23
6
2017/11/23
6
题目分析:
判断某一项是否能被3 整除
是否需要把某一项的值求出来,进行整除判断?
能被3整除的整数的特点?
关于能否被3整除,这样的项在排列上是否有规律?
(找出规律)
第0项除以3余1,第1项除以3余2,第2项整除,
第3项除以3余2,第4项除以3余2,第5项除以3余1,
第6项整除,第7项除以3余1,第8项除以3余1,
第9项除以3余2,第7项整除…….
2017/11/23
7
题目分析:
能被3整除的整数的特点?
如果两个数的和能被3整除,这两个数有什么特点?
关于能否被3整除,这两个数一共有多少种组合?
2017/11/23
8
Hdoj_1021程序清单:
#include<>
int main()
{
long n;
while(scanf("%ld",&n) != EOF)
if (n%8==2 || n%8==6)
printf("yes\n");
else
printf("no\n");
return 0;
}
2017/11/23
9
#include <>
int main()
{
int n;
while(scanf("%d", &n) !=EOF)
{
if((n - 2) % 4)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
2017/11/23
10
#include<>
int main()
{
int F1,F2,i,t;
long n;
while(scanf("%ld",&n)!=EOF)
{
F1=1;
F2=2;
for(i=2;i<=n;i++)
{
t=F2;
F2=(F1+F2)%3;
F1=t;
}
if(n<2)
printf("no\n");
else if(F2==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
ACM第三次课件 来自淘豆网www.taodocs.com转载请标明出处.