洛谷 P4447分組

2021-10-10 12:00:10 字數 743 閱讀 3671

大致想法是用乙個佇列記錄當前正在進行中分組的起始位置,並記錄當前分組數,若掃瞄到的下乙個數的個數少於當前分組數,則代表當前有一定數量的分組需要就此停止,按照開始順序依次出佇列即可

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace std;

intmain()

int res = int_max;

int num =0;

//表示當前分組數量

queue<

int> record;

int i =0;

for(map<

int,

int>

:: iterator it = store.

begin()

;it!=store.

end(

);i++

) num = q;

++it;

if(it == store.

end())

break;}

if(it-

>first - now!=1)

}}cout << res << endl;

}

洛谷P3940 分組

好題 細節題 答案字典序要求最小,所以考慮倒敘列舉,對於當前一組需要盡量多的加東西,因為後面組選的數越多,前面的選擇機會越多 化列舉序列為列舉值域,這是這道題的關鍵 k 1 倒敘列舉到 i 此時只需判斷當前組中的數是否有加 a i 等於完全平方數的 可以 o n 列舉,但顯然可以更優 列舉所有的完全...

洛谷 P4447 AHOI2018初中組 分組

題目 總共有n個隊員,每個人都有乙個實力值a i 把n個隊員分成若干個小組。要求分成的每個小組的隊員實力值連續,同時,乙個隊不需要兩個實力相同的選手。給出乙個合法的分組方案,滿足所有人都恰好分到乙個小組。使得人數最少的組人數最多,輸出人數最少的組人數的最大值。注意 實力值可能是負數,分組的數量沒有限...

洛谷 P4447 AHOI2018初中組 分組

題目 一開始沒讀懂題,直接排序 模擬找最短長度,像 6 1 2 3 1 2 3這組資料這種查詢方法結果是1,正解是3 include include include include include include include include using namespace std typedef...