湖南大学程序设计竞赛新生赛(重现赛)

比赛地址

A
思路:直接递归求斐波那契然后求

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;
const int N=50;
ll F[N];

ll fib()
{
    F[1]=F[2]=1;
    for(int i=3;i<=45;i++){
        F[i]=F[i-1]+F[i-2];
    }
}

ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    fib();
    while(t--){
        ll m,n;
        cin>>m>>n;
        ll d=F[gcd(m,n)];
        cout<<d<<endl;
    }
    return 0;
}

B
思路:数学构造,直接构造1^2 , 5 ^ 2, 7 ^ 2的三个数,输入a以后直接按a的5倍输出b,a的7倍输出c,只有a为0的时候构造不可行,找不到这样的三个数满足要求,输出-1,像这种数据范围跑到1e9平方以后1e18的,要警惕一下,然后他又只要求输出数学结果,很有可能是数学规律题,或者是考察数学构造法,一般来说只要想到了马上就能写,代码一般都很短,看到这种类似数学题的就想一下是不是规律题,或者是不是能够通过构造把他变成规律题,从而解决它

#include<cstdio>
#include<cmath>

typedef long long ll;

bool isqrt(ll n)
{
    ll m=floor(sqrt(n)+0.5);
    if(m*m==n)return true;
    return false;
}

int main()
{
    ll a;
    scanf("%lld",&a);
    if(a<0)a=-a;
    if(a==0)puts("-1");
    else printf("%lld %lld\n",5*a,7*a);
    return 0;
}

H
思路:数学,等比数列前n项和,直接输出结果就行,公比为1/2

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

int quick_pow(int x,int y)
{
    int ans=1;
    while(y){
        if(y&1)ans=ans*x;
        x=x*x;
        y>>=1;
    }
    return ans;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        double ans=1.0-1.0/(double)(quick_pow(2,n));
        printf("%.4lf\n",ans);
    }
    return 0;
}

L
思路:变相问l到r区间内素数个数,这里需要注意一下,0和1要特判,因为题目要求是不超过3个正整数因子,因此0不算,1算,素数也算,而数据范围比较小,1e5,直接for一下遍历区间然后试除法判定素数即可

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

bool isprimes(int n)
{
    if(n==0)return false;
    if(n==1)return true;
    for(int i=2;i<=n/i;i++){
        if(n%i==0)return false;
    }
    return true;
}

int main()
{
    int l,r;
    scanf("%d%d",&l,&r);
    int cnt=0;
    for(int i=l;i<=r;i++){
        if(isprimes(i))cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

M
思路:规律题,先打印出1~20区间内的异或和:
【1,2】:3
【1,3】:0
【1,4】:4
【1,5】:1
【1,6】:7
【1,7】:0
【1,8】:8
【1,9】:1
【1,10】:11
【1,11】:0
【1,12】:12
【1,13】:1
【1,14】:15
【1,15】:0
【1,16】:16
【1,17】:1
【1,18】:19
【1,19】:0
【1,20】:20

观察可以发现规律:r%4=0时直接打印r,r%4=1时打印1,r%4=2时打印r+1,r%4==3时打印0,这样推广到左端点为l,则1用l-1以后套进规律然后抑或上r套进规律以后的到的解即得结果

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

typedef long long ll;

ll sum(ll n)
{
    if(n%4==1)return 1;
    else if(n%4==2)return n+1;
    else if(n%4==3)return 0;
    return n;
}

int main()
{
    ll l,r;
    scanf("%lld%lld",&l,&r);
    printf("%lld\n",sum(l-1)^sum(r));
    return 0;
}

J
思路:博弈论

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;

const int N=5e4+10;
ll a[N];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1&&a[0]%2==0)puts("DaDa");
    else puts("TuTu");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值