随笔分类 -  递推

摘要:Given an equilateral triangle with n the length of its side, program to count how many triangles in it.InputThe length n (n <= 500) of the equilateral triangle's side, one per line.process to the end of the fileOutputThe number of triangles in the equilateral triangle, one per line.Sample Inp 阅读全文
posted @ 2012-10-06 16:27 欧阳生朵 阅读(383) 评论(0) 推荐(0)
摘要:突破蝙蝠的包围,yifenfei来到一处悬崖面前,悬崖彼岸就是前进的方向,好在现在的yifenfei已经学过御剑术,可御剑轻松飞过悬崖。现在的问题是:悬崖中间飞着很多红,黄,蓝三种颜色的珠子,假设我们把悬崖看成一条长度为n的线段,线段上的每一单位长度空间都可能飞过红,黄,蓝三种珠子,而yifenfei必定会在该空间上碰到一种颜色的珠子。如果在连续3段单位空间碰到的珠子颜色都不一样,则yifenfei就会坠落。比如经过长度为3的悬崖,碰到的珠子先后为 “红黄蓝”,或者 “蓝红黄” 等类似情况就会坠落,而如果是 “红黄红” 或者 “红黄黄”等情况则可以安全到达。现在请问:yifenfei安然抵达彼 阅读全文
posted @ 2012-10-05 11:04 欧阳生朵 阅读(318) 评论(0) 推荐(0)
摘要:我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。 Input输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。Output对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。Sample Input212Sample Output27View Code 1 #include<iostream> 2 #include<stdio.h> 阅读全文
posted @ 2012-10-05 10:10 欧阳生朵 阅读(1163) 评论(0) 推荐(0)
摘要:HDU 2006'10 ACM contest的颁奖晚会隆重开始了!为了活跃气氛,组织者举行了一个别开生面、奖品丰厚的抽奖活动,这个活动的具体要求是这样的:首先,所有参加晚会的人员都将一张写有自己名字的字条放入抽奖箱中;然后,待所有字条加入完毕,每人从箱中取一个字条;最后,如果取得的字条上写的就是自己的名字,那么“恭喜你,中奖了!”大家可以想象一下当时的气氛之热烈,毕竟中奖者的奖品是大家梦寐以求的Twins签名照呀!不过,正如所有试图设计的喜剧往往以悲剧结尾,这次抽奖活动最后竟然没有一个人中奖!我的神、上帝以及老天爷呀,怎么会这样呢?不过,先不要激动,现在问题来了,你能计算一下发生这种 阅读全文
posted @ 2012-10-05 10:03 欧阳生朵 阅读(275) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 int n; 4 int a[5]; 5 int main() 6 { 7 int m,i; 8 while(~scanf("%d %d",&n,&m)) 9 {10 a[0]=1; 11 a[1]=2;12 a[2]=4;13 a[3]=6;14 if(n<=3)15 printf("%d\n",a[n]%m);16 else17 {1... 阅读全文
posted @ 2012-06-23 23:44 欧阳生朵 阅读(266) 评论(0) 推荐(0)
摘要:1 import java.util.*; 2 import java.math.*; 3 public class Main 4 { 5 public static void main(String []args) 6 { 7 Scanner cin=new Scanner(System.in); 8 int i,n; 9 while(cin.hasNext())10 { 11 n=cin.nextInt();12 BigInteger... 阅读全文
posted @ 2012-06-23 23:42 欧阳生朵 阅读(342) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;int n;int main(){ int i; __int64 a[52]; a[1]=3; a[2]=6; a[3]=6; for(i=4;i<51;i++) a[i]=a[i-1]+a[i-2]*2; while(~scanf("%d",&n)) { printf("%I64d\n",a[n]); } return 0;}做了不少的递推题目了,发现了这些题目的结果一般都与前面或者前面的前面的结果有很大关系,自己以后做这种类型的... 阅读全文
posted @ 2012-06-23 23:39 欧阳生朵 阅读(179) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 int n; 4 int main() 5 { 6 int C; 7 int a[21],i; 8 scanf("%d",&C); 9 while(C--)10 {11 scanf("%d",&n);12 a[0]=0;13 a[1]=3;14 a[2]=7;15 for(i=3;i<=20;i++)16 {17 a[i]=a[i-1]*2+a... 阅读全文
posted @ 2012-06-23 23:36 欧阳生朵 阅读(145) 评论(0) 推荐(0)
摘要:1 #include <stdio.h> 2 3 #define MAX 31 4 5 int main() 6 { 7 int arr[MAX] ={1,3}; 8 int t,i,j,n; 9 10 scanf("%d",&t);11 12 for(i = 0;i < t;i++)13 {14 scanf("%d",&n);15 for(j = 2;j < n;j++)16 arr[j] = 2*arr[j-2] + arr[j-1];17 printf("%d\n",ar... 阅读全文
posted @ 2012-06-23 23:33 欧阳生朵 阅读(317) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 int n; 4 int main() 5 { 6 int s[55]; 7 while(~scanf("%d",&n)&&n) 8 { 9 int i;10 s[0]=0;11 for(i=1;i<=4;i++)12 s[i]=i;13 s[5]=6;14 s[6]=9;15 s[7]=13;16 for(i=8;i<=54;i++)17 ... 阅读全文
posted @ 2012-06-23 23:31 欧阳生朵 阅读(174) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int T,a,b,i; 6 scanf("%d",&T); 7 while(T--) 8 { 9 scanf("%d %d",&a,&b);10 __int64 f0=1,f1=1,f;11 if(b-a==0||b-a==1)12 printf("1\n");13 else14 {15 for(i=2;i<... 阅读全文
posted @ 2012-06-23 23:29 欧阳生朵 阅读(169) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int N,M,i; 6 scanf("%d",&N); 7 while(N--) 8 { 9 scanf("%d",&M);10 __int64 f1=1,f2=1,f;11 if(M==1||M==2)12 printf("1\n");13 else14 {15 for(i=3;i<=M;i++)16 ... 阅读全文
posted @ 2012-06-23 23:25 欧阳生朵 阅读(329) 评论(0) 推荐(0)