BZOJ 1505: [NOI2004]小H的小屋

05年的论文题

优化很玄学。。。。。。

贡献了俩WA,成功地拉低了这题的AC率(这题AC率好高啊)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const double inf=1e9;
double k1,k2;
double sqr(double x){return x*x;}
int a[4];
void calc(int m,int n){
	if(n%m){
		a[0]=n%m;
		a[1]=n/m+1;
		a[2]=m-a[0];
		a[3]=a[1]-1;
	}else{
		a[0]=m/2;
		a[1]=a[3]=n/m;
		a[2]=m-a[0];
	}
}
double area(int l,int n){
	calc(n,l);
	int m1=a[0],n1=a[1],m2=a[2],n2=a[3];
	return k1*sqr(l)+k2*(m1*sqr(n1)+m2*sqr(n2));
}
double area(int l,int m,int n){
	calc(m,l);
	int m1=a[0],n1=a[1],m2=a[2],n2=a[3];
	return m1*area(n1,n)+m2*area(n2,n);
}
int m1,n1,m2,n2;
double area(int i){
	return area(i,m1,n1)+area(100-i,m2,n2);
}
int main(){
	//freopen("a.in","r",stdin);
	int m,n;scanf("%lf%lf%d%d",&k1,&k2,&m,&n);
	calc(m,n);
	m1=a[0],n1=a[1],m2=a[2],n2=a[3];
	double q=k1/m2+k2/(m2*n2),p=k1/m1+k2/(m1*n1);
	int i=q*100/(p+q);
	while(true){
		if(i>n1&&area(i-1)<area(i))i--;
		else if(i<100-n2&&area(i+1)<area(i))i++;
		else break;
	}
	printf("%.1lf\n",area(i));
	return 0;
}
			


你可能感兴趣的:(BZOJ 1505: [NOI2004]小H的小屋)