HDU 6107 Typesetting (倍增)
Typesetting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 144 Accepted Submission(s): 72
The page width is fixed to W characters. In order to make the article look more beautiful, Yellowstar has made some rules:
1. The fixed width of the picture is pw. The distance from the left side of the page to the left side of the photo fixed to dw, in other words, the left margin is dw, and the right margin is W - pw - dw.
2. The photo and words can't overlap, but can exist in same line.
3. The relative order of words cannot be changed.
4. Individual words need to be placed in a line.
5. If two words are placed in a continuous position on the same line, then there is a space between them.
6. Minimize the number of rows occupied by the article according to the location and height of the image.
However, Yellowstar has not yet determined the location of the picture and the height of the picture, he would like to try Q different locations and different heights to get the best look. Yellowstar tries too many times, he wants to quickly know the number of rows each time, so he asked for your help. It should be noted that when a row contains characters or pictures, the line was considered to be occupied.
Each case begins with one line with four integers N, W, pw, dw : the number of words, page width, picture width and left margin.
The next line contains N integers ai, indicates i-th word consists of ai characters.
The third line contains one integer Q.
Then Q lines follow, each line contains the values of xi and hi, indicates the starting line and the image height of the image.
Limits
T≤10
1≤N,W,Q≤105
1≤pw,ai≤W
0≤dw≤W−pw
2 7 4 3
1 3
3
1 2
2 2
5 2
3 8 2 3
1 1 3
1
1 1
3
3
1
- #include <bits/stdc++.h>
- #define inf 0x3f3f3f3f
- #define met(a,b) memset(a,b,sizeof a)
- #define pb push_back
- #define mp make_pair
- #define rep(i,l,r) for(int i=(l);i<=(r);++i)
- #define inf 0x3f3f3f3f
- using namespace std;
- typedef long long ll;
- const int N = 1e5+;;
- const int M = ;
- const int mod = 1e9+;
- const int mo=;
- const double pi= acos(-1.0);
- typedef pair<int,int>pii;
- int n,w,q,pw,dw;
- int a[N],lto[N],rto[N];
- int h[N],s[N][M],t[N][M];
- void solve(int len,int to[]){
- for(int i=,j=,x=-;i<=n;i++){
- while(x+a[j]+<=len)x+=a[j++]+;
- to[i]=j;x-=a[i]+;
- }
- }
- int main() {
- int T;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d%d%d",&n,&w,&pw,&dw);
- rep(i,,n-)scanf("%d",&a[i]);
- a[n]=w+;
- solve(w,lto);
- rep(i,,n)s[i][]=lto[i];
- rep(j,,M-)rep(i,,n)s[i][j]=s[s[i][j-]][j-];
- h[n]=;
- for(int i=n-;i>=;i--)h[i]=h[lto[i]]+;
- solve(dw,lto);solve(w-dw-pw,rto);
- rep(i,,n)t[i][]=rto[lto[i]];
- rep(j,,M-)rep(i,,n)t[i][j]=t[t[i][j-]][j-];
- scanf("%d",&q);
- while(q--){
- int x,hh,res=;
- scanf("%d%d",&x,&hh);
- int ans=;
- ans+=min(--x,h[]);
- rep(j,,M-)if(x>>j & )res=s[res][j];
- rep(j,,M-)if(hh>>j & )res=t[res][j];
- ans+=hh+h[res];
- printf("%d\n",ans);
- }
- }
- return ;
- }
HDU 6107 Typesetting (倍增)的更多相关文章
- HDU 6107 - Typesetting | 2017 Multi-University Training Contest 6
比赛的时候一直念叨链表怎么加速,比完赛吃饭路上突然想到倍增- - /* HDU 6107 - Typesetting [ 尺取法, 倍增 ] | 2017 Multi-University Train ...
- HDU 6107 Typesetting
Problem Description Yellowstar is writing an article that contains N words and 1 picture, and the i- ...
- Typesetting HDU - 6107
Yellowstar is writing an article that contains N words and 1 picture, and the i-th word contains aia ...
- hdu 5726 GCD 倍增+ 二分
题目链接 给n个数, 定义一个运算f[l,r] = gcd(al, al+1,....ar). 然后给你m个询问, 每次询问给出l, r. 求出f[l, r]的值以及有多少对l', r' 使得f[l, ...
- HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 2586 How far away ?倍增LCA
hdu 2586 How far away ?倍增LCA 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2586 思路: 针对询问次数多的时候,采取倍增 ...
- HDU - 6394 Tree(树分块+倍增)
http://acm.hdu.edu.cn/showproblem.php?pid=6394 题意 给出一棵树,然后每个节点有一个权值,代表这个点可以往上面跳多远,问最少需要多少次可以跳出这颗树 分析 ...
- hdu 6394 Tree (2018 Multi-University Training Contest 7 1009) (树分块+倍增)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6394 思路:用dfs序处理下树,在用分块,我们只需要维护当前这个点要跳出这个块需要的步数和他跳出这个块去 ...
随机推荐
- btrace 常见问题
执行btrace命令报错:Unable to open socket file: target process not responding or HotSpot VM not loaded ---- ...
- 20151024_001_C#基础知识(静态与非静态的区别,值类型和引用类型,堆和栈的区别,字符串的不可变性,命名空间)
1:我们把这些具有相同属性和相同方法的对象进行进一步的封装,抽象出来类这个概念. 类就是个模子,确定了对象应该具有的属性和方法. 对象是根据类创建出来的. 2:类:语法 [public] class ...
- bzoj 1030 ac自动机
比较容易看出来先建立ac自动机,然后在自动机上做DP,设w[0..1][i][j]为当前不包括/包括字典中的字符串,当前在自动机中走到第i个节点,完成的文本的长度为j的方案数,那么比较容易的转移w[i ...
- NodeJS中Buffer模块详解
一,开篇分析 所谓缓冲区Buffer,就是 "临时存贮区" 的意思,是暂时存放输入输出数据的一段内存. JS语言自身只有字符串数据类型,没有二进制数据类型,因此NodeJS提供了一 ...
- 448D - Codeforces
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes Bizon the C ...
- (二十)ubuntu的recovery mode解决用户一些实际问题
遇到的问题如下: 1.在当前用户下使用sudo来直接修改password等几个文件,一旦修改了passwd,用户名发生了变化,其他的用户组.密码等却没有对应的配置,就再进不了该用户了. 2.忘记用户密 ...
- The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collectio
The content of element type "resultMap" must match "(constructor?,id*,result*,associa ...
- 使用Storm实现实时大数据分析(转)
原文链接:http://blog.csdn.net/hguisu/article/details/8454368 简单和明了,Storm让大数据分析变得轻松加愉快. 当今世界,公司的日常运营经常会生成 ...
- 利用h5,chart.js监测手机三轴加速度,用以研究计步算法等
用window.DeviceMotionEvent来判断手机浏览器是否支持访问硬件资源,window.addEventListener('devicemotion',deviceMotionHandl ...
- MySQL数据库分表分区(一)(转)
面对当今大数据存储,设想当mysql中一个表的总记录超过1000W,会出现性能的大幅度下降吗? 答案是肯定的,一个表的总记录超过1000W,在操作系统层面检索也是效率非常低的 解决方案: 目前针对 ...