这还是没有考什么几何题物理题,要是考了,岂不完蛋?
代码奇丑无比。。
A: 哦吼?GJC要防AK了?
如果x是y的倍数输出-1,否则输出x。
#include<cstdio>
#include<cctype>
#include<vector>
#include<iostream>
using namespace std;
int x,y;
int main()
{
scanf("%d%d",&x,&y);
if(x%y==0)printf("-1\n");
else printf("%d\n",x);
return 0;
}
B: 730的天花板
斐波那契变形。对于3*n的矩阵,考虑最左边的一列,只有两种选择,要么放2*2的,要么不放。设f(k)为3*k矩阵方案数,如果最左边放2*2,则占了两行,剩下两个位只能放2个1*1的,方案数2*f(n-2),如果不放2*2的,就是只放1*1的,只能放3个1*1的,方案数f(n-1).故递推公式f(n)=f(n-1)+2*f(n-2).递推边界f(1)=f(0)=1。
#include<cstdio>
#include<cctype>
#include<vector>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int t,n,a,b,c;
int f[10000005];
int main()
{
scanf("%d",&t);
f[0]=f[1]=1;
for(int i=2;i<=10000000;i++)f[i]=(f[i-1]+2*f[i-2])%19260817;
while(t--)
{
scanf("%d",&n);
printf("%d\n",f[n]);
}
return 0;
}
C: gugugu
模拟
#include<cstdio>
#include<cctype>
using namespace std;
int t,n;
char s[1005];
bool ok(int n)
{
if(n<=1)return 0;
for(int i=2;i<=n-1;i++)if(n%i==0)return false;
return true;
}
int main()
{
scanf("%d",&t);
int cnt=0;
while(t--)
{
scanf("%s",s);
for(int i=0;s[i];i++)if(tolower(s[i])=='g'&&tolower(s[i+1])=='u')cnt++;
}
printf(ok(cnt)?"gugugu\n":"gu\n");
return 0;
}
D: 不可思议唤来不可思议β
排列组合题,显然枚举会超时。比赛时思路是对的,但是忘了含有重复元素的排列数怎么算,使劲推公式,没有思路,无果,,回来一查,这不是高中数学排列组合裸题吗!
假设有 111223这6个数,如何计算它的全排列呢?先假设这6个数字都不相同,排列共A(6,6)种,但在这A(6,6)种排列中,3个1和2个2是一样的,但被计算了A(3,3),A(2,2)种,因此答案就是A(6,6)/A(3,3)/A(2,2)种,这就是这道题最关键的地方。
先考虑最左边那一位可以填1,2,3三种,可以确定全排列中