ZOJ 1178 Booklet Printing (book Folding problem)

Source: Internet
Author: User

Original title: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=178

The book is printed in half with the big open paper. For example, a booklet of 4 pages, in order to facilitate binding, printed on the outside 1, 4 pages, the inside printing 2, 3 pages, so that after folding can be in accordance with normal reading habits page.

The sensory algorithm is more handsome than the online family's algorithm
#include <iostream>
using namespace std;
int main ()
{
	int n,sheet,four_n;
	int front[2],back[2];
	while (cin>>n&&n!=0)
	{
		if (n%4) four_n=n+4-n%4;
		else four_n=n;
		SHEET=FOUR_N/4;
		Front[0]=four_n;
		Front[1]=1;
		back[0]=2;
		back[1]=four_n-1;
		cout<< "Printing order for" <<n<< "pages:" <<endl;
		for (int i=0;i<sheet;i++)
		{
			if (n==1)
			{
				cout<< "Sheet 1, Front:blank, 1" <<endl;
				break;
			}
			Front[0]=four_n-2*i;
			Front[1]=1+2*i;
			Back[0]=2+2*i;
			Back[1]=four_n-1-2*i;
			cout<< "Sheet" <<i+1<< ", Front:";
			if (front[0]>n) cout<< "Blank";
			else cout<<front[0];
			cout<< "," <<front[1]<<endl;
			cout<< "Sheet" <<i+1<< ", Back:";
			cout<<back[0]<< ",";					
			if (back[1]>n) cout<< "Blank" <<endl;
			Else cout<<back[1]<<endl;
		}}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.