HDU 1006 Tick and Tick
2017-12-05 12:10
429 查看
1006题目的意思是:
一个钟的三个指针在不停的转动,他们已经厌烦了这样,当他们互相的距离角度大于等于D时,他们会很开心,问一天之中他们happy的时间占总时间的概率。
这题想了好久,参考了网上大神,这是他的代码,AC了。使用JAVA来实现这道题。
一个钟的三个指针在不停的转动,他们已经厌烦了这样,当他们互相的距离角度大于等于D时,他们会很开心,问一天之中他们happy的时间占总时间的概率。
这题想了好久,参考了网上大神,这是他的代码,AC了。使用JAVA来实现这道题。
import java.util.Scanner; import java.math.BigDecimal; public class Main{ public static double max(double a,double b,double c) { a=a>b?a:b; a=a>c?a:c; return a; } public static double min(double a,double b,double c) { a=a<b?a:b; a=a<c?a:c; return a; } public static void main(String [] args) { int i,j; //double dsm[1444],dsh[1444],dmh[26]; double[] dsm=new double[1444]; double[] dsh=new double[1444]; double[] dmh=new double[26]; double d,sum,x,y; double sm,mh,sh; int []smf=new int[2]; int []mhf=new int[2]; int []shf=new int[2]; sm=3600.0000/59; sh=43200.0000/719; mh=43200.0000/11; Scanner scan=new Scanner(System.in); while (scan.hasNext()) { d=scan.nextDouble(); if(d==-1) { System.exit(0); } sum=0; x=0; y=0; dsm[0]=(10*d)/59; dsh[0]=(120*d)/719; dmh[0]=(120*d)/11; dsm[1]=sm-dsm[0]; dsh[1]=sh-dsh[0]; dmh[1]=mh-dmh[0]; for (i=2,j=3;;i+=2,j+=2) { dsm[i]=dsm[i-2]+sm; dsm[j]=dsm[j-2]+sm; if (dsm[i]>43200&&dsm[j]>43200) { break; } } for (i=2,j=3;;i+=2,j+=2) { dsh[i]=dsh[i-2]+sh; dsh[j]=dsh[j-2]+sh; if (dsh[i]>43200&&dsh[j]>43200) { break; } } for (i=2,j=3;;i+=2,j+=2) { dmh[i]=dmh[i-2]+mh; dmh[j]=dmh[j-2]+mh; if (dmh[i]>43200&&dmh[j]>43200) { break; } } smf[0]=0; mhf[0]=0; shf[0]=0; smf[1]=1; mhf[1]=1; shf[1]=1; while (y<=43200&&x<=43200) { x=max(dsm[smf[0]],dsh[shf[0]],dmh[mhf[0]]); y=min(dsm[smf[1]],dsh[shf[1]],dmh[mhf[1]]); if(x<y) { sum=sum+(y-x); } if (y==dsm[smf[1]]) { smf[0]+=2; smf[1]+=2; } if(y==dsh[shf[1]]) { shf[0]+=2; shf[1]+=2; } if(y==dmh[mhf[1]]) { mhf[0]+=2; mhf[1]+=2; } } sum=sum/432; BigDecimal sum1=new BigDecimal((sum)); sum1=sum1.setScale(3,BigDecimal.ROUND_HALF_UP); System.out.println(sum1); } } }
相关文章推荐
- hdu 1006 Tick and Tick
- hdu 1006 Tick and Tick (解不等式方程)
- hdu 1006 Tick and Tick
- HDU 1006 Tick and Tick
- HDU:1006 Tick and Tick
- [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]
- hdu 1006 Tick and Tick
- hdu 1006 Tick and Tick 时钟问题
- [HDU]1006 Tick and Tick
- hdu 1006 Tick and Tick 模拟时钟注意时间连续性!
- HDU 1006 Tick and Tick 时钟指针问题
- HDU 1006 Tick and Tick
- hdu 1006 Tick and Tick (解不等式方程)
- HDU-1006 Tick and Tick 几何
- hdu_1006 Tick and Tick(暴力模拟)
- hdu 1006 Tick and Tick 数学+枚举
- HDU 1006 Tick and Tick 模拟
- HDU 1006 Tick and Tick
- HDU 1006 Tick and Tick
- HDU 1006 Tick and Tick( 模拟题)