首页 > 其他 > 详细

ZOJ 1178 Booklet Printing

时间:2014-02-27 08:48:11      阅读:353      评论:0      收藏:0      [点我收藏+]

原题链接

题目大意:书本印刷都是用大开的纸张对折。比如一个册子一共4页,为了方便装订,外侧印刷1、4页,内侧印刷2、3页,这样对折之后就可以按照正常阅读习惯翻页了。此题目的就是给出书的总页数,要求计算每张纸正反面应该印刷什么内容。

解法:不难,但是略微繁琐。先计算需要的纸张数量,然后分别计算正反面的内容。如果书本页码很少,第一张和第二张纸比较特殊,需要单独列出来,其他内页按照公式推算。

 

参考代码:

#include<iostream>
using namespace std;

int main(){
	int n,i,j,k,sheet,r;

	while(cin>>n&&n!=0){
		sheet=(n+3)/4;
		r=n%4;
		cout<<"Printing order for "<<n<<" pages:"<<endl;
		i=1;
		while(i<=sheet){
			cout<<"Sheet "<<i<<", front: ";
			if(i==1){
				if(n==4)cout<<"4, 1"<<endl;
				else if(r!=0)cout<<"Blank, 1"<<endl;
				else cout<<n<<", 1"<<endl;
			}
			else{
				if(n<4*(sheet-i)+6)
					cout<<"Blank, "<<i*2-1<<endl;
				else
					cout<<sheet*4-i*2+2<<", "<<i*2-1<<endl;
			}
				

			if(n==1);
			else{
				cout<<"Sheet "<<i<<", back : ";
				if(i==1){
					if(r==1||r==2)cout<<"2, Blank"<<endl;
					else if(r==3)cout<<"2, "<<n<<endl;
					else cout<<"2, "<<n-1<<endl;
				}
				else if(i*4-3>n)
					cout<<i*2<<", Blank"<<endl;
				else
					cout<<i*2<<", "<<sheet*4+1-i*2<<endl;
			}
			i++;
		}
	}

	return 0;
}

ZOJ 1178 Booklet Printing,布布扣,bubuko.com

ZOJ 1178 Booklet Printing

原文:http://www.cnblogs.com/naive/p/3568800.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!