http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1391

1391: Boiling Vegetables

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 27  Solved: 14
[Submit][Status][Web Board]

Description

csuoj 1391: Boiling Vegetables-LMLPHP

Input

csuoj 1391: Boiling Vegetables-LMLPHP

Output

csuoj 1391: Boiling Vegetables-LMLPHP

Sample Input

0.99 3
2000 3000 4000

Sample Output

6

HINT

csuoj 1391: Boiling Vegetables-LMLPHP

Source

分析:

暴力枚举。

AC代码;

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; double vagetable[],limit;
int n; int main()
{
cin>>limit>>n;
for(int i=;i<n;i++) cin>>vagetable[i]; if(n==)
{
cout<<<<endl;
return ;
} sort(vagetable,vagetable+n,less<double>()); int ans=; for(int i=;i<n;i++)
{
for(int c=;c<ans;c++)
{
double maxsize=vagetable[i]/(c+);
double minsize=maxsize*limit; int temp=c;
bool flag=true; for(int j=;j<n;j++)
{
if(i==j) continue; int c1=(int)ceil(vagetable[j]/maxsize)-; if(vagetable[j]/(c1+) < minsize)
{
flag=false; break;
}
temp+=c1;
if(temp>=ans)
{
flag=false; break;
}
}
if(flag)
{
ans=min(ans,temp);
}
}
}
cout<<ans<<endl;
return ;
}
 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
double a[];
int main()
{
double T,maxx,minn;
int n,i,j,k,PP,sum,flag;
while(~scanf("%lf%d",&T,&n))
{
PP=;
for(i=;i<n;i++)
scanf("%lf",&a[i]);
for(i=;i<n;i++)
for(j=;j<=;j++)
{
sum=j;flag=;
maxx=a[i]*1.0/(j+);
minn=maxx*T;
for(k=;k<n && flag==;k++)
{
if(k==i)
continue;
int t1=(int)((a[k]-)/maxx);
double t2=a[k]*1.0/(t1+);
if(t2<minn)
{flag=;break;}
sum+=t1;
if(sum>PP)
{flag=;break;} }
if(flag==)
PP=min(PP,sum);
}
printf("%d\n",PP);
}
return ;
}
05-11 15:10