csuoj 1391: Boiling Vegetables
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1391
1391: Boiling Vegetables
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 27 Solved: 14
[Submit][Status][Web Board]
Description
Input
Output
Sample Input
0.99 3
2000 3000 4000
Sample Output
6
HINT
Source
分析:
暴力枚举。
AC代码;
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 #include <cmath> 6 7 using namespace std; 8 9 double vagetable[1100],limit; 10 int n; 11 12 int main() 13 { 14 cin>>limit>>n; 15 for(int i=0;i<n;i++) cin>>vagetable[i]; 16 17 if(n==1) 18 { 19 cout<<0<<endl; 20 return 0; 21 } 22 23 sort(vagetable,vagetable+n,less<double>()); 24 25 int ans=501; 26 27 for(int i=0;i<n;i++) 28 { 29 for(int c=0;c<ans;c++) 30 { 31 double maxsize=vagetable[i]/(c+1); 32 double minsize=maxsize*limit; 33 34 int temp=c; 35 bool flag=true; 36 37 for(int j=0;j<n;j++) 38 { 39 if(i==j) continue; 40 41 int c1=(int)ceil(vagetable[j]/maxsize)-1; 42 43 if(vagetable[j]/(c1+1) < minsize) 44 { 45 flag=false; break; 46 } 47 temp+=c1; 48 if(temp>=ans) 49 { 50 flag=false; break; 51 } 52 } 53 if(flag) 54 { 55 ans=min(ans,temp); 56 } 57 } 58 } 59 cout<<ans<<endl; 60 return 0; 61 }
1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<iostream> 5 using namespace std; 6 double a[1009]; 7 int main() 8 { 9 double T,maxx,minn; 10 int n,i,j,k,PP,sum,flag; 11 while(~scanf("%lf%d",&T,&n)) 12 { 13 PP=600; 14 for(i=0;i<n;i++) 15 scanf("%lf",&a[i]); 16 for(i=0;i<n;i++) 17 for(j=0;j<=500;j++) 18 { 19 sum=j;flag=0; 20 maxx=a[i]*1.0/(j+1); 21 minn=maxx*T; 22 for(k=0;k<n && flag==0;k++) 23 { 24 if(k==i) 25 continue; 26 int t1=(int)((a[k]-1)/maxx); 27 double t2=a[k]*1.0/(t1+1); 28 if(t2<minn) 29 {flag=1;break;} 30 sum+=t1; 31 if(sum>PP) 32 {flag=1;break;} 33 34 } 35 if(flag==0) 36 PP=min(PP,sum); 37 } 38 printf("%d\n",PP); 39 } 40 return 0; 41 }
悠游天地间 all rights reserved. © 2013 -- 1 << 64