码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 3798 Abs Problem

时间:2014-09-11 22:28:12      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   ar   for   2014   sp   on   


找规律....


Abs Problem

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

Alice and Bob is playing a game, and this time the game is all about the absolute value!

Alice has N different positive integers, and each number is not greater than N. Bob has a lot of blank paper, and he is responsible for the calculation things. The rule of game is pretty simple. First, Alice chooses a number a1 from the N integers, and Bob will write it down on the first paper, that‘s b1. Then in the following kth rounds, Alice will choose a number ak (2 ≤ k ≤ N), then Bob will write the number bk=|ak-bk-1| on the kth paper. |x| means the absolute value of x.

Now Alice and Bob want to kown, what is the maximum and minimum value of bN. And you should tell them how to achieve that!

Input

The input consists of multiple test cases;

For each test case, the first line consists one integer N, the number of integers Alice have. (1 ≤ N ≤ 50000)

Output

For each test case, firstly print one line containing two numbers, the first one is the minimum value, and the second is the maximum value.

Then print one line containing N numbers, the order of integers that Alice should choose to achieve the minimum value. Then print one line containing N numbers, the order of integers that Alice should choose to achieve the maximum value.

Attention: Alice won‘t choose a integer more than twice.

Sample Input

2

Sample Output

1 1
1 2
2 1

Author: ZHANG, Ruixiang
Source: ZOJ Monthly, August 2014



#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n;

int main()
{
	while(scanf("%d",&n)!=EOF)	
	{
		if(n==1)
		{
			puts("1 1");
			puts("1 1");
			puts("1 1");
			continue;
		}
		if(n==2)
		{
			puts("1 1");
			puts("1 2");
			puts("2 1");
			continue;
		}
		int b1=n,b2=n-1;
		for(int i=2;i<=n;i++)
		{
			b1=abs(b1-(n-i+1));
		}
		for(int i=2;i<n;i++)
		{
			b2=abs(b2-(n-i));
		}
		b2=abs(b2-n);
		printf("%d %d\n",b1,b2);
		printf("%d",n);
		for(int i=2;i<=n;i++)
		{
			printf(" %d",n-i+1);
		}
		putchar(10);
		printf("%d",n-1);
		for(int i=2;i<n;i++)
		{
			printf(" %d",n-i);
		}
		printf(" %d",n);
		putchar(10);	
	}
	return 0;
}





ZOJ 3798 Abs Problem

标签:style   color   io   os   ar   for   2014   sp   on   

原文地址:http://blog.csdn.net/ck_boss/article/details/39211687

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!