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. 让Linux下的打印机hp1020、hp p1008自动加载固件

    前言: 前段时间,处理公司打印机服务器Linux化工作.遇到问题如下:hp1020.hp1008断电后不能继续打印.而其他打印机在连接Linux打印机的情况下,断电后也能正常打印. 鉴于此情况,我搜寻 ...

  2. Tushare的安装

    TuShare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工到数据存储的过程,能够为金融分析人员提供快速.整洁.和多样的便于分析的数据. 考虑到python ...

  3. Linux Apache prefork和worker的原理详解

    prefork(多进程,每个进程产生子进程)和worker(多进程,每个进程生成多个线程)    prefork的工作原理是,控制进程在最初建立“StartServers”个子进程后,为了满足MinS ...

  4. swift 中String,Int 等类型使用注意,整理中

    swfit中的String和Int是 struct定义的,不同于NSString和NSNumber, 如果想在一个数组中同时包含String和Int,那么这个数组要声明为[Any] 而不是 [AnyO ...

  5. java文件上传路径缺少\的解决办法

    今天做一个文件上传,取路径,然后读取文件的时候,发现存储到MySQL的路径是这样的:

  6. July 16th, Week 29th Saturday, 2016

    A long road tests a horse's strength and a long task proves a man's heart. 路遥知马力,日久见人心. Do you have ...

  7. Win8 Cisco VPN Client 442错误解决办法

    进入注册表regedit,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CVirtA找到DisplayName, x86系统的将值" ...

  8. Popular Cows(codevs 2186)

    题意: 有N(N<=10000)头牛,每头牛都想成为most poluler的牛,给出M(M<=50000)个关系,如(1,2)代表1欢迎2,关系可以传递,但是不可以相互,即1欢迎2不代表 ...

  9. python基础——切片

    python基础——切片 取一个list或tuple的部分元素是非常常见的操作.比如,一个list如下: >>> L = ['Michael', 'Sarah', 'Tracy', ...

  10. ipconfig 无效

    刚刚配置了很多的环境变量后,在命令行下输入ipconfig后无效了 于是在环境变量PATH底下再次加入了;C:\WINDOWS\system32; 从新运行ipconfig,问题解决