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;
}