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,那 ...
随机推荐
- hdu 2433 Travel
http://acm.hdu.edu.cn/showproblem.php?pid=2433 题意: 求删除任意一条边后,任意两点对的最短路之和 以每个点为根节点求一个最短路树, 只需要记录哪些边在最 ...
- jenkins设置CSRF 协议(CRUMB值设置)
在关闭“”调用出现Error 403 No valid crumb was included in the request 第一种解决方式是 关闭 csrf,如上图,去掉勾就可以,但是并不推荐. 第二 ...
- 大话C#中能使用foreach的集合的实现
大家都知道foreach的语法:foreach(var item in items){ Console.Writeln(item);} 通过这样一个简单的语句,就能实现遍历集合items中的所有元素. ...
- ajax函数说明
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- python字典转datafarm,pandas
# coding:utf-8 import json import pandas as pd with open("./article_file/all_article.json" ...
- 面积并+扫描线 覆盖的面积 HDU - 1255
题目链接:https://cn.vjudge.net/problem/HDU-1255 题目大意:中文题目 具体思路:和上一篇的博客思路差不多,上一个题求的是面积,然后我们这个地方求的是啊覆盖两次及两 ...
- E1. Array and Segments (Easy version)(暴力) && E2. Array and Segments (Hard version)(线段树维护)
题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem ...
- click模块使用
# coding:utf8 import time import click @click.command() @click.option('--id', default='123', help='a ...
- Android Studio引用第三方jar包(例如:使用LitePal)
如何使用LitePal的教程网上很多,不过对于新手,这些教程中遗漏了将第三方jar包拷贝到app->libs路径下后,还需要add as library. 下载LitePal 这时操作步骤如下: ...
- Canvas 3D球形文字云动画特效
Canvas 3D球形文字云动画特效 效果图: 代码如下,复制即可使用: (适用浏览器:360.FireFox.Chrome.Opera.傲游.搜狗.世界之窗. 不支持Safari.IE8及以下浏览器 ...