XMUT第七届蓝桥杯全国软件和信息技术专业人才大赛校内选拔赛模拟赛

181 篇文章 0 订阅
173 篇文章 3 订阅



Problem A:八目鳗烧烤店

Time Limit:1000MS  Memory Limit:65536K
Total Submit:75 Accepted:26

Description

八目鳗烧烤店一共有6个八目鳗,幽幽子一口能吃1到6个八目鳗,求吃完所有的八目鳗共有多少种吃法。 
任意一口吃的八目鳗数量不同,就算不同的吃法。

Input

Output

输出一个整数,表示吃完所有的八目鳗共有多少种吃法。 
不要书写任何多余的内容(例如:添加说明文字等)。

Sample Input

 

Sample Output

 

Hint

#include 

int main() 

printf("这里写答案\n"); 
return 0; 
}



编程思想:简单递推。

AC code:

#include <stdio.h>
#include <math.h>
#include<string.h>
int f[6];
int main()
{
	int i,j;
	memset(f,0,sizeof(f));
	f[1]=1;
	f[2]=2;
	for(i=3;i<=6;i++)
	{
		for(j=1;j<i;j++)
			f[i]+=f[j];
		f[i]++;
	} 
	printf("%d\n",f[6]);
    return 0;
}


roblem B:琪露诺的完美算术教室(三)(Easy)

Time Limit:1000MS  Memory Limit:65536K
Total Submit:140 Accepted:26

Description

 

去年琪露诺又没把结果算出来,这一年里又被当成笨蛋了,但是琪露诺还是不服!为了洗刷被当成笨蛋的耻辱,于是这次她要挑战计算的是A^B mod C(A的B次方对C取余)

Input

输入数据第一行有三个整数A、B、C( 1 <= A,B,C < 10000)。

Output

输出A^B mod C的结果。

Sample Input

3 2 4

Sample Output

1


编程思想:快速幂的应用。

AC  code:

#include <stdio.h>
#include <math.h>
#include<string.h>
#define LL long long
int gcd(int a,int b)
{
	if(a<b)
	{
		int t=a;
		a=b;
		b=t;
	}
	if(b==0) return a;
	else return gcd(b,a%b);
}
LL PowerMod(LL a,LL b,LL c)
{
	LL ans=1;
	a=a%c;
	while(b>0)
	{
		if(b&1) ans=(ans*a)%c;
		b>>=1;
		a=(a*a)%c;
	}
	return ans;
}
int main()
{
	LL a,b,c;
	while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
	{
		printf("%I64d\n",PowerMod(a,b,c));
	}
	return 0;
}


Problem C:琪露诺的完美算术教室(三)(Hard)

Time Limit:1000MS  Memory Limit:65536K
Total Submit:143 Accepted:25

Description

 

去年琪露诺又没把结果算出来,这一年里又被当成笨蛋了,但是琪露诺还是不服!为了洗刷被当成笨蛋的耻辱,于是这次她要挑战计算的是A^B mod C(A的B次方对C取余)

Input

输入数据第一行有三个整数A、B、C(1<=A,C<10000,1<=B<=10^18)。

Output

输出A^B mod C的结果。

Sample Input

3 2 4

Sample Output

1

Hint

用long long代替int可以存储10^18的整数 
对应的输入输出则从%d改为%I64d



编程思想:快速幂。

AC code:

#include <stdio.h>
#include <math.h>
#include<string.h>
#define LL long long
int gcd(int a,int b)
{
	if(a<b)
	{
		int t=a;
		a=b;
		b=t;
	}
	if(b==0) return a;
	else return gcd(b,a%b);
}
LL PowerMod(LL a,LL b,LL c)
{
	LL ans=1;
	a=a%c;
	while(b>0)
	{
		if(b&1) ans=(ans*a)%c;
		b>>=1;
		a=(a*a)%c;
	}
	return ans;
}
int main()
{
	LL a,b,c;
	while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
	{
		printf("%I64d\n",PowerMod(a,b,c));
	}
	return 0;
}


  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值