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:

  1. For every i∈{1,2,...,n}, 0≤ai≤100.
  2. The sequence is non-increasing, i.e. a1≥a2≥...≥an.
  3. 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 水题的更多相关文章

  1. HDU 5832 A water problem (带坑水题)

    A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...

  2. HDU 5889 Barricade(最短路+最小割水题)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  3. hdu 1038 Biker&#39;s Trip Odometer(水题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...

  4. HDU 2012 FZU 1756关于素数的一些水题

    HDU 2012 素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDU 2066 一个人的旅行(dijkstra水题+判重边)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...

  6. hdu 5538 House Building(长春现场赛——水题)

    题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others)   ...

  7. HDU 4461:The Power of Xiangqi(水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4461 题意:每个棋子有一个权值,给出红方的棋子情况,黑方的棋子情况,问谁能赢. 思路:注意“ if a play ...

  8. hdu 1012:u Calculate e(数学题,水题)

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

随机推荐

  1. Here’s just a fraction of what you can do with linear algebra

    Here’s just a fraction of what you can do with linear algebra The next time someone wonders what the ...

  2. [转载]Web API OData Inlinecount not working

    http://stackoverflow.com/questions/15422831/web-api-odata-inlinecount-not-working

  3. 在Emacs中启用Fcitx输入法

    安装fcitx输入法,在 ~/.xinitrc文件中添加如下内容 (我用startx启动图形环境,所以在~/.xinitrc中配置X会话) export LC_CTYPE="zh_CN.UT ...

  4. 第7月第11天 AVAsset

    1. An AVAsset defines the collective properties of the tracks that comprise the asset. (You can acce ...

  5. mysql主键的缺少导致备库hang

    最近线上频繁的出现slave延时的情况,经排查发现为用户在删除数据的时候,由于表主键的主键的缺少,同时删除条件没有索引,或或者删除的条件过滤性极差,导致slave出现hang住,严重的影响了生产环境的 ...

  6. 模板引擎--hogan

    学习地址:https://www.imooc.com/article/18493 Hogan的github地址镇楼:https://github.com/twitter/hogan.js

  7. Zookeeper+Curator 分布式锁

    本来想着基于zk临时节点,实现一下分布式锁,结果发现有curator框架.PS:原声API真的难用,连递归创建path都没有? 配置curator maven的时候,md配置了好几个小时,最后发现集中 ...

  8. 扩展BootstrapTable的treegrid功能

    扩展BootstrapTable的treegrid功能 阅读目录 一.效果预览 二.代码示例 三.组件需要完善的地方 四.总结 正文 前言:上篇  JS组件系列——自己动手封装bootstrap-tr ...

  9. 【AtCoder】ARC092

    C - 2D Plane 2N Points 把能连边的点找到然后跑二分图匹配即可 #include <bits/stdc++.h> #define fi first #define se ...

  10. JS代码浏览器兼容性 之 new Date()

    这里只测试3个浏览器的情况:IE, 火狐,谷歌. 一. 无参 //无参 var dateTime = new Date(); 所有浏览器都兼容,GOOD 二. 日期参数 //日期参数 格式1 var ...