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. Struts_客户列表练习

    1.导包 2.配置文件struts.xml 3.创建CustomerAction 4.修改menu.jsp和List.jsp 5.配置web.xml

  2. ZOJ3195 Design the city [2017年6月计划 树上问题04]

    Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...

  3. CF1132G

    听说,一个好的Oier都是题目喂出来的. 题目 定义一个序列的最长贪心严格上升子序列为:若选出的子序列为 \(a\),对于其中相邻两项 \(i,j\),不存在 b\(i<k<j\),满足在 ...

  4. (转)Json在Unity中的简单使用

    Json数据解析在Unity3d中的应用 最近做项目过程中因为Json文件名写错了一个字母Unity报错,找错误找到半夜,当时为了验错,写了一个小Demo,正好借此总结一下Json. 1.什么是Jso ...

  5. SASS:sass语法参照列表及教程

    http://sass-lang.com/documentation/file.SASS_REFERENCE.html 保存一下,上面的链接包括了scss中所有语法规则. 转载自:http://www ...

  6. 如何制作可以在 MaxCompute 上使用的 crcmod

    之前我们介绍过在 PyODPS DataFrame 中使用三方包.对于二进制包而言,MaxCompute 要求使用包名包含 cp27-cp27m 的 Wheel 包.但对于部分长时间未更新的包,例如 ...

  7. LintCode刷题笔记-- InterLeaving

    标签: 动态规划 解题思路 1. 这道题最重要的是,存在三个字符串,但是并不需要两个二维矩阵来进行解,因为可以使用i+j-1来代表s3的下标,这样就可以通过i和j来遍历s3了.因为对于任何一个合法的交 ...

  8. LintCode_488 快乐数

    题目 写一个算法来判断一个数是不是"快乐数". 一个数是不是快乐是这么定义的:对于一个正整数,每一次将该数替换为他每个位置上的数字的平方和,然后重复这个过程直到这个数变为1,或是无 ...

  9. MVVMDemo

    QueryCommand.cs using System;using System.Collections.Generic;using System.Linq;using System.Text;us ...

  10. C++ std::vector指定位置插入

    使用vector,必须加上:#include <vector> 1.初始化vector,一般有这几种方式: std::vector<std::wstring> v1; //创建 ...