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. (一)Git时间--初识版本控制工具

    //配置一下你的身份 git config --global use.name "Douzi" git config --global use.email "jdouzi ...

  2. 【NOI】2017 整数(BZOJ 4942,LOJ2302) 压位+线段树

    [题目]#2302. 「NOI2017」整数 [题意]有一个整数x,一开始为0.n次操作,加上a*2^b,或询问2^k位是0或1.\(n \leq 10^6,|a| \leq 10^9,0 \leq ...

  3. iOS-Socket编程体验

    CHENYILONG Blog Socket编程体验 Socket编程体验  技术博客http://www.cnblogs.com/ChenYilong/新浪微博http://weibo.com/lu ...

  4. CTSC/APIO2018滚粗记

    CTSC/APIO2018滚粗记 前言 从\(5.5\)晚上的火车到\(5.14\)早上的高铁 \(10\)天的时间真的过去的很快. 眨眼间,就到了今天晚上的颁奖. 至于结果如何,反而并不是那么重要了 ...

  5. Linux输出重定向>和>>的区别是什么

    [简介:>与>>的区别]   1 > 是定向输出到文件,如果文件不存在,就创建文件:如果文件存在,就将其清空:一般我们备份清理日志文件的时候,就是这种方法:先备份日志,再用`& ...

  6. python3之安装、pip、setuptools

    1.python3安装 下载地址:https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz #安装环境centOS 7 #安装依赖包: yum ...

  7. xtrabackup 恢复单个表【转】

    一.安装与备份 1. 下载安装XtraBackup$wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/tarba ...

  8. Linux本地解析文件/etc/hosts说明【原创】

    windows的域名本地解析文件hosts是可以一个域名对多个IP,如果有一个IP有问题,可以去解析到其他IP Linux的本地解析文件/etc/hosts,是否也可以这样呢.下面做了个测试 先看一下 ...

  9. 在SharePoint 2013里配置Excel Services

    配置步骤,请参看下面两篇文章 http://www.cnblogs.com/jianyus/p/3326304.html https://technet.microsoft.com/zh-cn/lib ...

  10. Windwos8.1下配置PHP环境

    一.     下载安装包: Apache2.2:http://mirrors.cnnic.cn/apache//httpd/binaries/win32/httpd-2.2.25-win32-x86- ...