It's All In The Mind

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 409    Accepted Submission(s): 189

Problem 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=1 ai 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
 
Author
zimpha
 
Source
 
 
 
解析:
 
 
 
 
 
#include <bits/stdc++.h>

int a[105];

int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a%b);
} int main()
{
int T, n, m;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
memset(a, -1, sizeof(a));
int x, y;
while(m--){
scanf("%d%d", &x, &y);
a[x] = y;
}
if(a[1] == -1)
a[1] = 100;
if(a[2] == -1)
a[2] = a[1];
int p = a[1]+a[2], q = p;
a[n+1] = 0;
for(int i = n; i >= 3; --i){
if(a[i] == -1)
a[i] = a[i+1];
q += a[i];
}
int g = gcd(p, q);
printf("%d/%d\n", p/g, q/g);
}
return 0;
}

  

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

  1. 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 ...

  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 (贪心) 2016杭电多校联合第二场

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

  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. 2016 Multi-University Training Contest 2题解报告

    A - Acperience HDU - 5734 题意: 给你一个加权向量,需要我们找到一个二进制向量和一个比例因子α,使得|W-αB|的平方最小,而B的取值为+1,-1,我们首先可以想到α为输入数 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. **json_encode:让Json更懂中文(JSON_UNESCAPED_UNICODE)

    我们知道, 用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式, 还会在一定程度上增加传输的数据量. 代码如下: <?php echo ...

  2. 李洪强iOS开发之【零基础学习iOS开发】【01-前言】01-开篇

    从今天开始,我就开始更新[零基础学习iOS开发]这个专题.不管你是否涉足过IT领域,也不管你是理科生还是文科生,只要你对iOS开发感兴趣,都可以来阅读此专题.我尽量以通俗易懂的语言,让每个人都能够看懂 ...

  3. java retention注解

    Retention注解 Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值:1.RetentionPolicy.SOURCE —— 这种类型的Annotations只在源 ...

  4. 删除元素 不存在 NO 存在 输出余下元素

    #include<stdio.h> #include<stdlib.h> #define N 5 #define NULL 0 #define OK 1 #define ERR ...

  5. GridView 和ListView中自适应高度

    android中GridView  和ListView放在scrollView中时会默认的只有一行高这时就要我们自己计算出它的高度啦 首先是listview的 //动态设置listview的高度 pu ...

  6. (转)Struts 拦截器

    一.拦截器是怎么实现: 实际上它是用Java中的动态代理来实现的 二.拦截器在Struts2中的应用 对于Struts2框架而言,正是大量的内置拦截器完成了大部分操作.像params拦截器将http请 ...

  7. Segmentation Fault错误原因总结

    最近在项目上遇到了Segmentation Fault的错误,一直调试不出来是哪里出了问题,对于刚接触嵌入式的,也不知道该如何去调试一个项目,定位内存问题,纠结了好几天,好阿红整理下自己的思路.从头开 ...

  8. struts2中token防止重复提交表单

    struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...

  9. VirtualBox虚拟机剪贴板共享

    默认VirtualBox的虚拟机和主机的剪贴板和拖拽不会共享的,因此需要我们进行处理. 一般情况下,我们选中虚拟机,然后设置剪贴板和拖拽为双向就ok了,但是我这里并没有好,设置如下图: 当我设置上面的 ...

  10. 如何使用UIAutomation进行iOS 自动化测试(Part I)

    转自:http://www.cnblogs.com/vowei/archive/2012/08/10/2631949.html 写在前面 研究iOS的自动化测试也有些日子了,刚开始的时候,一直苦于找不 ...