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. GYM 101350 F. Monkeying Around

    F. Monkeying Around time limit per test 2.0 s memory limit per test 256 MB input standard input outp ...

  2. UvaLive1347

    Programming contests became so popular in the year 2397 that the governor of New Earck — the largest ...

  3. Leetcode59. Spiral Matrix II螺旋矩阵2

    给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵. 示例: 输入: 3 输出: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, ...

  4. 将jacoco集成到测试工具平台

    最近在做接口测试,想通过代码覆盖率来判断一下接口用例是否缺失,但是每次通过命令来生成覆盖率报告,感觉太麻烦,所以就想着把jacoco集成到测试工具平台中,只需要点几个按钮,就能查看到覆盖率报告. 测试 ...

  5. web前端学习(二)html学习笔记部分(9)-- 响应式布局

    1.2.23  响应式布局基础 1.2.23.1  响应式布局介绍 1.响应式布局是2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多终端 -- 而不是为每个终端做一个特定的版本.这个概 ...

  6. FZU 1576【计算几何/费马点】

    Oaiei居住在A城市,并且是这个城市建设的总设计师.最近有个问题一直困恼着他.A城市里有三个大型工厂,每个大型工厂每天都需要消耗大量的石油,现在城市里要建设一个石油中转站,从石油中转站到三个大型工厂 ...

  7. Element UI table组件源码分析

    本文章从如下图所示的最基本的table入手,分析table组件源代码.本人已经对table组件原来的源码进行削减,源码点击这里下载.本文只对重要的代码片段进行讲解,推荐下载代码把项目运行起来,跟着文章 ...

  8. iOS 中的 Deferred Deep Linking(延迟深度链接)

    http://www.cocoachina.com/ios/20160105/14871.html Deep Linking 其实 deep linking 并不是一个新名词,在 web 开发领域,区 ...

  9. Hibernate QBC 简单收集

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

  10. 【如花美眷】初探weex

    我想我更喜欢weex的原因,应该是weex可以直接运行在浏览器中,而不是像react-native需要运行在模拟设备中. 我想这个原因足以让我使用vue而不是RN. 初探就是稍微运行一下,来看步骤 可 ...