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
Input
Output
Sample Input
0.99 32000 3000 4000
Sample Output
6
HINT
Source
Analysis:
Brute Force enumeration.
AC Code;
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5#include <cmath>6 7 using namespacestd;8 9 Doublevagetable[1100],limit;Ten intN; One A intMain () - { -Cin>>limit>>N; the for(intI=0; i<n;i++) cin>>Vagetable[i]; - - if(n==1) - { +cout<<0<<Endl; - return 0; + } A atSort (vagetable,vagetable+n,less<Double>()); - - intcn1=501; - - for(intI=0; i<n;i++) - { in for(intC=0; c<ans;c++) - { to Doublemaxsize=vagetable[i]/(c+1); + Doubleminsize=maxsize*limit; - the inttemp=C; * BOOLflag=true; $ Panax Notoginseng for(intj=0; j<n;j++) - { the if(I==J)Continue; + A intC1= (int) Ceil (vagetable[j]/maxsize)-1; the + if(Vagetable[j]/(c1+1) <minsize) - { $flag=false; Break; $ } -temp+=C1; - if(temp>=ans) the { -flag=false; Break;Wuyi } the } - if(flag) Wu { -ans=min (ans,temp); About } $ } - } -cout<<ans<<Endl; - return 0; A}View Code
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <iostream>5 using namespacestd;6 Doublea[1009];7 intMain ()8 {9 DoubleT,maxx,minn;Ten intN,i,j,k,pp,sum,flag; One while(~SCANF ("%lf%d",&t,&N)) A { -pp= -; - for(i=0; i<n;i++) thescanf"%LF",&a[i]); - for(i=0; i<n;i++) - for(j=0; j<= -; j + +) - { +sum=j;flag=0; -maxx=a[i]*1.0/(j+1); +minn=maxx*T; A for(k=0; K<n && flag==0; k++) at { - if(k==i) - Continue; - intT1= (int) ((a[k]-1)/Maxx); - Doublet2=a[k]*1.0/(t1+1); - if(t2<Minn) in{flag=1; Break;} -sum+=T1; to if(sum>PP) +{flag=1; Break;} - the } * if(flag==0) $pp=min (pp,sum);Panax Notoginseng } -printf"%d\n", PP); the } + return 0; A}View Code
Csuoj 1391:boiling Vegetables