您的位置:首页 > 其它

UVa 1388 Graveyard 墓地雕塑

2014-01-16 10:16 344 查看
圆上的等距N个点,每个点相距360/N 度,增加M个点后,每个点相距360/(N+m)度,这N个点可顺时针或逆时针移动

每次取移动的最小值即可算出ans

代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<limits.h>
using namespace std;
double min(double x,double y)
{
return x< y? x: y;
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
double d1,d2;
d1= 360.0 / n;
d2= 360.0 / (n+m);
double ans= 0.0;
for(int i=1,j=1; i< n && j<= n+m; j++)
{
double t1,t2,t3;
t1= i* d1;
t2= j* d2;
t3= (j+1)* d2;
if(t1>= t2 && t1<= t3)
{
ans+= min(t1- t2, t3- t1);
i++;
}
}
ans= ans/360;
printf("%.4lf\n",ans*10000);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: