代码有点多,也不够简洁。希望大家不要介意,应该还有更简单的方法吧?emmm,我只想到这种。
[http://history.ccfccsp.org.cn/2019/0-tasks.pdf]
import java.util.Scanner;
class pack{
int apple;
int pear;
int appleAdd;
int pearAdd;
int value;
public pack() {在这里插入代码片
}
public pack(int apple, int pear, int appleAdd, int pearAdd, int value) {
this.apple = apple;
this.pear = pear;
this.appleAdd = appleAdd;
this.pearAdd = pearAdd;
this.value = value;
}
}
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []a = new int[2*n+1];
int []b = new int[2*n+1];
int []state = new int[2*n+1];
for(int i=1;i < a.length;i++){
a[i] = sc.nextInt();
}
for(int i=1;i < b.length;i++){
b[i] = sc.nextInt();
state[b[i]]++;
}
//n次
for(int i=1; i<=n;i++){
pack max = new pack();
for(int x=1;x<=n;x++){
if(state[x]==0 && a[x]>=0){
//苹果可取的
for(int y=n+1;y<=2*n;y++){
if(state[y]==0 && a[y]>=0){
if((a[x]^a[y]) == max.value){
if(a[x]==max.apple){
if(x == max.appleAdd){
//梨编号
if(y>max.pearAdd){
max = new pack(a[x],a[y],x,y,a[x]^a[y]);
}
}
//苹果编号
if(x>max.appleAdd){
max = new pack(a[x],a[y],x,y,a[x]^a[y]);
}
}
//分情况 苹果美味度
if(a[x]>max.apple){
max = new pack(a[x],a[y],x,y,a[x]^a[y]);
}
}
if((a[x]^a[y])>max.value){
//直接换
max = new pack(a[x],a[y],x,y,a[x]^a[y]);
}
}
}
}
}
state[b[max.appleAdd]]--;
state[b[max.pearAdd]]--;
a[max.appleAdd]= -1;
a[max.pearAdd] = -1;
System.out.println(max.value);
}
}
}