CSU 1391 Boiling Vegetables

暴力枚举。。。


1391: Boiling Vegetables

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 21   Solved: 10
[ Submit][ Status][ Web Board]

Description

CSU 1391 Boiling Vegetables_第1张图片

Input

Output

CSU 1391 Boiling Vegetables_第2张图片

Sample Input

0.99 3
2000 3000 4000

Sample Output

6

HINT

CSU 1391 Boiling Vegetables_第3张图片

Source

[ Submit][ Status][ Web Board] 한국어    中文    فارسی    English    ไทย

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

double vagetable[1100],limit;
int n;

int main()
{
    cin>>limit>>n;
    for(int i=0;i<n;i++) cin>>vagetable[i];

    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }

    sort(vagetable,vagetable+n,less<double>());

    int ans=501;

    for(int i=0;i<n;i++)
    {
        for(int c=0;c<ans;c++)
        {
            double maxsize=vagetable[i]/(c+1);
            double minsize=maxsize*limit;

            int temp=c;
            bool flag=true;

            for(int j=0;j<n;j++)
            {
                if(i==j) continue;

                int c1=(int)ceil(vagetable[j]/maxsize)-1;

                if(vagetable[j]/(c1+1) < minsize)
                {
                    flag=false; break;
                }
                temp+=c1;
                if(temp>=ans)
                {
                    flag=false; break;
                }
            }
            if(flag)
            {
                ans=min(ans,temp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}





你可能感兴趣的:(CSU 1391 Boiling Vegetables)