杭电oj2047-2049、2051-2053、2056、2058

2047  阿牛的EOF牛肉串

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,i;
 5     _int64 s[51];
 6     while(~scanf("%d",&n)){
 7         s[1]=3;s[2]=8;
 8         for(i=3;i<=n;i++){
 9             s[i] = s[i-1]*2 + s[i-2]*2;
10         }
11         printf("%I64d\n",s[n]);
12     }
13
14
15 }

2048  神、上帝以及老天爷

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,m,i;
 5     _int64 s[21][2];
 6     while(~scanf("%d",&n)){
 7         while(n--){
 8             scanf("%d",&m);
 9             s[1][0] = 0;s[2][0] = 1;s[1][1] = 1;s[2][1] = 2;
10             for(i=3;i<=m;i++){
11                 s[i][0] = (i-1)*(s[i-1][0] + s[i-2][0]);
12                 s[i][1] = s[i-1][1] * i;
13             }
14             printf("%.2lf%%\n",s[m][0]*100.00/s[m][1]);
15         }
16     }
17
18 }

转一个错排公式

错排公式推导:

当n个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用D(n)表示,那么D(n-1)就表示n-1个编号元素放在n-1个编号位置,各不对应的方法数,其它类推.

第一步,把第n个元素放在一个位置,比如位置k,一共有n-1种方法;

第二步,放编号为k的元素,这时有两种情况:⑴把它放到位置n,那么,对于剩下的n-1个元素,由于第k个元素放到了位置n,剩下n-2个元素就有D(n-2)种方法;⑵第k个元素不把它放到位置n,这时,对于这n-1个元素,有D(n-1)种方法;

综上得到

D(n) = (n-1) [D(n-2) + D(n-1)]
---------------------
作者:程序小白_龙
来源:CSDN
原文:https://blog.csdn.net/dragon_dai_2017/article/details/70880960
版权声明:本文为博主原创文章,转载请附上博文链接!

2049  不容易系列之(4)——考新郎

 1 #include<stdio.h>
 2
 3 int main(){
 4     int c,n,m,i,j;
 5     _int64 s[21],num1,num2;
 6     s[1] = 0;s[2] = 1;
 7     for(i=3;i<21;i++){
 8         s[i] = (i-1)*(s[i-1] + s[i-2]);
 9     }
10     while(~scanf("%d",&c)){
11         while(c--){
12             scanf("%d %d",&n,&m);
13             j=n;num1=1;num2=1;
14             for(i=m;i>0;i--){
15                 num1 *= j;
16                 num2 *= i;
17                 j--;
18             }
19             printf("%I64d\n",num1/num2*s[m]);
20         }
21     }
22
23 }

2051  Bitset

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,i,j,s[50];
 5     while(~scanf("%d",&n)){
 6         i=0;
 7         while(n/2>=1){
 8             s[i] = n%2;
 9             i++;
10             n /= 2;
11         }
12         s[i] = 1;
13         for(j=i;j>=0;j--){
14             printf("%d",s[j]);
15         }
16         printf("\n");
17     }
18
19
20 }

2052   Picture

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,m,i,j;
 5     char s[80][80];
 6     while(scanf("%d %d",&n,&m)!=EOF){
 7         for(i=0;i<=m+1;i++){
 8             for(j=0;j<=n+1;j++){
 9                 if(i==0 || i==m+1){
10                     s[i][j] = ‘-‘;
11                 }else if(j==0 || j==n+1){
12                     s[i][j] = ‘|‘;
13                 }else{
14                     s[i][j] = ‘ ‘;
15                 }
16             }
17         }
18         s[0][0] = ‘+‘;s[0][n+1] = ‘+‘;
19         s[m+1][0] = ‘+‘;s[m+1][n+1] = ‘+‘;
20         for(i=0;i<=m+1;i++){
21             for(j=0;j<=n+1;j++){
22                 printf("%c",s[i][j]);
23             }
24             printf("\n");
25         }
26         printf("\n");
27     }
28 }

2053   Switch Game

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,i,count;
 5     while(~scanf("%d",&n)){
 6         count = 0;
 7         for(i=1;i<=n;i++){
 8             if(n%i==0){count++;}
 9         }
10         if(count%2==0){printf("0\n");}
11         else{printf("1\n");}
12     }
13 }

2056  Rectangles

 1 #include<stdio.h>
 2
 3 void sort(double s[]){
 4     int i,j;
 5     double temp;
 6     for(i=1;i<5;i++){
 7         for(j=4;j>i;j--){
 8             if(s[i]>s[j]){
 9                 temp = s[i];
10                 s[i] = s[j];
11                 s[j] = temp;
12             }
13         }
14     }
15
16 }
17
18 int main(){
19     int i,j;
20     double x[10],y[10],temp;
21     while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[1],&y[1],&x[2],&y[2],&x[3],&y[3],&x[4],&y[4])){
22         if((x[3]>x[1]&&x[4]>x[1]&&x[3]>x[2]&&x[4]>x[2])||(x[3]<x[1]&&x[4]<x[1]&&x[3]<x[2]&&x[4]<x[2])||(y[3]>y[1]&&y[4]>y[1]&&y[3]>y[2]&&y[4]>y[2])||(y[3]<y[1]&&y[4]<y[1]&&y[3]<y[2]&&y[4]<y[2])){
23             printf("0.00\n");
24         }else{
25             sort(x);
26             sort(y);
27             printf("%.2lf\n",(x[3]-x[2])*(y[3]-y[2]));
28         }
29     }
30 }

2058  The sum problem

 1 #include<stdio.h>
 2 #include<math.h>
 3
 4 int main(){
 5     int n,m,i,a;
 6     while(~scanf("%d %d",&n,&m)){
 7         if(n==0&&m==0){break;}
 8         for(i=sqrt(m*2);i>0;i--){
 9             a = (m-(i-1)*i/2)/i;
10             if(a*i+i*(i-1)/2==m){
11                 printf("[%d,%d]\n",a,a+i-1);
12             }
13         }
14         printf("\n");
15     }
16 }

原文地址:https://www.cnblogs.com/Ragd0ll/p/10498821.html

时间: 2024-11-07 16:13:48

杭电oj2047-2049、2051-2053、2056、2058的相关文章

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

杭电 acm 2053 ( Switch Game )

这题思路: 一开始有n盏灯,且全部为关闭状态,都记为 0  就是  The initial condition :      0 0 0 0 0 … 然后之后进行i操作就是对这些灯以是否能被i整除,进行改变状态,如将 0 改为 1 或 将 1 改为 0 正如提醒里的 After the first operation :  1 1 1 1 1 … After the second operation : 1 0 1 0 1 … After the third operation :  1 0 0

杭电 2049

不容易系列之(4)--考新郎 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21384    Accepted Submission(s): 7874 Problem Description 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b