题目链接:

It's All In The Mind

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)

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
 
题意:
 
给一个单调序列的一部分,让你求这个式子的最大值;
 
思路:
 
(a1+a2)/(∑ai)的最小值;就是∑ai/(a1+a2)的最大值;就是1+(a3+a4+...an)/(a1+a2)的最大值;然后就是分子上的尽量小,分母上的尽量大了,相当于不等式的放缩;
 
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e5+10;
const int maxn=500+10;
const double eps=1e-6; int a[maxn]; int gcd(int x,int y)
{
if(y==0)return x;
return gcd(y,x%y);
}
int main()
{
int t;
read(t);
while(t--)
{
int n,m;
read(n);read(m);
mst(a,-1);
int x,y;
For(i,1,m)
{
read(x);read(y);
a[x]=y;
}
int sum=0;
if(a[n]==-1)a[n]=0;
sum+=a[n];
for(int i=n-1;i>2;i--)
{
if(a[i]==-1)a[i]=a[i+1];
sum+=a[i];
}
if(a[1]==-1)a[1]=100;
if(a[2]==-1)a[2]=a[1];
int p,q;
p=a[1]+a[2];
q=sum+p;
//if(q==0)
int g=gcd(p,q);
cout<<p/g<<"/"<<q/g<<endl;
}
return 0;
}

  

hdu-5742 It's All In The Mind(数学)的更多相关文章

  1. HDU 5742 It's All In The Mind (贪心)

    It's All In The Mind 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...

  2. hdu 5742 It's All In The Mind 水题

    It's All In The Mind 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...

  3. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  4. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

  5. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  6. hdu 5742 It's All In The Mind(2016多校第二场)

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. HDU - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  8. HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))

    小C的倍数问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. HDU 3153 Pencils from the 19th Century(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...

  10. hdu 5492 Find a path(dp+少量数学)2015 ACM/ICPC Asia Regional Hefei Online

    题意: 给出一个n*m的地图,要求从左上角(0, 0)走到右下角(n-1, m-1). 地图中每个格子中有一个值.然后根据这些值求出一个最小值. 这个最小值要这么求—— 这是我们从起点走到终点的路径, ...

随机推荐

  1. mac os+selenium2+Firefox驱动+python3

    此文章建立在之前写的chrome+selenium+Python环境配置的基础上,链接http://blog.csdn.net/zxy987872674/article/details/5308289 ...

  2. Unable to connect to the MKS : Failed to connect to server XXXXXX:903

    Issue : 通过 vSphere 连接VM控制台的时候, 报错       Unable to connect to the MKS : Failed to connect to server X ...

  3. apk 签名

    给apk签名步骤:(比方apk名称是EasyMsg.apk) (1)将EasyMsg.apk包后缀改为zip, EasyMsg.zip (2)删除EasyMsg.zip文件包中的META-INF目录, ...

  4. Effective JavaScript Item 54 将undefined视为&quot;没有值&quot;

    将undefined视为"没有值" JavaScript中的undefined是一个特殊的值:当JavaScript没有提供详细的值时.它就会产生undefined. 比方: 未被 ...

  5. 定义自己的代码风格CheckStyle简单使用

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module PUBLIC "-/ ...

  6. mysql 查看当前连接数

    http://www.cnblogs.com/pcdelphi/archive/2009/10/31/2017990.html   实战经验: >登录到mysql数据库的终端 >show ...

  7. 在eclipse中查找指定文件 [多种方法]

    在eclipse中查找指定文件   1.ctrl+h打开搜索界面 File Search: containing text填*,File name patterns填写hello.*,可以找到hell ...

  8. idea常用的快捷命令

    main方法: psvm System.out.println(): sout

  9. Ubuntu16.04下屏幕侧边栏的设置

    ubnutu的任务栏都是在左侧: zhang@zhang-virtual-machine:~$ gsettings set com.canonical.Unity.Launcher launcher- ...

  10. LeetCode求能够装得最多的水

    费了半天劲还是没想出来,然后跑到网上找答案,明白了是怎么回事儿了,就是不知道为啥自己没有想出来. 明天再搞~~~ 国庆快乐~~~ 一年了~~~~~ 明年今日~~我会在哪儿 =====2017.9.30 ...