ZOJ 3798 Abs Problem

A - Abs Problem
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu

Description

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
解析

就是一道找规律的数学题,死活找不出来,数学题就是弱点啊!

先考虑找最小值,因为最大值就是 b[N] = N - b[N-1] 其中 b[N-1] 是N-1的最小值。(这是一个很重要的思想,在很多题中都有应用)

发现有规律:

ann-1n-2n-3
bn1n-30
按照这样的排列方式每4个刚好可以抵消掉,因此只需要考虑N%4(或者是(N-1)%4)剩下的部分

N%4剩下的数列min
0没有0
111
22 11
33 2 10
我也不知道如何证明n%4==1或2时 min==1 为最优答案

#include<cstdio>
using namespace std;

int N;
int min,max;

int main()
{
	while(scanf("%d",&N)==1)
	{
		if(N==1) {printf("1 1\n1\n1\n");continue;}
		if(N==2) {printf("1 1\n1 2\n2 1\n");continue;}
		if(N%4==0 || N%4==3) min=0; else min=1;
		if((N-1)%4==0 || (N-1)%4==3) max=N; else max=N-1;
		printf("%d %d\n",min,max);

		for(int i=N;i>1;i--) printf("%d ",i); printf("1\n");
		for(int i=N-1;i>=1;i--) printf("%d ",i); printf("%d\n",N);
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值