SDUT 2021 Winter Individual Contest - N(Gym - 100971)

48 篇文章 0 订阅
34 篇文章 0 订阅

B - Derangement

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

int n;
int dp[N];
int tot;
int vis[N];

void solve(){
    cin>>n;
    rep(i,1,n){
        cin>>dp[i];
        if(dp[i]==i) vis[tot++]=i;
    }
    if(tot%2==0){
        cout<<tot/2<<endl;
        for(int i=0;i<tot;i+=2){
            cout<<vis[i]<<" "<<vis[i+1]<<endl;
        }
    }
    else{
        cout<<(tot/2)+1<<endl;
        for(int i=0;i<tot-1;i+=2){
            cout<<vis[i]<<" "<<vis[i+1]<<endl;
            swap(dp[vis[i]],dp[vis[i+1]]);
        }
        int ans=vis[tot-1];
        if(dp[1]!=ans) cout<<1<<" "<<ans<<endl;
        else if(dp[2]!=ans) cout<<2<<" "<<ans<<endl;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

C - Triangles

题目链接

这个题,用puts wa了两次,用puts就不过很离谱

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

int dp[N];

void solve(){
    int n;
    cin>>n;
    rep(i,1,n) cin>>dp[i];
    sort(dp+1,dp+1+n);
    int maxn=dp[1]+dp[2];
    int minn=dp[n]-dp[1];
    if(maxn-minn>1){
        cout<<"YES"<<endl;
        cout<<minn+1<<endl;
    }
    else cout<<"NO"<<endl;;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

D - Laying Cables

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

struct node{
    int x;
    int p;
    int i;
}dp[N];

int vis[N];
bool operator<(node a,node b){
    return a.x<b.x;
}


bool cmp(node x,node y){
    return x.p>y.p;
}

void solve(){
    int n;
    cin>>n;
    rep(i,1,n){
        cin>>dp[i].x>>dp[i].p;
        dp[i].i=i;
    }
    sort(dp+1,dp+1+n,cmp);
    set<node> st;
    vis[dp[1].i]=-1;
    st.insert(dp[1]);
    rep(i,2,n){
        set<node>::iterator it=st.lower_bound(dp[i]),index;
        if(it==st.begin()) vis[dp[i].i]=it->i;
        else if(it==st.end()){
            it--;
            vis[dp[i].i]=it->i;
        }
        else{
            index=it;
            it--;
            if((abs(it->x-dp[i].x)<abs(index->x-dp[i].x))||(abs(it->x-dp[i].x)==abs(index->x-dp[i].x)&&it->p>index->p)) vis[dp[i].i]=it->i;
            else vis[dp[i].i]=index->i;
        }
        st.insert(dp[i]);
    }
    rep(i,1,n){
        if(i==n) cout<<vis[i]<<endl;
        else cout<<vis[i]<<" ";
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

F - Two Points

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

double chan(double k){
    return k*k;
}

double judge(double x1,double y1,double x2,double y2){
    return sqrt(chan(x1-x2)+chan(y1-y2));
}

void solve(){
    int x1,y1;
    int x2,y2;
    int a1,b1;
    int a2,b2;
    cin>>x1>>y1>>x2>>y2;
    cin>>a1>>b1>>a2>>b2;
    int x=chan(a1-a2)+chan(b1-b2);
    int y=(a1-a2)*(x1-x2)+(b1-b2)*(y1-y2);
    y<<=1;
    if(!x){
        printf("%.15f\n",judge(x1,y1,x2,y2));
        return ;
    }
    double temp=y/(x*(-2.0));
    if(temp+eps<0) temp=0;
    printf("%.15f\n",judge(x1+a1*temp,y1+b1*temp,x2+a2*temp,y2+b2*temp));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

G - Repair

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

void solve(){
    int a,b;
    cin>>a>>b;
    int a1,b1;
    int a2,b2;
    cin>>a1>>b1>>a2>>b2;
    int ma=max(a1,a2);
    int mb=max(b1,b2);
    int mx=max(b1,a2);
    int my=max(a1,b2);
    if((a1+a2<=a&&mb<=b)||(a1+a2<=b&&mb<=a)) puts("YES");
    else if((a1+b2<=a&&mx<=b)||(a1+b2<=b&&mx<=a)) puts("YES");
    else if((b1+a2<=a&&my<=b)||(b1+a2<=b&&my<=a)) puts("YES");
    else if((b1+b2<=a&&ma<=b)||(b1+b2<=b&&ma<=a)) puts("YES");
    else puts("NO");
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

K - Palindromization

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

void solve(){
    string s;
    cin>>s;
    int tot=0;
    int pos=0;
    rep(i,1,2){
        int l=0;
        int r=(int)s.size()-1;
        tot=0;
        while(l<=r){
            if(s[l]==s[r]) {
                l++;
                r--;
            }
            else{
                tot++;
                if(i==1){
                    pos=l;
                    l++;
                }
                if(i==2){
                    pos=r;
                    r--;
                }
            }
        }
        if(tot<2){
            cout<<"YES"<<endl;
            if(!tot) cout<<((int)s.size()/2+1)<<endl;
            else cout<<pos+1<<endl;
            break;
        }
    }
    if(tot>1) cout<<"NO"<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

L - Chess Match

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

int arr[N];
int brr[N];

void solve(){
    int n;
    cin>>n;
    rep(i,1,n) cin>>arr[i];
    rep(i,1,n) cin>>brr[i];
    sort(arr+1,arr+1+n);
    sort(brr+1,brr+1+n);
    int suma=0;
    int sumb=0;
    int j=1;
    rep(i,1,n){
        if(j<=n&&arr[i]>brr[j]) {
            suma++;
            j++;
        }
    }
    j=1;
    rep(i,1,n){
        if(j<=n&&brr[i]>arr[j]) {
            sumb++;
            j++;
        }
    }
    if(suma*2>n&&sumb*2<=n) puts("First");
    else if(suma*2<=n&&sumb*2>n) puts("Second");
    else if(suma*2<=n&&sumb*2<=n) puts("None");
    else if(suma*2>n&&sumb*2>n) puts("Both");
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值