团体程序设计天梯赛刷题记录

题目链接


2023.3.24更新

这个博客可能不更啦

但是视频讲解会慢慢更新的~:

更新一个视频连接:主要讲解L1 20分和L2的题,希望今年(2023…)能更新完
团体程序设计天梯赛视频讲解-bilibili


2023.10.8 更新: 因为要准备考试,所以这个视频题解更新得咕到2024了55


L1-009 N个数求和 (20 分)

小模拟,字符串转数字,分数加法模拟,最大公约数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef struct num{
    ll up;
    ll down;
}num;
const int N = 110;
num a[N],sum;
int n;
ll change(string s)
{
    ll res = 0;
    if(s[0]=='-') 
    {
        for(int i = 1;i<s.size();i++)
        {
            res = res*10+(s[i]-'0');
        }
        res = -res;
    }
    else{
        for(int i = 0;i<s.size();i++)
        {
            res = res*10+(s[i]-'0');
        }
    }
    return res;
}
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
void add()
{
    sum = a[0];
    for(int i = 1;i<n;i++)
    {
        ll _lcm = lcm(sum.down,a[i].down);
        sum.up = sum.up*(_lcm/sum.down)+a[i].up*(_lcm/a[i].down);
        sum.down = _lcm;
    }
}
int main()
{
    cin>>n;
    for(int i = 0;i<n;i++)
    {
        string s;
        cin>>s;
        int pos = 0;
        for(int j = 0;j<s.size();j++)
        {
            if(s[j]=='/')
            {
                pos = j;break;
            }
        }
        string up = s.substr(0,pos);
        string down = s.substr(pos+1);
        ll u = change(up),d = change(down);
        a[i] = {u,d};
    }
    add();
    if(sum.up==0)
    {
        cout<<'0';
        return 0;
    }
    ll first = sum.up/sum.down;
    sum.up%=sum.down;
    ll gcd_2 = gcd(sum.up,sum.down);
    sum.up/=gcd_2,sum.down/=gcd_2;
    if(first!=0)
    {
        if(sum.up!=0)
        {
            cout<<first<<' '<<sum.up<<'/'<<sum.down;
        }
        else{
            cout<<first;
        }
    }
    else{
        cout<<sum.up<<'/'<<sum.down;
    }
}

L1-019 谁先倒 (15 分)

需要看清题意

#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main()
{
    cin>>a>>b;
    cin>>n;
    int cnt1 = 0,cnt2 = 0;
    bool flag1 = false,flag2 = false;
    while (n -- ){
        int han1,hua1,han2,hua2;
        cin>>han1>>hua1>>han2>>hua2;
        if(hua1==han1+han2&&hua2==han1+han2)
        {
            continue;
        }
        if(hua1==han1+han2)
        {
            cnt1++;
        }
        if(hua2==han1+han2)
        {
            cnt2++;
        }
        if(cnt1>a){flag1 = true;break;}
        if(cnt2>b){flag2 = true;break;}
    }
    if(flag1)
    {
        cout<<"A\n";
        cout<<cnt2;
    }
    else
    {
        cout<<"B\n";
        cout<<cnt1;
    }
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值