[Codecforces]1011 B. Planning The Expedition

題目URL : http://codeforces.com/problemset/problem/1011/B

其實稍微想一下這題,二分搜......嗎......不 ! 看了看範圍即可想到一個很邪惡的作法------對 ! brute force !
掃過去邊 input 邊標記一下,j 為天數,用 i 掃過去除,再用人數 tot 去減,tot < = 0就輸出囉~至於我的 j 為何由大到小去掃,讀者們不妨思考一下~~ =w=

#include<bits/stdc++.h>
using namespace std;
int str[1005];
main()
{
    int a,b,x,ans=0;
    cin >> a >> b;
    for(int i=0;i<b;i++)
    {
        cin >> x;
        str[x]++;
    }
    int tot;
    for(int j=100;j>=1;j--)
    {
        tot=a;
        for(int i=1;i<=100;i++)
            tot-=str[i]/j;
        if(tot<=0)
        {
            ans=j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}





(其實由小到大依我所知要判到 tot > 0 後 ans 要減 1 之類的我覺得好煩 XD 深怕特判例外隱藏其中所以走簡單且保險的路線)

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP