POJ 2162 Document Indexing(模拟)
Description
- If the last line on a page is the last line of the paragraph, then the following empty line is skipped, i.e. it is not placed on any page. Therefore, the page never starts with a blank line.
- If the last line on a page is the first line of a paragraph that contains more than one line (so called orphan line), then it is moved to the next page.
- If the last line on a page is the next-to-last line of a paragraph that contains more than three lines, then this line is moved to the next page (otherwise, the last line of the paragraph would be alone on the page -- so called widow line).
- If the last line on a page is the next-to-last line of a paragraph that contains exactly two or three lines, then the whole paragraph is moved to the next page (so we have neither orphan, nor widow lines).
After applying the correction rules the next page is formed, and so on until the whole document is paginated. A word is a continuous sequence of letters of the English alphabet. Case is not important. The index of the document contains each word from the document and the list of the pages it occurs at. The numbers of pages a word occurs at must be listed in the ascending order. Numbers must be separated by commas. If a word occurs on three or more consecutive pages, only the first and the last page numbers of this range must be listed, separated by a dash, for example "3-5,7-10,12,13,15".
Input
Output
题目大意:模拟一些段落的书页分配。除了一段只有一行的,不要让任何行单独在一页的最上面和最下面。
思路:模拟。注意如果像我这么做一段一段读的话要开大内存,之前开了1000行结果WA了无数次>_<。我的做法相当暴力啊o(╯□╰)o
代码(922MS):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cctype>
#include <map>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL; const int MAXN = ; map<string, int> mymap;
char s[][MAXN];
bool ans[][];
int n, page, row, cur, cnt; string to_str(char *&st) {
while(!isalpha(*st) && *st != ) ++st;
string ret;
while(isalpha(*st) && *st != ) {
if(islower(*st)) *st += 'A' - 'a';
ret += *st, ++st;
}
return ret;
} void to_map(char *s) {
string tmp;
while(true) {
tmp = to_str(s);
if(tmp == "") break;
int now;
if(mymap.find(tmp) != mymap.end()) now = mymap[tmp];
else mymap[tmp] = now = ++cnt;
//cout<<tmp<<endl;
ans[now][page] = true;
}
} void output() {
map<string, int>::iterator it;
for(it = mymap.begin(); it != mymap.end(); ++it) {
bool flag = false;
int now = it->second;
cout<<it->first;
for(int i = ; i <= page; ++i) {
if(!ans[now][i]) continue;
if(!flag) putchar(' '), flag = true;
else putchar(',');
printf("%d", i);
int j = i;
while(ans[now][j + ]) ++j;
if(j >= i + ) {
printf("-%d", j);
i = j;
}
}
puts("");
}
} int main() {
scanf("%d", &n); getchar();
page = , row = ;
cur = ; cnt = ;
bool flag = true;
mymap.clear();
while(flag && gets(s[])) {
cur = ;
while((flag = gets(s[cur])) && s[cur][] != ) ++cur;
if(cur == ) {
to_map(s[]);
++row;
if(++row > n) row = , ++page;
continue;
}
if(cur == ) {
if(row == n) row = , ++page;
to_map(s[]);
to_map(s[]);
row += ;
if(++row > n) row = , ++page;
continue;
}
if(cur == ) {
if(row + == n || row == n) row = , ++page;
to_map(s[]);
to_map(s[]);
to_map(s[]);
row += ;
if(++row > n) row = , ++page;
continue;
}
if(row == n) row = , ++page;//cur >= 4
for(int i = ; i < cur; ++i) {
if(row == n && i == cur - ) row = , ++page;
to_map(s[i]);
++row;
if(row > n) row = , ++page;
}
if(row == ) continue;
if(++row > n) row = , ++page;
}
output();
}
POJ 2162 Document Indexing(模拟)的更多相关文章
- Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟
B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...
- HDU 2494/POJ 3930 Elevator(模拟)(2008 Asia Regional Beijing)
Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartmen ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2014 Flow Layout 模拟
http://poj.org/problem?id=2014 嘻嘻2014要到啦,于是去做Prob.ID 为2014的题~~~~祝大家新年快乐~~ 题目大意: 给你一个最大宽度的矩形,要求把小矩形排放 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- poj 3253 Fence Repair(模拟huffman树 + 优先队列)
题意:如果要切断一个长度为a的木条需要花费代价a, 问要切出要求的n个木条所需的最小代价. 思路:模拟huffman树,每次选取最小的两个数加入结果,再将这两个数的和加入队列. 注意priority_ ...
- Code POJ - 1780(栈模拟dfs)
题意: 就是数位哈密顿回路 解析: 是就算了...尼玛还不能直接用dfs,得手动开栈模拟dfs emm...看了老大半天才看的一知半解 #include <iostream> #inclu ...
随机推荐
- Git相关内容
先聊一点关于gitlab的内容和github的内容 Gitlab和GitHub,都是我们可以存放代码库的地方.不过Gitlab可以免费的存储私人代码,GitHub需要花钱才能够存储私人代码库,不过我想 ...
- sql*plus
[sql*plus创建txt文档编辑sql语句] (1)创建一个txt,命名doc SQL> ed doc; /*ed 文件名*/ (2)在doc.txt文件编辑sql语 ...
- 关于truthy 和 falsy
一,强制类型转换 JavaScript 在需要用到布尔类型值的上下文中使用强制类型转换(Type Conversion )将值转换为布尔值,比如:在条件语句或者循环语句中 一,truthy 在java ...
- 洛谷P3871 [TJOI2010]中位数(splay)
题目描述 给定一个由N个元素组成的整数序列,现在有两种操作: 1 add a 在该序列的最后添加一个整数a,组成长度为N + 1的整数序列 2 mid 输出当前序列的中位数 中位数是指将一个序列按照从 ...
- 前端之Vue.js库的使用
vue.js简介 Vue.js读音 /vjuː/, 类似于 view Vue.js是前端三大新框架:Angular.js.React.js.Vue.js之一,Vue.js目前的使用和关注程度在三大框架 ...
- Linux 学习第二天
一.常用命令的使用 1.echo echo https://www.cnblogs.com/rise-home/ 输出字符串 2.ps -aux(显示进程信息) ps 进程状态共有5种 A.STAT ...
- loushang框架的开发中关于BSP的使用,将写好的功能模块部署到主页界面结构上
前言: 当我们已经开发好相应的模块或者功能的时候,需要将这个功能部署在index主页上作为可点击直接使用的模块,而不是每次需要去浏览对应的url地址. 这时候就需要运用到L5的BSP. 作为刚刚入门l ...
- 图片懒加载 jquery.lazyload
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 数据解压及if else的应用
def sum(items): head, *tails = items return head + sum(tails) if tails else head # 最后一句有点像三目运算符,如果ta ...
- 用友二次开发之科脉TOT3凭证接口
按客户的要求,根据科脉导出的数据,开发一个工具,将凭证导入T3 这个科目导出的凭证格式. 选择账套登陆,你没看错,这个是我开发的登陆界面. 选择接口文件. 软件自动进数据分类,你可以看到数据了.但只是 ...