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. 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 题意:n个数字1-n出现次数唯一。 b1 = a1 , bi = |ai - b(i-1)| ,ai任意。求最大和最小的bn 1 2 3 4 可以抵消为0. 所以从后往前没4项化为0 ,直接%4后 转化为判断1 - 3的情况。
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; void solve(int n)
{
int minn ,maxn;
/**min**/
int k = n%;
if(k== || k==) minn = ;
else minn = ; /**max**/
int m = n-;
k = m%;
if(k== || k==) maxn = n;
else maxn = n-; printf("%d %d\n",minn,maxn);
for(int i=n;i>=;i--)
{
if(i==n) printf("%d",i);
else printf(" %d",i);
}
printf("\n"); for(int i=n-;i>=;i--)
{
printf("%d ",i);
}
printf("%d\n",n); }
int main()
{
int n;
while(scanf("%d",&n)>)
{
if(n==)
{
printf("1 1\n");
printf("1\n");
printf("1\n");
continue;
}
if(n==)
{
printf("1 1\n");
printf("1 2\n");
printf("2 1\n");
continue;
}
solve(n);
}
return ;
}
zoj Abs Problem的更多相关文章
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds Me ...
- ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
- zoj 3777 Problem Arrangement(壮压+背包)
Problem Arrangement Time Limit: 2 Seconds Memory Limit: 65536 KB The 11th Zhejiang Provincial C ...
- zoj 3777 Problem Arrangement
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序 ...
- ZOJ 3959 Problem Preparation 【水】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 AC代码 #include <cstdio> ...
- ZOJ 3329 Problem Set (期望dp)
One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...
- 浙大月赛ZOJ Monthly, August 2014
Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...
- ZOJ Monthly, August 2014
A Abs Problem http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5330 找规律题,构造出解.copyright@ts ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
随机推荐
- 数据库性能之--ibatis cache应用
(1)利用cache是提升性能的一个很重要方式!cacheModel节点定义了本映射文件中使用的Cache机制:<cacheModel id="userCache" type ...
- C++之路进阶——codevs2313(星际竞速)
2313 星际竞速 2010年省队选拔赛山东 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 10 年一度的银河系 ...
- CORBA的简单介绍及HelloWorld(zhuan)
http://blog.csdn.net/drykilllogic/article/details/25971915
- demo14
/Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/tabl ...
- 弱类型变量原理探究(转载 http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php)
N首页> 云计算 [问底]王帅:深入PHP内核(一)——弱类型变量原理探究 发表于2014-09-19 09:00| 13055次阅读| 来源CSDN| 36 条评论| 作者王帅 问底PHP王帅 ...
- switch结构2016/03/08
Switch 03/08 一.结构 switch(){ case *: ;break;……default: ;brek;} 练习:输入一个日期,判断这一年第几天? Console.Write(&q ...
- TortoiseSVN提交文件的时候卡死
提交文件的时候卡死,查找很久,才发现原来是IP被修改了,郁闷
- DirectX 绘制
先上图.后面会描写 ,细节
- selenium+phantomJS学习使用记录
背景知识: phantomjs是一个基于webkit的没有界面的浏览器,所以运行起来比完整的浏览器要高效. selenium是一个测试web应用的工具,目前是2.42.1版本,和1版的区别在于2.0+ ...
- xxxx
http://www.cnblogs.com/zhuojun/p/5747999.html