Hust oj 2000 极差(水题)
来源:互联网 发布:mac如何设置分辨率 编辑:程序博客网 时间:2024/05/16 15:33
极差Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 211(141 users)Total Accepted: 155(136 users)Rating: Special Judge: NoDescription小辉是个顽皮的胖孩纸,总爱在老师的黑板上乱涂乱画,又一次他在老师的黑板上写了有n个正数组成的数列,这时小彪看见了,就说:“小胖子,就用黑板上的这些数,我考你一道题,你每次选中这些数的其中两个数a和b,然后将它们擦掉,再在黑板上写上a*b+1,直到剩下最后一个数。。。如果你能得到最小的数min和最大的数max,并求出max-min,我就给你买煎饼果子吃。” 听到了好吃的,小辉两眼放光,可是这种费脑细胞的问题小辉不会,请你来帮帮他。。。Input有多组测试数据,每组数据第一行是数列长度n(2<=n<=20),第二行是小辉所写的数列,最大值保证不超过int,输入处理到文件结束。Output输出max-min的值并换行。Sample Input
Sample Output
2
1 2
6
4 3 5 1 7 9
0
1688
想让得到的数越大,就要让被乘数越大,想要得到的数越小,就要让被乘数越小,所以分别遍历就好了
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int Maxn = 50;const int Inf = 0x3f3f3f;int a[Maxn];int n;int main(){ while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); int Max; int Min = a[n-1]; for(int i=n-1;i>0;i--) { Min = Min * a[i-1] + 1; } for(int i=1;i<n;i++) { a[i] = a[i-1] * a[i] + 1; sort(a+i,a+n); } Max = a[n-1]; printf("%d\n",Max - Min); }}
0 0
- Hust oj 2000 极差(水题)
- Hust oj 1369 Buy Computers(水题)
- Hust oj 2121 你猜猜(水题)
- Hust oj 2235 毒(水题)
- Hust oj 2125 钱多多(水题)
- Hust oj 1693 Difficult work(水题)
- Hust oj 1720 Fibonacci Numbers(水题)
- Hust oj 1629 统计图(水题)
- Hust oj 1431 摞盘子(水题)
- Hust oj 1046 Balls Collision(水题)
- Hust oj 2084(大数)
- Hust oj 1394 XianGe的游戏I(水题)
- Hust oj 1197 Cuts the cake(水题)
- Hust oj 1384 Leyni, LOLI and Toasts(水题)
- Hust oj 2116 Maximum continuous product(水题)
- Hust oj 1673 2013新的旅程(水题)
- Hust oj 1754 Minimum Scalar Product(水题)
- Hust oj 1648 Tailmon与序列(水题)
- runloop补充
- Linux-apache服务器
- 朴素贝叶斯
- 2016年总
- 使用Fresco遇到的坑。
- Hust oj 2000 极差(水题)
- java.util.UUID.fromString() 方法使用详解
- matlab基础知识
- halcon/c++接口基础 之 析构函数和Halcon算子
- 占位占位占位占位占位
- 对js中call、apply和bind的理解
- Unity3D开发之Matrix4x4矩阵变换
- Linux-dns服务器
- Maven的pom.xml文件结构之环境配置profiles