hdu 5742 It's All In The Mind 水题
It's All In The Mind
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5742
Description
Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:
- For every i∈{1,2,...,n}, 0≤ai≤100.
- The sequence is non-increasing, i.e. a1≥a2≥...≥an.
- The sum of all elements in the sequence is not zero.
Professor Zhang wants to know the maximum value of a1+a2∑ni=1ai among all the possible sequences.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first contains two integers n and m (2≤n≤100,0≤m≤n) -- the length of the sequence and the number of known elements.
In the next m lines, each contains two integers xi and yi (1≤xi≤n,0≤yi≤100,xi<xi+1,yi≥yi+1), indicating that axi=yi.
Output
For each test case, output the answer as an irreducible fraction "p/q", where p, q are integers, q>0.
Sample Input
2
2 0
3 1
3 1
Sample Output
1/1
200/201
Hint
题意
你有n个数,现在给你规定一些数的取值。
然后你要给其他没有赋值的数赋值,使得这个序列是单调不增的序列。
并且(a1+a2)/sigma(a)最大,输出这个值。
题解:
贪心就好了,a1,a2取得越大越好,剩下的数取得越小越好。
先左右扫一下,确定每个数的取值范围,然后再扫一遍贪心就行了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 103;
int a[maxn];
int gcd(int aa,int bb){
if(bb==0)return aa;
return gcd(bb,aa%bb);
}
int Ma[maxn],Mi[maxn];
void solve(){
memset(a,-1,sizeof(a));
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<=n+1;i++){
Ma[i]=100;
Mi[i]=0;
}
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
Ma[x]=y;
Mi[x]=y;
}
for(int i=1;i<=n;i++)
Ma[i]=min(Ma[i],Ma[i-1]);
for(int i=n;i>=1;i--)
Mi[i]=max(Mi[i],Mi[i+1]);
long long up = 0;
long long down = 0;
for(int i=1;i<=n;i++){
if(i<=2)a[i]=Ma[i];
else a[i]=Mi[i];
down+=a[i];
}
up = a[1]+a[2];
if(down==0)down=1;
int g = gcd(up,down);
printf("%I64d/%I64d\n",up/g,down/g);
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}
hdu 5742 It's All In The Mind 水题的更多相关文章
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
- HDU 5889 Barricade(最短路+最小割水题)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- hdu 1038 Biker's Trip Odometer(水题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...
- HDU 2012 FZU 1756关于素数的一些水题
HDU 2012 素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 2066 一个人的旅行(dijkstra水题+判重边)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...
- hdu 5538 House Building(长春现场赛——水题)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4461:The Power of Xiangqi(水题)
http://acm.hdu.edu.cn/showproblem.php?pid=4461 题意:每个棋子有一个权值,给出红方的棋子情况,黑方的棋子情况,问谁能赢. 思路:注意“ if a play ...
- hdu 1012:u Calculate e(数学题,水题)
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 2674 N!Again(数学思维水题)
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
随机推荐
- NEGOUT: SUBSTITUTE FOR MAXOUT UNITS
NEGOUT: SUBSTITUTE FOR MAXOUT UNITS Maxout [1] units are well-known and frequently used tools for De ...
- CSS reset--(来自网易)
/* reset */ html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,capti ...
- ios TextField限制输入两位小数
只需要实现textField的这个代理方法就可以实现 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: ...
- 开放通用Api,总有你喜欢的
接口文档 目录 通用 更新记录 接口列表 一.福彩-双色球接口 指定期号中奖号码 最新中奖号码信息 获取双色球中奖信息列表 二.节假日及万年历 指定日期的节假日及万年历信息 指定多个日期的节假日及万年 ...
- 第10月第6天 lua 闭包
1. static int mytest(lua_State *L) { //获取上值 )); printf("%d\n", upv); upv += ; lua_pushinte ...
- Python 入门基础7 --文件操作
今日目录: 一.文件处理 1.什么是文件 2.为何用文件 3.如何用文件 4.文件操作 5.常用方法 6.文件内指针的移动 7.with的使用 一.文件处理 1. 什么是文件 文件是操作系统为用户/应 ...
- 采用jacob实现word转pdf
网络上已经有很多这方面的内容,在用之前也是参考了好多别人的文章,下面记录下我自己的整合过程.整个过程都比较简单: 开发环境:win8 64位系统,在2008下面部署也是一样的. 文档要求jdk的版本要 ...
- Axure RP 快速原型设计工具
Axure RP是美国Axure Software Solution公司旗舰产品,是一个专业的快速原型设计工具,让负责定义需求和规格.设计功能和界面的专家能够快速创建应用软件或Web网站的线框图 ...
- poj2679
题意:给出一个有向图,每条边有两个属性:一个长度一个费用.费用可能是负数.长度一定是非负的.给出一个起点和一个终点,现要求,从起点走到终点,且从每个点走出时选择的那条边必须是以该点作为起点的边中费用最 ...
- 安装Python3.6.4后,在使用numpy时报错RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
原因: 因为安装numpy用的是 pip来安装的 pypi官方对于numpy的库已经升级了,但是升级后的版本与其他的库不匹配 所以报错 解决: 先把已经安装的numpy卸载: pip uninstal ...