四题情况:
第一题 96%
第二题 100%
第三题 50%
第四题 0
代码
Q1
第一题大佬帮我看看还有什么情况,我剩下4%的样例实在是没想出来
import java.util.Scanner; public class Main1 { public static void main(String[] args){ Scanner in = new Scanner(System.in); int K = in.nextInt(); int N = in.nextInt(); int count = 0; int dis = K; int flag = 0; if(K==0){ flag = 1; } for(int i = 1 ; i <= N ; i++){ int tmp = in.nextInt(); if(tmp == dis){ flag = 1; break; } if(tmp < dis){ dis = dis - tmp; }else{ dis = tmp - dis; count += 1; } } if(flag == 1){ System.out.println("paradox"); }else{ System.out.println(dis + " "+count); } } }
Q2
第二题我直接用面向对象的思想做了,写的有点麻烦了,直接写了个色子类
package PDD_exam; import java.util.HashMap; import java.util.Scanner; import java.util.Arrays; class ball{ int up; int front; int right; int down; int back; int left; public ball(int u , int d, int l , int r , int f, int b){ up = u; front = f; right = r; down = d; back = b; left = l; } public void turn_front(){ int tmp = this.front; this.front = this.up; this.up = this.back; this.back = this.down; this.down = tmp; } public void turn_right(){ int tmp = this.up; this.up = this.left; this.left = this.down; this.down = this.right; this.right = tmp; } public void turn_shun(){ int tmp = this.front; this.front = this.right; this.right = this.back; this.back = this.left; this.left = tmp; } public boolean judge(ball test){ // System.out.print("yeee"); if(this.up == test.up){ if(this.down != test.down){ return false; } if(this.equals(test)){ return true; } test.turn_shun(); if(this.equals(test)){ return true; } test.turn_shun(); if(this.equals(test)){ return true; } test.turn_shun(); if(this.equals(test)){ return true; } return false; }else{ test.turn_front(); if(test.up == this.up){ return this.judge(test); } test.turn_front(); if(test.up == this.up){ return this.judge(test); } test.turn_front(); if(test.up == this.up){ return this.judge(test); } test.turn_front(); if(test.up == this.up){ return this.judge(test); } test.turn_right(); if(test.up == this.up){ return this.judge(test); } test.turn_right(); if(test.up == this.up){ return this.judge(test); } test.turn_right(); if(test.up == this.up){ return this.judge(test); } test.turn_right(); if(test.up == this.up){ return this.judge(test); } return false; } } public void print(){ System.out.println(up + " " + down + " " + left + " " +right + " " + front + " " + back); } @Override public boolean equals(Object other) { return (this.up == ((ball)other).up && this.front == ((ball)other).front && this.right == ((ball)other).right && this.back == ((ball)other).back && this.left == ((ball)other).left && this.down == ((ball)other).down); } } public class Main2 { public static void main(String[] args){ Scanner in = new Scanner(System.in); HashMap<ball , Integer> map = new HashMap<>(); int num = in.nextInt(); for(int i = 0 ; i < num ; i++){ int up = in.nextInt(); int down = in.nextInt(); int left = in.nextInt(); int right = in.nextInt(); int front = in.nextInt(); int back = in.nextInt(); ball tmp = new ball(up,down,left,right,front,back); int flag = 0; for(ball test : map.keySet()){ if(test.judge(tmp)){ map.put(test,map.get(test)+1); flag = 1; break; } } if(flag == 0){ map.put(tmp,1); } } int count = map.size(); System.out.println(count); int[] res = new int[count]; int index = 0; for(ball test:map.keySet()){ res[index] = map.get(test); index += 1; } Arrays.sort(res); for(int i = res.length - 1 ; i >= 0 ; i--){ if(i == res.length - 1){ System.out.print(res[i]); }else{ System.out.print(" "+res[i]); } } } }
Q3
第三题没什么时间了,直接暴力拿了一半分。代码就不放了
Q4
目测DP,但没时间做了。
综上
自己真的太菜了,发个帖记录一下算了。第二题那里有个bug找了一点时间,忘了色子要转四次才变回原样。
也希望看看大佬们可以帮我看看第一题到底哪里的样例错漏了
全部评论
(1) 回帖