本文主要是介绍Missing Pages,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目描述
Long ago, there were periodicals called newspapers, and these newspapers were printed on paper, and people used to read them, and perhaps even share them. One unfortunate thing about this form of media is that every so often, someone would like an article so much, they would take it with them, leaving the rest of the newspaper behind for others to enjoy. Unfortunately, because of the way that paper was folded, not only would the page with that article be gone, so would the page on the reverse side and also two other pages that were physically on the same sheet of folded paper.
For this problem we assume the classic approach is used for folding paper to make a booklet that has a number of pages that is a multiple of four. As an example, a newspaper with 12 pages would be made of three sheets of paper (see figure below). One sheet would have pages 1 and 12 printed on one side, and pages 2 and 11 printed on the other. Another piece of paper would have pages 3 and 10 printed on one side and 4 and 9 printed on the other. The third sheet would have pages 5, 6, 7, and 8.
When one numbered page is taken from the newspaper, the question is what other pages disappear.
输入
输出
示例输入
12 2 12 9 8 3 0
示例输出
1 11 12 3 4 10 4 5 6
提示
来源
解题报告
开始比赛的时候没去,现在闲着就做做题,英语略过,大概意思就是一张纸有四面,页码就是报纸的形式,看图就会明白,输入页码总数和一个页码,用来输出那个页码所在的纸的其他三个页码数。刚开始没有思路,结果想想用数组来完成,用一个二维数组来表示一份报纸的页码,比如有12页,也就是三页纸,每张纸的页码分别是(1,2,11,12);(3,4,9,10);(5,6,7,8),只要二维数组表示出来就没问题了。结果兴高采烈的提交了,给Presentation Error了,问题很明显,应该是多了空格,输出代码如下
for(i=0;i<4;i++)if(x[l][i]!=b){printf("%d",x[l][i]);if(i!=3)printf(" ");} //前面代码略去,x[l][i]表示以储存的报纸页码顺序
修改了空格输出两次,都是PE,就换一种方式,用int数组来储存要输出的页码,就解决问题了
#include<stdio.h> int main () {int i,k,l,o,a,b,x[250][4],p,q[3];while(scanf("%d",&a)!=EOF){if(a==0)break;scanf("%d",&b);l=1;o=a;p=0;for(i=0;i<a/4;i++)for(k=0;k<2;k++){x[i][k]=l++;}for(i=i-1;i>-1;i--)for(k=2;k<4;k++)x[i][k]=l++;l=a+1-b;for(i=0;i<a/4;i++)for(k=0;k<4;k++)if(l==x[i][k]){l=i;break;}for(i=0;i<4;i++)if(x[l][i]!=b){q[p++]=x[l][i];}printf("%d %d %d\n",q[0],q[1],q[2]);}return 0; }
这篇关于Missing Pages的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!