Ural1881(模拟)

来源:互联网 发布:达内软件测试怎么样 编辑:程序博客网 时间:2024/05/17 22:59

题目链接:点击打开链接


解题思路:

处理起来比较麻烦,把长度用数组存起来,然后按照长度去取,去完之后看能分多少行,最后在取页数即可。精彩点在分行那。


完整代码:

#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;    }}

更多精彩请访问:点击打开链接

0 0
原创粉丝点击