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.

输入

 Each test case will be described with two integers N and P, on a line, where 4 ≤ N ≤ 1000 is a multiple of four that designates the length of the newspaper in terms of numbered pages, and 1 ≤ P ≤ N is a page that has been taken. The end of the input is designated by a line containing only the value 0.

输出

 For each case, output, in increasing order, the page numbers for the other three pages that will be missing.

示例输入

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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值