2017-08-21 20:34
哈尔滨理工大学 Java sb785646:import java.util.Scanner; public class Main1 { static int[] re=new int[1]; static int[] g1=new int[1]; static int[] s1=new int[1]; static int[] b1=new int[1]; static int[] g2=new int[1]; static int[] s2=new int[1]; static int[] b2=new int[1]; public static void main(String[] args) { Scanner in = new Scanner(System.in); g1[0] = in.nextInt(); s1[0]= in.nextInt(); b1[0]= in.nextInt(); g2[0]= in.nextInt(); s2[0]= in.nextInt(); b2[0]= in.nextInt(); getcount(); System.out.print(re[0]); } public static int getcount(){ if(g1[0]>=g2[0]){//无需交换 g1[0]=g1[0]-g2[0]; }else{ if(!leftchange(g1,g1[0]-g2[0],s1)){ if(!leftchange(s1,(g2[0]-g1[0]-s1[0]*11),b1)){ return -1; }else{ leftchange(g1,g2[0]-g1[0],s1); } } } if(s1[0]>=s2[0]){//无需交换 s1[0] = s1[0]-s2[0]; }else{ while(g1[0]>=0&&s1[0]<=s2[0]){ rightchange(g1,1,s1); } if(s1[0]<s2[0] ){ if(!leftchange(s1,s2[0]-s1[0],b1)){ return -1; } } s1[0]=s1[0]-s2[0]; } if(b1[0]>=b2[0]){ return re[0]; }else{ while(b1[0]<=b2[0]){ if(!rightchange(s1,1,b1)){ break; } } if(b1[0]<b2[0]){ if(!rightchange(g1,(b2[0]-b1[0]+80/*防止为0的情况*/)/(9*9),s1)){ return -1; }else{ rightchange(s1,(b2[0]-b1[0]+8)/9,b1); } } } return re[0]; } public static boolean leftchange(int[] h,int count,int[] l){ if( l[0]>= 11*count){ l[0] = l[0]-11*count; h[0]=h[0]+count; re[0] = re[0]+count; return true; }else{ return false; } } public static boolean rightchange(int[] h,int count,int[] l){ if(h[0]>=count){ l[0] = l[0]+ h[0]*count*9; h[0] -=count; re[0] += count; return true; }else{ return false; } } }
0 点赞 评论 收藏
分享
关注他的用户也关注了: