ZOJ 3798 Abs Problem
2014-09-11 21:23
330 查看
找规律....
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!
For each test case, the first line consists one integer N, the number of integers Alice have. (1 ≤ N ≤ 50000)
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.
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;
}
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 22 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
- zoj 3798 Abs Problem(数学:推理+滚动数组)
- ZOJ 3798 Abs Problem(规律题)
- zoj 3798 Abs Problem( ZOJ Monthly, August 2014 - A)
- 组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)
- ZOJ 3798 Abs Problem
- zoj3798 Abs Problem 水题
- ZOJ 3798 Abs Problem
- ZOJ 3798 Abs Problem(找规律)
- ZOJ 3798--解题报告
- ZOJ 3789 Abs Problem
- zoj 3623
- ZOJ-1501
- zoj 3430 Detect the Virus(ac自动机)
- zoj 2136 Longest Ordered Subsequence 最长上升子序列 新思路
- poj 1077 zoj 1217 hdu 1043 八数码
- ZOJ-1717
- ZOJ-1243(parse URL)
- ZOJ 1156 - Unscrambling Images
- Farm Irrigation_zoj 2412