Missing Pages |
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB |
Total submit users: 78, Accepted users: 78 |
Problem 12941 : No special judgement |
Problem description |
Long ago, there were periodicals called newspapers, and these newspapers were printed on 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 When one numbered page is taken from the newspaper, the question is what other pages disappear. |
Input |
Input: Each test case will be described with two integers |
Output |
Output: For each case, output, in increasing order, the page numbers for the other three pages that will be missing. |
Sample Input |
12 2 12 9 8 3 0 |
Sample Output |
1 11 12 3 4 10 4 5 6 |
Problem Source |
ACM Mid-Central Programming Competition 2013
#include<stdio.h> int main() { int N,p,m,tp,p1,p2,p3; while(scanf("%d",&N)>0&&N) { scanf("%d",&p); m=N/4; if(2*m>=p) { tp=(p+1)/2; int k1=1,k2=N; for(int i=2;i<=tp;i++) k1+=2,k2-=2; if(k1!=p)p1=k1;else p1=k1+1; p2=k2-1; p3=k2; } else { tp=(p-m*2+1)/2; int k1=m*2,k2=m*2+1; for(int i=2;i<=tp;i++) k1-=2,k2+=2; if(k2!=p)p3=k2;else p3=k2+1; p1=k1-1;p2=k1; } printf("%d %d %d\n",p1,p2,p3); } } |