ZOJ 3798 Abs Problem

找规律....

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;
}
时间: 2024-12-09 19:43:31

ZOJ 3798 Abs Problem的相关文章

ZOJ 3798 Abs Problem(规律题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3798 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

组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)

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.

ZOJ 3789 Abs Problem

有时候像这种题,没有明显的思路,感觉像规律题.那么先暴力打表,再找规律就很快了. 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3798 先上我的暴力打表,这种肯定是TLE的,只用它发现规律就好了. #include<cstdio> #include<cstring> #include<algorithm> #define INF 0x3f3f3f3f #define N 100 us

zoj Abs Problem

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.

ZOJ3798 Abs Problem

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3798 学会了对于序列用next_permutation暴力打表 可以先打表找规律 #include<cstdio> #include<algorithm> #define INF 0x3f3f3f3f// #define N 100 using namespace std; int seq[N];//保存当前序列 int mi[N], ma[N];//

zoj 3621 Factorial Problem in Base K 数论 s!后的0个数

Factorial Problem in Base K Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3621 Description How many zeros are there in the end of s! if both s and s! are written in base k which is not nece

zoj3798Abs Problem(思维)

题目链接: huangjing 题目意思: 用1~n中的数字进行组合,得到后面减前面的一项的最大最小值... 思路: 多试两个就会发现从n到1的排列得到的是最小值,同理从n-1到1得到的也是最小值,那么用n-这个最小值,那么必定得到的是最大值... 题目: Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and thi

浙大月赛ZOJ Monthly, August 2014

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

差分约束小结

ZOJ 2770 Burn the Linked Camp /* ZOJ 2770 Burn the Linked Camp 差分约束 */ #include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; const int MAXN = 1009; struct Edge { int v, ne, c; } G[MAXN*MAXN]