22/7/7

1,cf Nicholas and Permutation;2,cf Circle Coloring


1,Nicholas and Permutation

题意:给你一次交换数组两个元素的机会,输出最大元素和最小元素的距离的绝对值;

思路:直接4个答案取max;

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i) 
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i) 
#define per1(i,n,a) for(register int i=(n);i>(a);i--) 
#define per2(i,n,a) for(register int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define pb push_back
#define pf push_front
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define yi first
#define er second
#define INF 0x3f3f3f3f
#define tulun() int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
using namespace std;
typedef long long LL;
typedef double dob;
const int N=1e3+10;
int a[N];
int n;

signed main()
{
    quick_cin();
    cin>>n;
    int maxx=INT_MIN,minn=INT_MAX;
    rep2(i,1,n)
    {
        cin>>a[i];
        maxx=max(maxx,a[i]);
        minn=min(minn,a[i]);
    }
    int idmax,idmin;
    rep2(i,1,n)
    {
        if(a[i]==maxx)idmax=i;
        if(a[i]==minn)idmin=i;
    }
    cout<<max(max(idmax-1,n-idmax),max(idmin-1,n-idmin));
    return 0;
}

2,Circle Coloring

题意:有a,b,c,三个序列;你需要创造一个序列p,使得pi属于(ai,bi,ci)并且,pi的相邻元素互不相等,包括pn-1 pn p1(看作环);

思路:直接选,注意不重复就行;

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i) 
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i) 
#define per1(i,n,a) for(register int i=(n);i>(a);i--) 
#define per2(i,n,a) for(register int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define pb push_back
#define pf push_front
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define yi first
#define er second
#define INF 0x3f3f3f3f
#define tulun() int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define moreT int T;cin>>T;while(T--)solve();
using namespace std;
typedef long long LL;
typedef double dob;
const int N=1e3+10;
int a[N],b[N],c[N];
int n;
int p[N];

void solve()
{
    cin>>n;
    memset(p,0,p);
    rep2(i,1,n)cin>>a[i];
    rep2(i,1,n)cin>>b[i];
    rep2(i,1,n)cin>>c[i];
    p[1]=a[1];
    rep2(i,2,n-1)
    {
        if(a[i]==p[i-1])p[i]=b[i];
        else p[i]=a[i];
    }
    if(a[n]!=p[1]&&a[n]!=p[n-1])p[n]=a[n];
    else if(b[n]!=p[1]&&b[n]!=p[n-1])p[n]=b[n];
    else p[n]=c[n];
    rep2(i,1,n)cout<<p[i]<<" ";
    cout<<endl;
}

signed main()
{
    quick_cin();
    moreT;

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Dull丶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值