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. PHP获取真实客户端的真实IP的方法

    REMOTE_ADDR 是你的客户端跟你的服务器“握手”时候的IP.如果使用了“匿名代理”,REMOTE_ADDR将显示代理服务器的IP. HTTP_CLIENT_IP 是代理服务器发送的HTTP头. ...

  2. LAMP标准化安装

    操作系统说明: 操作系统 版本 linux red hat release 6.4 关键软件包说明: 软件包 版本 目录 运行用户 httpd-2.2.27.tar.gz 2.2.27 /usr/lo ...

  3. node的源码安装

    Node.js 安装配置 本章节我们将向大家介绍在 Windows 和 Linux 上安装 Node.js 的方法. 本安装教程以 Node.js v4.4.3 LTS(长期支持版本)版本为例. No ...

  4. 基于 DataLakeAnalytics 的数据湖实践

    随着软硬件各方面条件的成熟,数据湖(Data Lake)已经越来越受到各大企业的青睐, 与传统的数仓实践不一样的是,数据湖不需要专门的“入仓”的过程,数据在哪里,我们就从哪里读取数据进行分析.这样的好 ...

  5. Centos7.2源码编译安装LA(N)MP

    LAMP环境中php是作为apache的模块安装的,所以安装顺序是php放在apache的后面安装,这样便于安装php时可以在apache的模块目录生成对应的php模块. apache版本:2.4.3 ...

  6. 【模板】树的重心 洛谷P1364 医院设置

    P1364 医院设置 题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接 ...

  7. 廖雪峰Python总结4

    面向对象编程 将计算机程序视为一系列的命令集合.包含: 数据 操作数据的函数 Python中,所有的数据类型都可以视为对象. 面向对象特点:封装,继承,多态. 类的函数和普通函数:类的第一个参数永远是 ...

  8. Ubuntu无法连接无线网

    shell里输入: su ifconfig wlan0 up 不行的话 rfkill block all rfkill unblock all ifconfig wlan0 up

  9. Spring_Bean的作用域---和使用外部属性文件

    <!-- 使用 bean的scope属性来配置bean的作用域 singleton:默认值.容器初始时创建bean实例,在整个容器的生命周期内只创建这一个bean单例 prototype:原型的 ...

  10. 【JZOJ4921】【NOIP2017提高组模拟12.10】幻魔皇

    题目描述 幻魔皇拉比艾尔很喜欢斐波那契树,他想找到神奇的节点对. 所谓斐波那契树,根是一个白色节点,每个白色节点都有一个黑色节点儿子,而每个黑色节点则有一个白色和一个黑色节点儿子.神奇的节点对则是指白 ...