题目链接:

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;
}

  

最新文章

  1. Event的Propagate
  2. mysql 重置root密码
  3. 工作随笔——Swift中的Range和一些字符操作
  4. CentOS 6.5部署安装Memcached
  5. ==和equals的区别
  6. POJ 2193 Lenny&#39;s Lucky Lotto Lists (DP)
  7. JavaScript中值的真真假假(true and false)
  8. CSS属性[text-overflow]使用问题
  9. New ipad install Metasploit(New ipad 安装Metasploit)
  10. oschina企业应用
  11. 观察者模式:猫叫鼠跑人醒(C#)
  12. PHP发送短信如何实现?
  13. C语言-指针、数组、结构体、分支、循环混合使用
  14. Node.js之包与npm包管理工具
  15. C语言程序设计第一次实验
  16. Python基础之 函数名,闭包,和迭代器
  17. p9半幺群
  18. Django--分页器(paginator)
  19. 【IDEA&amp;&amp;Eclipse】2、从Eclipse转移到IntelliJ IDEA一点心得
  20. python 全栈开发,Day108(客户管理之权限控制,客户管理之动态&quot;一级&quot;菜单,其他应用使用rbac组件,django static文件的引入方式)

热门文章

  1. iOS开发 NSArray技巧
  2. fast-cgi &amp; php-fpm 等的理解
  3. Majority Number
  4. [Guava源代码阅读笔记]-Basic Utilities篇-1
  5. C#.NET的TabControl如何隐藏和显示页面
  6. 几个关于tableView的问题解决方式整合
  7. 构造方法后面带:this()
  8. 转 Python Selenium设计模式-POM
  9. SDUT 1068-Number Steps(数学:直线)
  10. linux find prune排除某目录或文件