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

Source

2016 Multi-University Training Contest 2

##题意:

对于一个数组a1 - an,部分元素已知,部分未知.
数组满足性质:0≤ai≤100, 非严格递减, 所有数之和非0.
求所有满足情况的数组中,a1+a2/sum(ai) 的最大值.


##题解:

贪心的想法:
a1和a2应该尽量大; 其余数尽量小.
WA点:a1已知但a2未知,注意不要把a2直接赋成100;
WA了一个下午....弱的不行


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define double LL
#define eps 1e-8
#define maxn 150
#define mod 1000000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n,m;

int num[maxn];

int gcd(int a, int b) {

return b==0? a:gcd(b,a%b);

}

int main(void)

{

//IN;

int t; cin >> t;
while(t--)
{
memset(num, -1, sizeof(num));
cin >> n >> m;
for(int i=1; i<=m; i++) {
int x,y; scanf("%d %d", &x,&y);
num[x] = y;
} int mimi = 0;
for(int i=n; i>=3; i--) {
if(num[i] == -1) {
num[i] = mimi;
} else {
mimi = num[i];
}
} if(num[1] == -1) num[1] = 100;
if(num[2] == -1) num[2] = min(100, num[1]); int sum1 = num[1] + num[2];
int sum2 = sum1;
for(int i=3; i<=n; i++) sum2 += num[i];
if(sum2 == 0) sum2 = 1; int gcds = gcd(sum1, sum2);
printf("%d/%d\n", sum1/gcds, sum2/gcds);
} return 0;

}

HDU 5742 It's All In The Mind (贪心)的更多相关文章

  1. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

  2. 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 Zhan ...

  3. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  4. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  5. hdu 5742 It's All In The Mind(2016多校第二场)

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  6. HDU 5055 Bob and math problem(简单贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的 ...

  7. HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...

  8. HDU 1053 Entropy(哈夫曼编码 贪心+优先队列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Time Limit: 2000/1000 MS (Java/Others)   ...

  9. HDU 1052 Tian Ji -- The Horse Racing (贪心)(转载有修改)

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. JVM参数配置

    JVM参数配置 设置堆大小 -Xms 初始堆大小 -Xmx 最大堆大小 -Xmn 设置年轻代大小 设置每个线程堆栈大小 -Xss 设置每个线程的堆栈大小 设置年轻代大小 -XX:NewSize= -X ...

  2. 5 commands to check memory usage on Linux

    Memory Usage On linux, there are commands for almost everything, because the gui might not be always ...

  3. RazorEngine 3.6.5.0

    public class Person { public string Name { get; set; } public string Code { get; set; } } var templa ...

  4. UVa 1467 (贪心+暴力) Installations

    题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...

  5. UVA 10917 Walk Through the Forest(dijkstra+DAG上的dp)

    用新模板阿姨了一天,换成原来的一遍就ac了= = 题意很重要..最关键的一句话是说:若走A->B这条边,必然是d[B]<d[A],d[]数组保存的是各点到终点的最短路. 所以先做dij,由 ...

  6. 使用D3D渲染YUV视频数据

    源代码下载 在PC机上,对于YUV格式的视频如YV12,YUY2等的显示方法,一般是采用DIRECTDRAW,使用显卡的OVERLAY表面显示.OVERLAY技术主要是为了解决在PC上播放VCD而在显 ...

  7. [转]Android调用so文件(C代码库)方法详解

    一.为什么调用c的dll要用源码编译成so库 Android系统是基于linux内核的移动终端系统,而dll是在windows环境下生成和调用的c库,所以不可以直接为android系统调用. 二.安装 ...

  8. 调试WEB APP多设备浏览器(转)

      方法:adobe shadow  \ opera远程调试\ weinre adobe shadow: 我们经常使用Firefox的firebug或者Chrome的开发人员工具进行Web调试页面,J ...

  9. 【c++内存分布系列】单独一个类

    首先要明确类型本身是没有具体地址的,它是为了给编译器生成相应对象提供依据.只有编译器生成的对象才有明确的地址. 一.空类 形如下面的类A,类里没有任何成员变量,类的sizeof值为1. #includ ...

  10. HDU 5835 Danganronpa

    Danganronpa Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...