UVA 12482 Short Story Competition

简介: 给你一篇短故事,求至少需要几页纸才能容纳这篇段故事,已知短故事有N个单词,每页能容纳L行,每行能容纳C个字符,这里要注意每个单词后有一个空格,一个单词只能在同一行。

Maratona de Programação da SBC – ACM ICPC – 2012                                                              

                                                Problem A

                                Short Story Competition

   Machado wants to be a writer.       He has written many short stories,  book reviews,  reports of trips

he made, and a little romance.  Now Machado wants to take part in a short story competition, which

has very strict rules about the submission format.

   The  rules  of  the  competition  limit  the  number  of  total  pages,  and  specify  the  maximum  number

of characters per line, and the maximum number of lines per page.           Additionally, each word must be

written integrally in one line (ie, a word cannot be separated in two lines).  Machado wants to write a

story with as many words as possible within the rules of the contest, and needs your help.

   Given  the  maximum  number  of  characters  per  line,  the  maximum  number  of  lines  per  page,  and

the words of the short story that Machado is writing, he wants to know the minimum number of pages

that his short story will ocuppy, considering the rules of the contest.

Input

   The  first  line  of  a  test  case  contains  three  integers  N, L and  C,  which  indicate,  respectively,  the

number of words of the short story, the maximum number of lines per page and the maximum number

of  characters  per  line. Machado’s  short  story  is  innovative  and  contains  no  characters  besides  upper

and  lower  case  letters  and  blanks. The  second  line  contains  Machado’s  short  story,  consisting  of  N

words separated by exactly one blank space.

Output

   For each test case your program must output a single line containing a single integer indicating the

minimum number of pages the short story will ocuppy, considering the contest rules.

Restrictions

   • 2 ≤ N ≤ 1000

   • 1 ≤ L ≤ 30

   • 1 ≤ C ≤ 70

   • 1 ≤ length of each word  ≤ C

Example

Sample Input

14 4 20

Se mana Piedade tem casado com Quincas Borba apenas me daria uma esperanca colateral

16 3 30

No dia seguinte entrou a dizer de mim nomes feios e acabou alcunhando me Dom Casmurro

5 2 2

a de i de o

5 2 2

a e i o u

Sample output

2

1

3

3


题意:给你一篇短故事,求至少需要几页纸才能容纳这篇段故事,已知短故事有N个单词,每页能容纳L行,每行能容纳C个字符,这里要注意每个单词后有一个空格,一个单词只能在同一行。


思路:数据较小,直接定义二维数组算出每个单词的长度,然后一个个找下去即可。


#include<stdio.h>
#include<string.h>
char a[1111][77];
int b[1111];
int main()
{
  int n,l,c,sum,flag,i;
  while(scanf("%d %d %d",&n,&l,&c)!=EOF)
  {
    for(i=0;i<n;i++)
      scanf("%s",a[i]);
    for(i=0;i<n;i++)
      b[i]=strlen(a[i]);
    sum=0;
    flag=0;
    for(i=0;i<n;i++)
    {
      if(flag+b[i]<=c)
      {
        flag+=b[i];
        flag++;
      }
      else
      {
        sum++;
        flag=0;
        i--;
      }
    }
    if(flag!=0)
      sum++;
    if(sum%l==0)
      printf("%d\n",sum/l);
    else
      printf("%d\n",sum/l+1);
  }
  return 0;
}

相关文章
|
2月前
|
弹性计算 固态存储 测试技术
阿里云服务器收费标准2026年最新:轻量38元与ECS 99元、199元爆款配置全解析
2026年阿里云推出三档高性价比服务器:38元/年轻量(2核2G,适合个人博客与学习)、99元/年ECS(2核2G+ESSD+VPC,入门生产首选)、199元/年ECS(2核4G+60G ESSD,适配数据库与容器)。本文详解配置、场景与避坑指南,助你理性选型。
578 1
|
3月前
|
存储 人工智能 安全
阿里云服务器经济型e实例:99元/年起续费同价,企业级SLA保障,从技术特性到最优选型全解析
本文聚焦预算有限的个人开发者、学生及小微企业的上云痛点,全面解析阿里云经济型e实例这款入门级共享云服务器。内容覆盖其搭载英特尔可扩展处理器的技术架构、多档规格参数,拆解建站、开发测试等适配场景,详解99元/年起且续费同价的特惠政策,同时给出针对性选型、成本优化的实用选购策略,是入门用户低成本上云的实用参考指南。
|
3月前
|
缓存 人工智能 JSON
阿里云Qwen3.7‑Plus深度解析:多模态智能体模型能力、分档定价、上下文约束与API开发实战与调用排坑教程
在AI智能体产业化落地的浪潮下,单纯文本能力已经难以满足真实业务诉求,大量业务场景需要模型同时看懂截图、UI界面、图表、视频内容,把视觉信息转化成代码、操作指令、分析结论。Qwen3.7‑Plus作为3.7系列主打高性价比的多模态混合智能体模型,核心定位就是打通视觉感知与智能体执行闭环,在保留强大文本推理、编码、工具调用能力的基础上,大幅强化视觉‑语言融合理解,支持百万级上下文窗口,单次最高处理2048张图片以及64段视频,能够完成UI截图生成代码、GUI模拟操作、多模态办公自动化等完整业务流程。该模型面向全球五大区域完成部署,不同地域的功能支持、计费标准存在明显区分,仅华北2(北京)地域开放
757 1
micropython esp8266+ssd1306(OLED) 显示中文(示例)
1.Adafruit_SSD1306 OLED显示库使用Adafruit_SSD1306:https://github.com/adafruit/Adafruit_SSD1306 连接示例: 库使用示例: >>> from ...
8166 0
|
4月前
|
缓存 C++ Python
VS Code中选择Python解释器后,右侧仍显示“Select Python Interpreter”,终端仍为(base)环境。
VS Code中选择Python解释器后,右侧仍显示“Select Python Interpreter”,终端仍为(base)环境。此为环境缓存问题,解决方法:打开命令面板(Ctrl+Shift+P),执行“Python: Clear Cache and Reload Window”,或手动删除Python Environments配置即可恢复正常。
460 0
|
5月前
|
人工智能 JSON Java
Spring AI 集成 Qwen3.7-Max 实战:从 Chat 到 Function Calling 的完整指南
Qwen3.7-Max 的 API 调用很多人已经熟悉,但如何用 Spring AI 的抽象层优雅地集成它,充分发挥其推理、函数调用和结构化输出能力?本文从 Spring AI 的项目初始化开始,覆盖 Chat/Streaming/Structured Output/Function Calling/Chat Memory 五大核心模式,并给出生产级的配置建议和踩坑实录。
Spring AI 集成 Qwen3.7-Max 实战:从 Chat 到 Function Calling 的完整指南
|
人工智能 自然语言处理 搜索推荐
携多项成果亮相云栖大会,探索大模型在云通信中的创新应用与全球实践
2025云栖大会云通信分论坛聚焦大模型与云通信融合,阿里云发布智能联络中心2.0与Chat App AI助理,携手伙伴推动通信智能化升级。
1158 1
|
机器学习/深度学习 人工智能 编解码
智谱AI发布新版VLM开源模型GLM-4.1V-9B-Thinking,引入思考范式,性能提升8倍
视觉语言大模型(VLM)已经成为智能系统的关键基石。
1905 0
|
6月前
|
人工智能 自然语言处理 前端开发
Playwright + 三大AI测试智能体实战:从用例生成到自动修复全记录(附可复现命令)
团队基于Playwright打造“测试智能体”三件套:用例生成器(RAG+自然语言)、执行自愈引擎(AI定位修复)、智能断言分析器(LLM比对结果)。三者协同使Web自动化测试编写与维护成本降60%,200个场景验证有效。
|
人工智能 Cloud Native 自然语言处理
拔俗AI智能体服务开发:你的7x24小时数字员工,让企业效率飙升的秘密武器
在“人效为王”时代,企业面临服务响应慢、成本高、协同难等痛点。阿里云AI智能体以自主决策、多模态交互、持续学习三大引擎,打造永不疲倦的“数字员工”,实现7×24小时高效服务,助力企业降本增效、驱动创新增长。(238字)
826 0