Booklet Printing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 503    Accepted Submission(s): 269

Problem Description
When printing out a document, normally the first page is printed first, then the second, then the third, and so on until the end. However, when creating a fold-over booklet, the order of printing must be altered. A fold-over booklet has four pages per sheet, with two on the front and two on the back. When you stack all the sheets in order, then fold the booklet in half, the pages appear in the correct order as in a regular book.
For example, a 4-page booklet would print on 1 sheet of paper: the front will contain page 4 then page 1, and the back will contain page 2 then page 3.

Front Back
------------- -------------
| | | | | |
| 4 | 1 | | 2 | 3 |
| | | | | |
------------- -------------

Your task is to write a program that takes as input the number of pages to be printed, then generates the printing order.

Input
The input contains one or more test cases, followed by a line containing the number 0 that indicates the end of the file.

Each test case consists of a positive integer n on a line by itself, where n is the number of pages to be printed; n will not exceed 100.

Output
For each test case, output a report indicating which pages should be printed on each sheet, exactly as shown in the example. If the desired number of pages does not completely fill up a sheet, then print the word Blank in place of a number. If the front or back of a sheet is entirely blank, do not generate output for that side of the sheet.

Output must be in ascending order by sheet, front first, then back.

Sample Input
1
14
4
0

Sample Output
Printing order for 1 pages:
Sheet 1, front: Blank, 1
Printing order for 14 pages:
Sheet 1, front: Blank, 1
Sheet 1, back : 2, Blank
Sheet 2, front: 14, 3
Sheet 2, back : 4, 13
Sheet 3, front: 12, 5
Sheet 3, back : 6, 11
Sheet 4, front: 10, 7
Sheet 4, back : 8, 9
Printing order for 4 pages:
Sheet 1, front: 4, 1
Sheet 1, back : 2, 3

Source
Mid-Central USA 1998

Recommend
Eddy

#include<stdio.h>
int s[500][4];
int main()
{
int P,i;
while (scanf("%d",&P)!=EOF)
{
if (P==0) return 0;
int N=(P-1)/4+1;
int M=4*N;
int l=1,r=M;
for (i=1;i<=N;i++)
{
s[i][0]=r--;
s[i][1]=l++;
s[i][2]=l++;
s[i][3]=r--;
}
printf("Printing order for %d pages:\n",P);
for (i=1;i<=N;i++)
{
if (!(s[i][0]>P && s[i][1]>P))
{
printf("Sheet %d, front:",i);
if (s[i][0]>P) printf(" Blank, ");
else printf(" %d, ",s[i][0]);
if (s[i][1]>P) printf("Blank\n");
else printf("%d\n",s[i][1]);
}
if (!(s[i][2]>P && s[i][3]>P))
{
printf("Sheet %d, back :",i);
if (s[i][2]>P) printf(" Blank, ");
else printf(" %d, ",s[i][2]);
if (s[i][3]>P) printf("Blank\n");
else printf("%d\n",s[i][3]);
}
}
}
return 0;
}

Booklet Printing[HDU1117]的更多相关文章

  1. ZOJ 1178 Booklet Printing

    原题链接 题目大意:书本印刷都是用大开的纸张对折.比如一个册子一共4页,为了方便装订,外侧印刷1.4页,内侧印刷2.3页,这样对折之后就可以按照正常阅读习惯翻页了.此题目的就是给出书的总页数,要求计算 ...

  2. UVa 637 - Booklet Printing

    题目:模拟输出n页书的装订打印状态. 分析:模拟.页数为(n+3)/ 4,仅仅有n不超过半篇时会输出半篇. 说明:好多曾经做过的题目(⊙_⊙). #include <cstdlib> #i ...

  3. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  6. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  7. 转载 ACM训练计划

    leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...

  8. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  9. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

随机推荐

  1. 3ds Max光照纹理导入Unity的教程.

    原地址:http://www.cocoachina.com/gamedev/gameengine/2010/0531/1581.html 相信这个3ds Max光照纹理导入Unity的教程对游戏设计师 ...

  2. GLUT教程 - 安装

    转载:http://www.cnblogs.com/live41/p/3368830.html glut库 - 下载频道 - CSDN.NEThttp://download.csdn.net/down ...

  3. HTML快速入门2

    三.版面风格控制 1. 字体控制 A. 字体大小 用 <font Size=#> 和 </font> 表示,#为字号: 1 - 7 ,缺省为 3 ,可用 <basefon ...

  4. Linux EOF使用

    # cat << EOF > fileB   用法 例: vi ceshi.sh cat<<eof>file1 aaaa bbbb cccc dddd eof 操作 ...

  5. CF#310 d2

    A:|c[1]-c[0]| B:A+-(oc)A[0]==0..n-1 C: #include <cstdio> int n,m,i,j,k,p; int ll,ca,cb,cc; int ...

  6. 【转】js onclick用法:跳转到指定URL

    使用onclick跳转到其他页面/跳转到指定url   ☆如果是本页显示可以直接用location,方法如下: ①onclick="javascript:window.location.hr ...

  7. 如何提高cocos2d-x-spine骨骼动画加载速度

    下面分2点来说: 1. 时间消耗点:io和现场解析 解决方案:加载过的骨骼动画就不要每次重新加载,不要每次都去加载json文件和atlas,我推荐使用 static CCSkeletonAnimati ...

  8. canvas API ,通俗的canvas基础知识(三)

    全文说到了三角形,圆形等相关图形的画法,不熟悉的同学可以出门右转,先看看前文,接下来继续我们的图形——曲线. 学过数学,或者是比较了解js 的同学都知道贝塞尔曲线,当然,在数学里面,这是一门高深的学问 ...

  9. Java for LeetCode 035 Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  10. 【USACO】第一章总结

    做了大半个月,终于把第一章做完了 有的题遇到了不小的坎儿,看着网上一群高中生都做得那么好,心理还是有些小郁闷的.不禁感慨我过去的四年真是虚度啊.总结一下第一章学习到的知识吧. ①闰年判断 int is ...