Missing Pages

2024-09-04 09:08
文章标签 pages missing

本文主要是介绍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;
}




这篇关于Missing Pages的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1135586

相关文章

code: 400, msg: Required request body is missing 错误解决

引起这个错误的原因是,请求参数按照get方式给。 应该给json字符串才对 补充: 1. @RequestBody String resource 加@RequestBody必须给json字符串,否则会报错400,记如标题错误。 不加这个的进行请求的话,其实post和get就没有什么区别了。 2. List<String> indexCodes=(List<String>)json.

Vue3+Vite+Echarts 出现Missing semicolon错误

使用的echarts代码如下:   import * as echarts from 'echarts';type EChartsOption = echarts.EChartsOption;var chartDom = document.getElementById('main')!;var myChart = echarts.init(chartDom);var option: ECha

LeetCode - 41. First Missing Positive

41. First Missing Positive  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一组整数,找出第一个空缺的正整数. 要求:时间O(n),空间O(n). analyse: 这题时间O(n)想了

经验笔记:JSP(JavaServer Pages)

JSP(JavaServer Pages)经验笔记 JSP(JavaServer Pages)是一种用于创建动态网页的技术,它允许在HTML页面中嵌入Java代码,从而实现动态内容的生成。JSP与Servlet一样,都是Java EE平台的一部分,用于开发Web应用程序。以下是关于JSP的一些经验和技巧,旨在帮助开发者更好地理解和使用这项技术。 1. 基础概念 JSP页面:一个JSP页面是一

Missing Purpose String in Info.plist File:构建版本按钮不显示.

最近做了一个新项目,打包发布的时候,等了好长时间,构建版本的按钮就是不出现,后来登录开发者账号的邮箱,才看见苹果发过来的邮件: Dear Developer, We identified one or more issues with a recent delivery for your app, "蓝汇智能AI". Please correct the following issues, t

keras missing label unlabeled 未标注类 如何训练 如何自定义损失函数 去除未标注类 缺少标签

我从这里找到的答案: def ignore_unknown_xentropy(ytrue, ypred):return (1-ytrue[:, :, :, 0])*categorical_crossentropy(ytrue, ypred) 然后下面是我的代码: 我感觉看到这个帖子的应该都看得懂吧(其实就是懒得解释了,请看注释)  from __future__ import print_

java.lang.IllegalStateException: aidl is missing

从windows电脑上面切换到Mac上面经历了一些列的问题呀。。。关键问题还是sdk,gradle,版本不全的问题,缺这少那的。奈何下载又不给力,头大,最后终于是好了。 先来说下这个问题吧:java.lang.IllegalStateException: aidl is missing,这个问题是因为我的 compileSdkVersion buildToolsVersion targetSdk

【Maven】dependencies.dependency.version is missing 问题

子模块为web项目,在写依赖时,没有写version的信息。在父pom中使用dependencyManagement中写明了version 于是pom报错:dependencies.dependency.version is missing 原因及解决办法: 1、 maven 对于父项目定义的dependencyManagement 中的 非 jar 类型的 type节点不会继承,也就是说子

GEE错误:Property ‘species_ID‘ of feature ‘0_0‘ is missing.

目录 错误 数据属性 现有的属性信息 原始代码  错误解析 已经写过的博客 错误 Image (Error) Property 'species_ID' of feature '0_0' is missing. 数据属性 现有的属性信息   原始代码 var sp = ee.FeatureCollection("projects/ee-aptiawo

装过mr又卸载了,max报错 mrmateralattribs missing dlls

rendering>scene converter 打开对话框后,current preset 中选择 remove invalid legacy elements,取消open scene converter。。勾选 automaticaly remove missing。再点 convet scene