POJ 1905,3122,3273
做了不想写解题报告,有点水。
POJ 1905:
卡精度的题目,WA到疯了。
代码:
[html]
#include<cstdio>
#include<cmath>
using namespace std;
const double eps = 1e-5;
const double pi = acos(-1.0);
int main()
{
double L, N, C;
while ( scanf("%lf%lf%lf",&L,&N,&C) )
{
if (L < 0 && N < 0 && C < 0) break;
if (L==0 || N==0 || C==0)
{
printf("0.000\n");
continue;
}
double Len = (1+N*C) * L;
double mid, left = 0, right = pi / 2;
double tmp, Sin, ret;
while ( 1 )
{
mid = (left+right) / 2.0;
tmp = mid * L;
Sin = sin(mid);
if ( fabs(tmp-Len*Sin) < eps*Sin ) break;
if ( tmp > Len*Sin ) right = mid;
else left = mid;
}
ret = Len * (1-cos(mid)) / (2 * mid);
printf("%.3lf\n",ret);
}
return 0;
}
POJ 3122 pie
代码:
[cpp]
#include<iostream>
#include<cmath>
using namespace std;
int r[10005];
#define PI 4*atan(1.0)
#define maxn 10000
int main()
{
int t,n,f;
scanf("%d",&t);
while( t--){
scanf("%d%d",&n,&f);
memset(r,0,sizeof(r));
for(int i=0;i<n;i++) scanf("%d",&r[i]);
double low=0,high=PI*maxn*maxn,mid;
while( high-low>0.0001){
mid=(low+high)/2;
int cnt=0;
for(int i=0;i<n;i++)
cnt+=(int)floor(PI*r[i]*r[i]/mid);
if(cnt<f+1) high=mid;
else low=mid;
}
printf("%.4lf\n",low);
}
return 0;
}
POJ 3273
代码:
[cpp]
#include<iostream>
using namespace std;
int a[100005],m,n;
bool ok(int av)
{
int sum,i,j;
for( i=1,j=0;i<=m;i++){
for( sum=0;j<n;j++){
if(sum+a[j]>av) break;
sum+=a[j];
}
if(j==n) return true;
}
return false;
}
int main()
{
int i,sum;
while( scanf("%d%d",&n,&m)!=EOF){
sum=0;
for( i=0;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
int lo=0,high=sum, mid;
while( lo<high){
mid=(lo+high)>>1;
if( ok(mid))
high=mid;
else lo=mid+1;
}
printf("%d\n",lo);
}
return 0;
}
补充:软件开发 , C++ ,