zoukankan      html  css  js  c++  java
  • ZOJ 1178 Booklet Printing

    原题链接

    题目大意:书本印刷都是用大开的纸张对折。比如一个册子一共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;
    }
  • 相关阅读:
    珍珠项链——容斥的应用
    协程库中 WaitGroup / CountDownLatch 实现
    简单C++线程池
    switch 比 if/else 效率更高?
    [LeetCode 264.] 丑数 II
    [LeetCode 229.] 求众数 II
    [NC41] 最长无重复子数组
    [NC105] 二分查找-II
    高楼扔鸡蛋
    C++ 编译期计算
  • 原文地址:https://www.cnblogs.com/naive/p/3568800.html
Copyright © 2011-2022 走看看