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 ...
随机推荐
- 省市联动初探AJAX操作数据
主要学习代码: List.html <script type="text/javascript"> function GetXhr() { return new XML ...
- csu oj 1339: 最后一滴血
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1339 1339: 最后一滴血 Time Limit: 1 Sec Memory Limit: 1 ...
- JSon_零基础_004_将Set集合对象转换为JSon格式的对象字符串,返回给界面
将Set集合对象转换为JSon格式的对象字符串,返回给界面 需要导入的jar包: 编写:servlet: package com.west.webcourse.servlet; import java ...
- php 警告
php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...
- struts2中的ognl详解,摘抄
http://blog.csdn.net/tjcyjd/article/details/6850203 很全很细致,自己再分析原理进阶
- 夺命雷公狗---node.js---8url模块和util模块
我们先到手册上看看: 上面很明显就写着返回一个对象. 再来看看util模块, 废话不哦多说,先上一点代码: /** * Created by leigood on 2016/8/13. */ var ...
- linux中关于php和nginx用户权限的一些东西
当我们启动nginx之后, 会有两个nginx进程(一个是master, 一个是worker). master的用户身份是root, worker用户的身份是nobody. 在nginx中可以修改 w ...
- 【py】配置python环境
首先,在ubuntu 10.10之后的版本中,要这样安装 sudo apt-get install python-pip python-dev build-essential sudo pip ins ...
- hadoop 启动停止命令
1 批量启动与停止 1.1 Start-all.sh # Start all hadoop daemons. Run this on master node. bin=`dirname ...
- Objective-C代码的文件扩展名与数据类型
Objective-C数据类型可以分为:基本数据类型.对象类型和id类型. 基本数据类型有:int.float.double和char类型. 对象类型就是类或协议所声明的指针类型,例如:SAutore ...