Good Bye 2018(有待更新)

本文提供了CodeForces竞赛中四道题目的详细解答代码,包括简单的数学问题、坐标排序匹配、因数分解求和以及递推计算组合数的题目。通过这些代码,读者可以了解如何运用C++解决算法竞赛中的常见问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://codeforces.com/contest/1091

(最近快期末考了,只贴了代码。。。)

第一题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =1e5+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int x,y,z;

int main()
{
    cin>>x>>y>>z;
    int ans=0;
    if(x+1<=y&&x+2<=z) ans=max(ans,3*x+3);
    if(y-1<=x&&y+1<=z) ans=max(ans,3*y);
    if(z-1<=y&&z-2<=x) ans=max(ans,3*z-3);
    cout<<ans<<endl;
    return 0;
}

第二题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =1e3+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

struct node
{
    int x,y;
    bool operator<(const node& q) const
    {
        if(x==q.x) return y<q.y;
        return x<q.x;

    }
};
node a[maxn],b[maxn];
int main()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
    for(int i=1;i<=n;i++) cin>>b[i].x>>b[i].y;
    sort(a+1,a+n+1);
    sort(b+1,b+1+n);
    cout<<a[1].x+b[n].x<<" "<<a[1].y+b[n].y<<endl;


    return 0;
}

第三题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =1e5+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll ans[maxn],n;

int main()
{
    cin>>n;
    ans[0]=1LL*n*(n+1)/2;
    int tot=1;
    for(int i=2;1LL*i*i<=n;i++) if(n%i==0)
    {
        ll x=n/i;
        ans[tot++]=1LL*x*(x-1)/2*i+1LL*x;
        if(n/i!=i)
        {
            x=i;
            ans[tot++]=1LL*x*(x-1)/2*(n/x)+1LL*x;
        }
    }
    ans[tot++]=1LL;
    sort(ans,ans+tot);
    for(int i=0;i<tot;i++)
    {
        if(i==0) cout<<ans[i];
        else cout<<" "<<ans[i];
    }
    puts("");
    return 0;
}

第四题:

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

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))

#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)

const int  maxn =1e6+5;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll res[maxn];
ll n;

int main()
{
    res[1]=1LL;
    for(int i=2;i<maxn;i++) res[i]=res[i-1]*i%mod;
    cin>>n;
    res[n]=res[n]*n%mod;
    ll tmp=1LL;
    for(ll i=n;i>=2;i--)
    {
        tmp=tmp*i%mod;
        res[n]=(res[n]-tmp+mod)%mod;
    }
    cout<<res[n]<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值