zoj3798Abs Problem(思维)
来源:互联网 发布:为什么脸会变宽 知乎 编辑:程序博客网 时间:2024/06/05 04:20
题目链接:
题目意思:
用1~n中的数字进行组合,得到后面减前面的一项的最大最小值。。。
思路:
多试两个就会发现从n到1的排列得到的是最小值,同理从n-1到1得到的也是最小值,那么用n-这个最小值,那么必定得到的是最大值。。。
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 11 22 1
#include<cstdio>#include<cmath>const int maxn=50000+10;int fabs(int x){ if(x<0) return -x; else return x;}int main(){ int n; while(~scanf("%d",&n)) { int Min=n; for(int i=n-1;i>=1;i--) Min=fabs(i-Min); int Max=n-1; for(int i=n-2;i>=1;i--) Max=fabs(i-Max); Max=fabs(n-Max); printf("%d %d\n",Min,Max); for(int i=n;i>1;i--) printf("%d ",i); printf("%d\n",1); for(int i=n-1;i>=1;i--) printf("%d ",i); printf("%d\n",n); } return 0;}
- zoj3798Abs Problem(思维)
- An easy problem 思维
- Problem K: Deadline----思维题
- 思维体操: HDU1022Train Problem I
- 【HDU 6038 Problem Description】+ 思维
- 【巧妙思维】【4-6】Problem F
- B. Far Relative’s Problem【思维】
- FZU 2038 Another Postman Problem【思维】
- hdu 5858 Hard problem【计算几何+思维】
- Codeforces Problem 707B Bakery(思维题)
- Light oj 1179 - Josephus Problem 【思维】
- HDU-2601-An easy problem【思维】
- HDU 2601 An easy problem(思维)
- Codefroces 527D Clique Problem【思维+贪心】
- HDU problem 5635 LCP Array【思维】
- Codeforces 340C Tourist Problem【思维】
- Problem-330A-Codeforce Cakeminator(思维)
- Problem-330B-Ceodeforces Road Construction(思维)
- Extjs4.2边学边用之Controller()
- virtualbox 磁盘大小调整
- Php实现验证码功能
- 趣味编程:静夜思(Javascript版)
- U盘安装CentOS 7的方法
- zoj3798Abs Problem(思维)
- 安装mysql5.7,不能下载Connector/ODBC 5.3.2
- python 的一些有趣用法
- 搭建Ubuntu的交叉编译浪费了我半天时间
- x4412开发板&ibox卡片电脑项目实战5-修改内核LOGO
- 《Linux程序设计》——使用curses函数库管理基于文本的屏幕
- zend studio 9 字体,颜色,快捷键
- 关于如何实现美团网的导航功能并且能重用ListView的Item(下载免费了)
- IOS之手势识别