版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lishang6257/article/details/53010449
#include <iostream>
#include <iomanip>
using namespace std;
float abs(float a){
if(a < 0) a = -a;
return a;
}
int main()
{
int n,time;
while(std::cin >> n && n != -1){
time = 0;
int n,m,z;
float d_hm,d_ms,d_hs;
for(m = 0;m < 12;m ++){
for(n = 0;n < 60;n ++){
d_hm = abs(m*30 + n/180. - n*6);
if(d_hm < n) continue;
for(z = 0;z < 60;z ++){
d_ms = abs(6*n - 6*z);
d_hs = abs(n/180. + 30*m - 6*z);
if(d_ms < n || d_hs < n) continue;
time += 1;
}
}
}
std::cout << time << endl;
std::cout << setprecision(3) << time / (12*3600.) << std::endl;
}
return 0;
#include <iomanip>
using namespace std;
float abs(float a){
if(a < 0) a = -a;
return a;
}
int main()
{
int n,time;
while(std::cin >> n && n != -1){
time = 0;
int n,m,z;
float d_hm,d_ms,d_hs;
for(m = 0;m < 12;m ++){
for(n = 0;n < 60;n ++){
d_hm = abs(m*30 + n/180. - n*6);
if(d_hm < n) continue;
for(z = 0;z < 60;z ++){
d_ms = abs(6*n - 6*z);
d_hs = abs(n/180. + 30*m - 6*z);
if(d_ms < n || d_hs < n) continue;
time += 1;
}
}
}
std::cout << time << endl;
std::cout << setprecision(3) << time / (12*3600.) << std::endl;
}
return 0;
}
这是大数处理,极端数据要能跑过