acm递推求解(3)

2020-02-21 15:26

对于每个测试实例,请输出发生这种情况的百分比,每个实例的输出占一行, 结果保留两位小数(四舍五入),具体格式请参照sample output。

Sample Input 12

Sample Output 50.00%

Author lcy

Source

递推求解专题练习(For Beginner)

真是我的神

1111111111111111111 #include <stdio.h> int main() {

int z, n, i;

__int64 l, a, b, t;

scanf("%d", &z); while (z--){

scanf("%d", &n); l = 1;

for (i=n; i>1; i--) l *= i;//sum number a = 0; b = 1;

for (i=3; i<=n; i++){ t = (a+b)*(i-1); a = b;//a[2] b = t;//a[3]

}//f[n]=(n-1)*(f[n-1]+f[n-2]) if (n < 3) t = n-1;

printf("%.2lf%%\\n", (double)t*100/l);//格式 }

return 0; }

不容易系列之一

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 17 Accepted Submission(s) : 10 Problem Description

大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。

话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。

不幸的是,这种小概率事件又发生了,而且就在我们身边:

事情是这样的——HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!

现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?

Input

输入数据包含多个多个测试实例,每个测试实例占用一行,每行包含一个正整数n(1<n<=20),n表示8006的网友的人数。

Output

对于每行输入请输出可能的错误方式的数量,每个实例的输出占用一行。

Sample Input 23

Sample Output 12

Author lcy

Source

ACM暑期集训队练习赛(九)

竟这样简单

11111111111111111111 #include <stdio.h> int main() {

int n, i;

__int64 a, b, t;

while(scanf("%d", &n)!=EOF) {

a = 0; b = 1;

for (i=3; i<=n; i++){ t = (a+b)*(i-1);

a = b; b = t; }

if (n < 3) t = n-1;

printf("%I64d%\\n", t); }

return 0; }

折线分割平面

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 3 Accepted Submission(s) : 2 Problem Description

我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。

Input

输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。

Output

对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。

Sample Input 212

Sample Output 27

Author lcy

Source

递推求解专题练习(For Beginner) 蒙了

111111111

#include<stdio.h> int t(int n) { int c;

if(n==1)c=2;

else c=t(n-1)+4*n-3;//关键 return c; }

int main() {

int t(int n); int n,i,m;

scanf("%d",&n); for(i=0;i<n;i++) {

scanf("%d",&m); printf("%d\\n",t(m));

}

return 0; }

Children’s Queue

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 6 Accepted Submission(s) : 2 Problem Description

There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM

Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?

Input

There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)

Output

For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.

Sample Input 123

Sample Output 124

Author

SmallBeer (CML)


acm递推求解(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《摩擦力的秘密》教案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: