hdoj1495 是分可乐的,分类为search,泊松分酒是解决给你一瓶酒,两个杯子,用这两个杯子能否平分这瓶酒的问题。 我用泊松分酒的方法来做分可乐,但是结果tle了,另外对于泊松分酒的解法我还是不太明白,但是代码如下,只是超时了 import java.util.*; public class Main1495 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cup1v,cup2v,cup3v; while(sc.hasNextInt()) { cup1v = sc.nextInt(); cup2v = sc.nextInt(); cup3v = sc.nextInt(); if(cup1v == 0) { return; } else { if(cup1v%2!=0) { System.out.println("NO"); } else { int m=0; if(cup2v < cup3v) { m = probe(cup1v, cup3v, cup2v); } else { m = probe(cup1v, cup2v, cup3v); } if(m < 0) { System.out.println("NO"); } else { System.out.println(m); } } } } } static int probe(int cup1v, int cup2v, int cup3v) { int n=0, cup2=0, cup3=0; int half = cup1v/2; while(cup1v!=half || cup2!=half && cup3!=half) { if(cup2==0) { if(cup1v<cup2v) { n = -1; break; } else { cup1v -= cup2v; cup2 = cup2v; } } else if(cup3v == cup3) { cup1v += cup3v; cup3 = 0; } else if(cup2>cup3v-cup3) { cup2 -= (cup3v-cup3); cup3 = cup3v; } else { cup3 += cup2; cup2 = 0; } n ++; } return n; } }