A - Tick and Tick
HDU - 1006
Input
Output
Sample Input
0
120
90
-1
Sample Output
100.000
0.000
6.251
题意:时钟的三针厌倦了重叠的生活,他们觉得和另外两个保持一定的角度才会开心。给出角度,求一天中他们开心的时间占全天的百分比。
分析:原来想着一天不过43200秒,直接模拟就行了。结果怎么测数据都对不到,后来看了其他人的题解才知道这里的时间是连续的……
但是只要计算单位足够小,暴力出答案还是没问题的(因为题解里解方程的代码看不懂_(:з」∠)_ )
最后以0.0001秒为单位时,AC(我的笔记本大概跑了9分钟吧……)
暴力代码:
#include<iostream>
#include<math.h>
#define e 0.00000001
using namespace std;
double num[121];
int main(){
int n;
double h=0,m=0,s=0;
int cnt=0;
for(int n=0;n<=120;n++){
if(n==-1) return 0;
h=0; m=0; s=0; cnt=0;
while(360-h > e ){
s+=0.0006; //1秒加6 以千分之一秒为单位
m+=0.0006/60;
h+=0.0006/60/12;
if(s-360.0 >= 0) s=0.0;
if(m-360.0 >= 0) m=0.0;
double d1,d2,d3;
d1=fabs(s-m); d2=fabs(s-h); d3=fabs(m-h);
if(d1-180 > 0) d1=360.0-d1;
if(d2-180 > 0) d2=360.0-d2;
if(d3-180 > 0) d3=360.0-d3;
if(d1-n>=0 && d2-n>=0 && d3-n>=0) cnt++;
// cout<<s<<" "<<m<<" "<<h<<" "<<cnt<<endl;
}
num[n] = (double)(cnt)*100/432000000; // 43200 * 1000
cout<<num[n]<<endl;
}
for(int i=0;i<=120;i++)
printf("%.3lf,",num[i]);
}
提交代码: #include<iostream>
using namespace std;
double num[121]={100.000,98.340,96.694,95.061,93.443,91.839,90.249,88.672,87.110,85.562
,84.027,82.507,81.001,79.508,78.030,76.565,75.114,73.676,72.252,70.841
,69.445,68.063,66.694,65.340,64.000,62.673,61.361,60.062,58.778,57.507
,56.251,55.008,53.779,52.562,51.360,50.172,48.997,47.838,46.692,45.560
,44.443,43.339,42.249,41.173,40.111,39.064,38.030,37.010,36.002,35.008
,34.029,33.063,32.111,31.174,30.250,29.340,28.444,27.563,26.695,25.841
,25.001,24.175,23.363,22.565,21.779,21.007,20.250,19.506,18.776,18.060
,17.359,16.671,15.997,15.338,14.693,14.061,13.444,12.841,12.252,11.675
,11.112,10.563,10.028,9.507,9.000,8.507,8.028,7.562,7.111,6.674,6.251,
5.842,5.446,5.065,4.697,4.342,4.001,3.674,3.361,3.062,2.777,2.506,2.249
,2.005,1.776,1.561,1.360,1.172,0.999,0.840,0.695,0.562,0.444,0.340,0.249
,0.173,0.110,0.062,0.027,0.007,0.000};
int main(){
int n;
while(cin>>n){
if(n==-1) return 0;
else printf("%.3lf\n",num[n]);
}
}