这次题都偏构造啊。。。写的代码都觉得有点奇怪。
({frak{A - XORwice }})
直接异或。
({frak{code}})
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=1e5+3;
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
int t=in(),a,b;
while(t--){
a=in(),b=in();
printf("%d
",a^b);
}
return 0;
}
({frak{B - Putting Bricks in the Wall }})
考虑 ((1,2)) ,((2,1)) , ((n,n-1)) , ((n-1,n)),发现只要改这 (4) 个点就好了。
({frak{code}})
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=2e2+3;
int n,op1,op2;
char s[N][N];
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
int t=in(),cnt=0;
while(t--){
n=in();cnt=0;
for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
int s1=s[1][2]-'0',s2=s[2][1]-'0',s3=s[n][n-1]-'0',s4=s[n-1][n]-'0';
if(s1==s2) op1=s1,op2=op1^1;
else if(s4==s3){op2=s3,op1=op2^1;}
else op1=0,op2=1;
if(s1^op1) ++cnt;
if(s2^op1) ++cnt;
if(s3^op2) ++cnt;
if(s4^op2) ++cnt;
printf("%d
",cnt);
if(s1^op1) printf("%d %d
",1,2);
if(s2^op1) printf("%d %d
",2,1);
if(s3^op2) printf("%d %d
",n,n-1);
if(s4^op2) printf("%d %d
",n-1,n);
}
return 0;
}
({frak{C - Palindromifier }})
多操作几遍就能构造出来了。
({frak{code}})
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=1e5+3;
int n,m,bo[130];
char s[N];
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
void solve1(){printf("R 2
R %d
L %d
L 2
",n-1,3*n-4);}
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
if(n>3) printf("2
"),solve1();
else printf("6
R 2
R 2
"),n=n*4-6,solve1();
return 0;
}
({frak{D - Hexagons}})
先将 (6) 个方向相互更新,然后贪心走最少的次数。
({frak{code}})
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=1e5+3;
LL n,m,c[7],vis[7];
queue<int>q;
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
void C1(){
if(c[6]>c[1]+c[5]){
c[6]=c[1]+c[5];
if(!vis[6]) q.push(6);
}
if(c[2]>c[1]+c[3]){
c[2]=c[1]+c[3];
if(!vis[2]) q.push(2);
}
}
IL int Mod(int x){return x<0?x+6:x;}
IL int mod(int x){return x>=6?x-6:x;}
void gx(int x){
int x1=Mod(x-1),x2=mod(x+1),y1=Mod(x-2),y2=mod(x+2);
if(c[x1]>c[x]+c[y1]){
c[x1]=c[x]+c[y1];
if(!vis[x1]) q.push(x1);
}
if(c[x2]>c[x]+c[y2]){
c[x2]=c[x]+c[y2];
if(!vis[x2]) q.push(x2);
}
}
void spfa(){
for(int i=0;i<6;++i) q.push(i),vis[i]=1;
while(q.size()){
int u=q.front();q.pop();
gx(u);vis[u]=0;
}
}
int main()
{
int t=in();
while(t--){
n=in(),m=in();
for(int i=0;i<6;++i) c[i]=in();
spfa();
if(n==0){
if(m<0) printf("%lld
",-m*c[4]);
else printf("%lld
",m*c[1]);
}
else if(n>0){
if(m>0){
if(n>m) printf("%lld
",m*c[0]+(n-m)*c[1]);
else printf("%lld
",n*c[0]+(m-n)*c[5]);
}
else printf("%lld
",n*c[5]-m*c[4]);
}
else{
if(m>=0) printf("%lld
",-n*c[2]+m*c[1]);
else{
if(-n>-m) printf("%lld
",-m*c[3]+(m-n)*c[2]);
else printf("%lld
",-n*c[3]+(n-m)*c[4]);
}
}
}
return 0;
}
({frak{E - Swedish Heroes }})
找规律并枚举,用前缀和快速求出答案。
({frak{code}})
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=2e5+3;
struct hh{
int val,pos;
bool operator<(const hh &a) const{
return val<a.val;}
}a[N];
int n;
LL s[N],ans=-1e18;
IL int mod(int x){return x>=3?x-3:x;}
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
n=in();
for(int i=1;i<=n;++i) a[i]=(hh){in(),i};
sort(a+1,a+n+1);
for(int i=1;i<=n;++i) s[i]=s[i-1]+a[i].val;
if(n==1) return printf("%d
",a[1].val),0;
for(int i=mod(1-n%3+3);i<=n;i+=3){
if(i*2+1==n){
int flag=0;
for(int j=1;j<=i;++j)
if(a[j].pos&1) flag=1;
if(!flag){
LL del=a[i].val-a[i+1].val;
ans=max(ans,s[n]-2*s[i]+2*del);
}
else ans=max(ans,s[n]-2*s[i]);
}
else ans=max(ans,s[n]-2*s[i]);
}
printf("%lld
",ans);
return 0;
}