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

Sample Input

Sample Output
/
/

题意:

  有一个数字序列,给出数字序列的性质是:

  1.每个数最大为100,最小为0

  2.序列非递增

  3.序列总和不为0

  求出这个数列的最大值

  样例:第一行是T,表示T组测试样例,第二行是n,m。表示序列的长度和已知数的个数。下m行为xy,表示axi=yi

      第一组 长度为2,已知0个。则最大值为(100+100)/(100+100)或者(1+1)/(1+1)最大值为1。

      第二组长度为3,已知1个。已知的这一个为a3=1 。则最大值为(100+100)/(100+100+1)

思路:

  想求(a1+a2)/(a1+a2+...+an) 的最大值,只要让分母尽可能大,分子尽可能小即可。

  有两种情况,第一种为已知a1,a2。让不知道的数取最小值(不是0,因为要保证序列非递增)。

  第二种情况,不知道a1或者a2。让a1和a2取最大值(也要注意序列非递增)。

  最后用GCD求出a1+a2与序列和的最大公因数,然后取分数。

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int gcd(int a,int b)//求最大公约数
{
if(b==)
return a;
return gcd(b,a%b);
}
int main()
{
int a[],t,m,n;
scanf("%d",&t);
while(t--)
{
int i,j,x,y,sum1=,sum2=,ans=;
int w=;
scanf("%d%d",&n,&m);
for(i=; i<=n; i++)
a[i]=-;//初始化数组为-1,因为数组从0-100,所以可以用-1来表示
for(i=; i<=m; i++)
{
scanf("%d%d",&x,&y);
a[x]=y;//将已知条件赋值
}
for(i=n; i>=; i--)//从3-n尽量取最小
{
if(a[i]==-)//如果后面没有值,说明没有非递增限制,直接赋值为w,w初始为0
a[i]=w;
else//如果已经有值,则值前面的赋值为这个值。
{
w=a[i];
}
}
if(a[]==-)/*如果a[1]没有值,则赋值为100(最大)*/
a[]=;
if(a[]==-)/*如果a[2]没有值,则与a[1]相同*/
a[]=a[];
for(i=; i<=n; i++)
sum1+=a[i];
sum2=a[]+a[];
ans=gcd(sum2,sum1);
printf("%d/%d\n",(sum2/ans),(sum1/ans));
}
}

HDU5742 It's All In The Mind 数学思维题的更多相关文章

  1. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  2. Gym 100801D Distribution in Metagonia (数学思维题)

    题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...

  3. HDU5742 It's All In The Mind(思维题,水题)

    Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not ...

  4. 51Nod 1003 阶乘后面0的数量(数学,思维题)

    1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...

  5. BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题

    Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...

  6. BZOJ4377[POI2015]Kurs szybkiego czytania——数学思维题

    题目描述 给定n,a,b,p,其中n,a互质.定义一个长度为n的01串c[0..n-1],其中c[i]==0当且仅当(ai+b) mod n < p.给定一个长为m的小01串,求出小串在大串中出 ...

  7. EOJ2018.10 月赛(B 数学+思维题)

    传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 找到最小的包含子序列a的序列s,并且序列s是 p -莫干山序 ...

  8. EOJ2018.10 月赛(A 数学+思维题)

    传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 能否通过横着排或竖着排将 1x p 的小姐姐填满 n x m ...

  9. zoj 2818 Root of the Problem(数学思维题)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...

随机推荐

  1. idea编写的java代码,在cmd运行乱码解决方案

    1.解决方案 使用txt打开,另存为的时候选择编码为ANSI 即可.

  2. 【shell】shell中各种括号的作用()、(())、[]、[[]]、{}

    一.小括号,圆括号() 1.单小括号 ()    ①命令组.括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号隔开,最后一个命令可以没有 ...

  3. Python3安装Celery模块后执行Celery命令报错

    1 Python3安装Celery模块后执行Celery命令报错 pip3 install celery # 安装正常,但是执行celery 命令的时候提示没有_ssl模块什么的 手动在Python解 ...

  4. 【Windows使用笔记】Windows科研软件

    1 Anaconda Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项.主要是内置有jupyter notebook和jupyter ...

  5. 调试应用程序(Debugging Applications)

    调试应用程序(Debugging Applications)¶ Phalcon中提供了提供了几种调试级别即通知,错误和异常. 异常类 Exception class 提供了错误发生时的一些常用的调试信 ...

  6. Linux从入门到放弃

    Ch.0 几点Linux常识 Linux严格区分大小写,不像windows中命令是不区分大小写的 Linux中所有内容以文件形式保存,包括硬件 Linux不靠扩展名区分文件类型,所有扩展名只是为了方便 ...

  7. shellcheck 帮助你写出更好的脚本

    简介 shellcheck 是一款实用的 shell脚本静态检查工具. 首先,可以帮助你提前发现并修复简单的语法错误,节约时间.每次都需要运行才发现写错了一个小地方,确实非常浪费时间. 其次,可以针对 ...

  8. inetdev_init && inetdev_destroy

    inetdev_init为传入设备分配和绑定ip控制块,查看其调用关系如下: fs_initcall(inet_init)---->inet_init---->ip_init----> ...

  9. sunos kernel src

    https://github.com/eocallaghan/AuroraUX-SunOS https://github.com/zoyanhui/coroutine-libtask https:// ...

  10. C 实现有追求的线程池 探究

    引言 线程池很普通的老话题,讨论的很多.深入的不多,也就那些基础库中才能见到这种精妙完备的技巧.而本文随大流 想深入简述一种高效控制性强的一种线程池实现. 先引入一个概念, 惊群. 简单举个例子. 春 ...