杭电oj2040-2049————C语言

方便自己复习回顾
我在vc++编译的所以用__int64定义超级大数
2040亲和数
http://acm.hdu.edu.cn/showproblem.php?pid=2040

#include <stdio.h>
int main()
{
	int i,m;int a;
	scanf("%d",&a);
	while(a--){
		scanf("%d%d",&i,&m);
		int sum1=0,sum2=0;
		for(int j=1;j<i;j++){
    		if(i%j==0) {sum1+=j;}//求余相加就行
		}
		for(int n=1;n<m;n++){
    		if(m%n==0) {sum2+=n;}
		}
		if(sum1==m&&sum2==i) {printf("YES\n");}
		else {printf("NO\n");}
	}
	return 0;
}

2041超级楼梯
http://acm.hdu.edu.cn/showproblem.php?pid=2041

#include < stdio.h>
int main(){
	int n, x = 0, a[45] = {1,1,1,2};
	for (int i = 4; i <= 41;i++)
		a[i]= a[i - 1] + a[i - 2];

 	scanf("%d", &n);
 	while(n--){
 		scanf("%d",&x);
 		printf("%d\n",a[x]);
 	}
	return 0;
}

2042不容易系列之二
http://acm.hdu.edu.cn/showproblem.php?pid=2042

#include<stdio.h>
int main()
{
	int m,j;
	scanf("%d",&j);
	while(j--){
		int sum1=3,sum2=0;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			sum2=(sum1-1)*2;
			sum1=sum2;
		}
		printf("%d\n",sum1);
	}
	return 0;
}

2043密码
http://acm.hdu.edu.cn/showproblem.php?pid=2043

#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
	int i,j;char c[50];
	scanf("%d%*c",&j);
	while(j--){
		scanf("%s",c);
		int n=strlen(c),sum1=0,sum2=0,sum3=0,sum4=0;
		int t=0;

		for(i=0;i<n;i++){
    		if(islower(c[i])) {sum1++;}
    		else if(isupper(c[i])) {sum2++;}
    		else if(isdigit(c[i])) {sum3++;}
    		else {sum4++;}
		}
		if(sum1!=0) {t++;}
		if(sum2!=0) {t++;}
		if(sum3!=0) {t++;}
		if(sum4!=0) {t++;}

		if(n>=8&&n<=16&&t>=3)
			{printf("YES\n");}
		else
			{printf("NO\n");}
	}
	return 0;
}

2044一只小蜜蜂…
http://acm.hdu.edu.cn/showproblem.php?pid=2044

#include <stdio.h>
int main()
{
	__int64 s[50]={1,1,2};//数大会溢出
	int j,a,b;
	for(int i=3;i<50;i++){
   		s[i]=s[i-1]+s[i-2];
   	}

	scanf("%d",&j);
	while(j--){
    	scanf("%d%d",&a,&b);
    	printf("%I64d\n",s[b-a]);
	}
	return 0;
}

2045不容易系列之(3)—— LELE的RPG难题
http://acm.hdu.edu.cn/showproblem.php?pid=2045

思路:// n>=4时,考虑前n-1格已经定了情况(合法),由于首尾颜色不同,如果是加1格的话,其颜色只有1种可选,所以如果n格是从n-1格的基础上加一格而来,那么涂法数量是相同的,即这种情况f(n)=f(n-1);//考虑前n-2格已经定了情况,n-1取与第1格颜色相同(这个情况不会与前n-1格合法重叠),那么第n格有2种颜色可选,即这种情况f(n)=f(n-2)*2。综合这两种情况得f(n)=f(n-2)*2。

#include <stdio.h>
int main() { 
    int n, i;
    __int64 a[50]={3, 6, 6};   
    for(i=3; i<50; i++)
       { a[i] = a[i-1] + a[i-2] * 2;}

    while(~scanf("%d", &n)) {
        printf("%I64d\n", a[n-1]);
    }
    return 0;
}

2046题骨牌铺方格
http://acm.hdu.edu.cn/showproblem.php?pid=2046
又是斐波那契数列

#include <stdio.h>
int main()
{
    __int64 a[51]={0,1,2};int n;
    for(int i=3;i<=50;i++)
        a[i]=a[i-1]+a[i-2];
    while(~scanf("%d",&n))
    {
        printf("%I64d\n",a[n]);
    }
	return 0;
}

2047阿牛的EOF牛肉串
http://acm.hdu.edu.cn/showproblem.php?pid=2047

#include <stdio.h>
int main()
{
	int n;
	__int64 s[40]={3,8};
	for(int i=2;i<40;i++)
		{s[i]=2*(s[i-1]+s[i-2]);}

	while(~scanf("%d",&n)){
		printf("%I64d\n",s[n-1]);
	}
	return 0;
}

2048、2049这两题很相似

2048神、上帝以及老天爷
http://acm.hdu.edu.cn/showproblem.php?pid=2048

#include <stdio.h>
int main(){
    int c,i;
    scanf("%d",&c);
    while(c--){
        int n;
        scanf("%d",&n);
        double a[20]={1,2},b[20]={2,6};
        
        for(i=2;i<20;i++){
            a[i]=(i+1)*(a[i-1]+a[i-2]);
            b[i]=b[i-1]*(i+2);
        }
	 printf("%.2lf%%\n",a[n-2]/b[n-2]*100);
	 }
     return 0;
}

2049不容易系列之(4)——考新郎
http://acm.hdu.edu.cn/showproblem.php?pid=2049

#include<stdio.h>
int main(){
    int c;
    scanf("%d",&c);
    while(c--){
        int n,m,i,j,b=1;
        scanf("%d%d",&n,&m);
        __int64 a[21]={0,0,1,2},s;
        
        for(i=3;i<=m;i++)
            a[i]=(i-1)*(a[i-1]+a[i-2]);//把m个人全排错的可能种数存放在数组a中,全排错参见2048
            
        for(i=n-m+1,j=1;i<=n;i++,j++)
            b=b*i/j;//计算n个人当中m个人的选取种数
        s=b*a[m];
        printf("%I64d\n",s);
    }
    return 0;
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值