标签:asn string round down blog ati cpp set scanner
import java.math.BigDecimal; import java.util.Scanner; public class Main{ public static void main(String[] args){ BigDecimal two=new BigDecimal(2); BigDecimal three=new BigDecimal(3); BigDecimal five=new BigDecimal(5); //二分求sqrt(5) BigDecimal l=two, r=three; for(int i=0; i<500; i++){ BigDecimal mid=l.add(r).divide(two); if(mid.multiply(mid).compareTo(five)<0) l=mid; else r=mid; } BigDecimal gold=l.add(BigDecimal.ONE).divide(two); BigDecimal a, b; Scanner cin=new Scanner(System.in); while(cin.hasNext()){ a=cin.nextBigDecimal(); b=cin.nextBigDecimal(); if(a.compareTo(b)>0){//保证a<=b BigDecimal tmp=a; a=b; b=tmp; } //向下取整,统一精度 a=a.setScale(0, BigDecimal.ROUND_DOWN); b=b.subtract(a).multiply(gold); b=b.setScale(0, BigDecimal.ROUND_DOWN); if(a.compareTo(b)==0) System.out.println("0"); else System.out.println("1"); } } }
某个佐夫的博弈:基本上用到的东西都用到了。
标签:asn string round down blog ati cpp set scanner
原文地址:http://www.cnblogs.com/Heilce/p/7225468.html