2019ccsp 第一题摘水果(java)

代码有点多,也不够简洁。希望大家不要介意,应该还有更简单的方法吧?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);
        }



    }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值