Educational Codeforces Round 117 (Rated for Div. 2)

Educational Codeforces Round 117 (Rated for Div. 2)

A. Distance

  • 构造
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N=1e5+5;
signed main()
{
    ios_base::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int x,y;
        cin>>x>>y;
        int d=x+y;
        if(d&1) { cout<<"-1 -1\n"; continue;}
        d/=2;
        if(x==y) 
        {
            cout<<x<<" 0\n";
        }
        if(x>y)
        {
            cout<<d-y<<' '<<y<<"\n";
        }
        if(x<y) cout<<x<<' '<<d-x<<"\n";
    }
}

B. Special Permutation

  • 构造
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N=1e5+5;
int ans[N],vis[N];
signed main()
{
    ios_base::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int n,a,b;
        cin>>n>>a>>b;
        for(int i=1;i<=n;i++) ans[i]=vis[i]=0;
        vis[a]=vis[b]=1;
        int t=n/2-1,tot=0,fg=1;
        for(int i=n;i>a && t;i--)
        {
            if(!vis[i])
            {
                //cout<<i<<endl;
                ans[++tot]=i;
                vis[i]=1;
                t--;
            }
        }
        if(t) fg=0;
        for(int i=1;i<=n;i++) 
        {
            if(!vis[i] && i>b) fg=0; 
        }
        if(fg==0) cout<<"-1\n";
        else 
        {
            cout<<a<<' ';
            for(int i=1;i<=tot;i++) cout<<ans[i]<<' ';
            cout<<b<<' ';
            for(int i=1;i<=n;i++)
            {
                if(!vis[i]) cout<<i<<' ';
            }cout<<endl;
        }
    }
}

C. Chat Ban

  • 二分边界要注意
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N=1e5+5;
int ans[N],vis[N];
int solve(int x)
{
    int l=1,r=1e9,ans;
    while(l<=r)
    {
        int mid=l+r>>1;
        int t=(1+mid)*mid/2;
        if(t==x) { ans=mid; break; }
        if(t>x) r=mid-1;
        else l=mid+1,ans=mid+1;
    }
    return ans;
}
int solve2(int x)
{
    int l=1,r=1e9,ans;
    while(l<=r)
    {
        int mid=l+r>>1;
        int t=(1+mid)*mid/2;
        if(t==x) { ans=mid; break; }
        if(t>x) r=mid-1;
        else l=mid+1,ans=mid;
    }
    return ans;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int k,x;
        cin>>k>>x;
        int md=(1+k)*k/2, ans=0;
        if(x>md+md-k-1) { cout<<2*k-1<<"\n"; continue; }
        if(x<=md)
        {
            ans=solve(x);
        }
        else 
        {
            ans=2*k-1;
            x=md+md-k-x;
            ans-=solve2(x);
        }
        cout<<ans<<endl;
    }
}

D. X-Magic Pair

  • 注意取模为0的情况
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N=1e5+5;
int gcd(int a,int b,int x)
{
    if(b>a) swap(a,b);
    if(a<x && b<x) return 0;
    if(b==0) // 注意
    {
        if(a==x) return 1;
        else return 0;
    }
    if(a%b==x%b || b==x) return 1;
    else return gcd(b,a%b,x);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int a,b,x;
        cin>>a>>b>>x;
        if(gcd(a,b,x))
        {
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
    }
}

E. Messages

  • 待补充
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yezzz.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值