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
 
 
 
解析:
 
 
 
 
 
  1. #include <bits/stdc++.h>
  2.  
  3. int a[105];
  4.  
  5. int gcd(int a, int b)
  6. {
  7. return b == 0 ? a : gcd(b, a%b);
  8. }
  9.  
  10. int main()
  11. {
  12. int T, n, m;
  13. scanf("%d", &T);
  14. while(T--){
  15. scanf("%d%d", &n, &m);
  16. memset(a, -1, sizeof(a));
  17. int x, y;
  18. while(m--){
  19. scanf("%d%d", &x, &y);
  20. a[x] = y;
  21. }
  22. if(a[1] == -1)
  23. a[1] = 100;
  24. if(a[2] == -1)
  25. a[2] = a[1];
  26. int p = a[1]+a[2], q = p;
  27. a[n+1] = 0;
  28. for(int i = n; i >= 3; --i){
  29. if(a[i] == -1)
  30. a[i] = a[i+1];
  31. q += a[i];
  32. }
  33. int g = gcd(p, q);
  34. printf("%d/%d\n", p/g, q/g);
  35. }
  36. return 0;
  37. }

  

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. Python Requests模块讲解4

    高级用法 会话对象 请求与响应对象 Prepared Requests SSL证书验证 响应体内容工作流 保持活动状态(持久连接) 流式上传 块编码请求 POST Multiple Multipart ...

  2. java基础知识回顾之---java StringBuffer,Stringbuilder与String的区别

    public class StringBuilderTest { /** * StringBuffer和Stringbuilder :使用与内容可以被修改的字符串 * 与String的区别:Strin ...

  3. POJ1789Truck History

    题意 : 说实话,题意我没看懂,后来让人给我讲的样例..... 4 aaaaaaa baaaaaa abaaaaa aabaaaa 0 这个样例的话,就是输入n下面n行,每行7个字母,让你依次选两行进 ...

  4. N! HDU 1042

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  5. lintcode:子数组之和为0

    题目: 子数组之和 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出[-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. 解 ...

  6. struts2中利用POI导出Excel文档并下载

    1.项目组负责人让我实现这个接口,因为以前做过类似的,中间并没有遇到什么太困难的事情.其他不说,先上代码: package com.tydic.eshop.action.feedback; impor ...

  7. Java开发工具MyEclipse的设置自动联想功能

    最近初学Java,正在使用MyEclipse来编写新的项目,刚开始打开MyEclipse感觉这个工具既陌生又熟悉,熟悉之处在于编辑器的几大共通之处它都具备,比如说基本的设置.编辑区.调试区都是类似的, ...

  8. HDU 4565 So Easy!(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...

  9. rundeck email配置文件配置

    最近工作中用到了一个任务管理软件rundeck,其中有个很重要的功能就是任务执行提醒,用邮件执行,其中一些配置项,官网没有详细的说明,在网上也没有一个整体的说明,在次跟大家共享下,rundeck的使用 ...

  10. windows 下 apache设置

    apache,apache配置,配置端口 mac下apache配置 添加虚拟主机: Alias /selftest/ "D:/self-test/" <Directory & ...