Ural1881(模擬)

題目鏈接:點擊打開鏈接


解題思路:

處理起來比較麻煩,把長度用數組存起來,然後按照長度去取,去完之後看能分多少行,最後在取頁數即可。精彩點在分行那。


完整代碼:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
string s;
const int maxn = 10001;
int res[maxn];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    int a , b , c;
    while(cin >> a >> b >> c)
    {
        for(int i = 0 ; i < c ; i ++)
        {
            cin >> s;
            int len = s.length();
            res[i] = len;
        }
        int cnt = 0;
        for(int i = 0 ; i < c ; )
        {
            int sum = res[i];
            int j = i + 1;
            while(sum + 1 + res[j] <= b)
            {
                sum += 1 + res[j];
                j ++;
            }
            i = j;
            cnt ++;
        }
        int k = cnt % a == 0 ? cnt / a : cnt / a + 1;
        cout << k << endl;
    }
}

更多精彩請訪問:點擊打開鏈接
發佈了403 篇原創文章 · 獲贊 20 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章