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

来源:互联网 发布:安全炒股软件 编辑:程序博客网 时间:2024/06/11 17:34



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 longint 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 longint 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;}


0 0
原创粉丝点击