It's All In The Mind

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

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=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
 
Author
zimpha
 
题意:求a1+a2/a1+a2+..+an的最大值,其中只给出部分的值,ax=y;
 
水题,保证a1,a2最大,后面的尽量小就好,需要注意的是,这是非递增数列,后面有数赋值,会影响前面的数的取值。
 
附上代码:
 
 #include <iostream>
#include <cstdio>
using namespace std;
int a[];
int _gcd(int x,int y) ///求最大公约数
{
int z;
if(x<y) z=x,x=y,y=z;
while(y)
{
z=x%y;
x=y;
y=z;
}
return x;
}
int main()
{
int T,i,j,n,m;
scanf("%d",&T);
while(T--)
{
int x,y,t=;
scanf("%d%d",&n,&m);
for(i=; i<=n; i++) ///初始化全为-1
a[i]=-;
for(i=; i<m; i++)
{
scanf("%d%d",&x,&y);
a[x]=y;
}
if(n==||m==) ///若只有两个数,或者不给任何数赋值,都能输出最大的1/1
{
printf("1/1\n");
continue;
}
int nn=,mm=,fail=;
for(i=n; i>=; i--) ///因为前面的小于等于后面的,因此从后面向前面循环
{
if(a[i]!=-) ///如果a[i]被赋值,记录此时的a[i],并标记已出现赋值的数
{
t=a[i];
fail=;
mm+=t;
}
else
{
if(!fail) ///若没有出现已赋值的数,可以定义为后面的数始终为0
{
mm+=;
}
else ///若已出现,则只能小于等于这个数
{
mm+=t;
}
}
}
if(a[]==-) ///a1和a2期望越大越好,若都无赋值,就都取100,若有赋值,则去赋值的数,且a2小于a1
{
nn+=,mm+=;
if(a[]==-)
nn+=,mm+=;
else
nn+=a[],mm+=a[];
}
else
{
nn+=a[],mm+=a[];
if(a[]==-)
nn+=a[],mm+=a[];
else
nn+=a[],mm+=a[];
}
int dd=_gcd(nn,mm);
printf("%d/%d\n",nn/dd,mm/dd);
}
return ;
}

hdu 5742 It's All In The Mind(2016多校第二场)的更多相关文章

  1. hdu 5745 La Vie en rose(2016多校第二场)

    La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  2. hdu 5734 Acperience(2016多校第二场)

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. hdu 5744 Keep On Movin (2016多校第二场)

    Keep On Movin Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)

    题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...

  5. hdu 5305 Friends(2015多校第二场第6题)记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人on ...

  6. hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语

    题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输 ...

  7. hdu 5301 Buildings (2015多校第二场第2题) 简单模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...

  8. [2019HDU多校第二场][HDU 6591][A. Another Chess Problem]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6591 题目大意:二维坐标系上,所有满足\(5|2x+y\)的点都被设为障碍物,无法通过.现给出一对点, ...

  9. HDU6602 Longest Subarray hdu多校第二场 线段树

    HDU6602 Longest Subarray 线段树 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6602 题意: 给你一段区间,让你求最长的区间使 ...

随机推荐

  1. list的基本使用

    转自:https://www.cnblogs.com/BeyondAnyTime/archive/2012/08/10/2631191.html vector :vector和built-in数组类似 ...

  2. Django项目:CRM(客户关系管理系统)--03--02PerfectCRM创建ADMIN页面01

    八.CRM项目创建king_admin python.exe manage.py startapp king_admin 'king_admin', 九.CRM项目分发URL "" ...

  3. PHP协程:并发 shell_exec

    在PHP程序中经常需要用shell_exec执行一些命令,而普通的shell_exec是阻塞的,如果命令执行时间过长,那可能会导致进程完全卡住.在Swoole4协程环境下可以用Co::exec并发地执 ...

  4. Hibernate QBC 简单收集

    Hibernate QBC 介绍: QBC(Query By Criteria)通过 API 来检索对象 主要由 Criteria 接口.Criterion 接口和 Exception 类组成,支持在 ...

  5. Promise https://www.liaoxuefeng.com/wiki/1022910821149312/1023024413276544

    在JavaScript的世界中,所有代码都是单线程执行的. 由于这个“缺陷”,导致JavaScript的所有网络操作,浏览器事件,都必须是异步执行.异步执行可以用回调函数实现: function ca ...

  6. 小爬爬5:scrapy介绍2

    1.scrapy:爬虫框架 -框架:集成了很多功能且具有很强通用性的一个项目模板 -如何学习框架:(重点:知道有哪些模块,会用就行) -学习框架的功能模板的具体使用. 功能:(1)异步爬取(自带buf ...

  7. POJ 1679The Unique MST

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...

  8. WPF TextBox提示文字设定

    WPF TextBox框提示文字,鼠标划入提示文字消失 <TextBox Width=" VerticalContentAlignment="Center" Bor ...

  9. JavaScript--微博发布效果

    效果图: 实现思路:  当发布按钮被点击时,又会分为三种情况 1.如果输入的内容为空,弹出提示:不能发布空微博 2.如果输入的文字超过120,弹出提示,微博内容不能超过120 3.正常发布微博到列表里 ...

  10. Servlet Cookies

    Cookie是在多个客户端请求之间持久存储的一小段信息. Cookie具有名称,单个值和可选属性,例如注释,路径和域限定符,生存周期和版本号. Cookie工作原理 默认情况下,每个请求都被视为新的请 ...