HDU 5742 It's All In The Mind(思维水)
来源:互联网 发布:dede免费源码站 编辑:程序博客网 时间:2024/05/22 06:48
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 everyi∈{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 ofa1+a2∑ni=1ai among all the possible sequences.
1. For every
2. The sequence is non-increasing, i.e.
3. The sum of all elements in the sequence is not zero.
Professor Zhang wants to know the maximum value of
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 integersn and m (2≤n≤100,0≤m≤n) -- the length of the sequence and the number of known elements.
In the nextm lines, each contains two integers xi and yi (1≤xi≤n,0≤yi≤100,xi<xi+1,yi≥yi+1) , indicating that axi=yi .
The first contains two integers
In the next
Output
For each test case, output the answer as an irreducible fraction "p /q ", where p , q are integers, q>0 .
Sample Input
22 03 13 1
Sample Output
1/1200/201
题意:一个长度n的非升序的未知序列a1,a2,a3...an,元素的值范围为[0,100],题目会给定一些已确定元素的值,除给定元素随意构造其他元素的值,使得
设A = a1 + a2,B = a3 + a4 + ... + an,则题中公式可以写成
A A + B
#include <bits/stdc++.h>using namespace std;int s[110];int main(){int t,n,m,x,y;scanf("%d",&t);while(t--){scanf("%d %d",&n,&m);memset(s,0,sizeof(s));s[1] = s[2] = 100;for(int i = 0 ; i < m ; i++){scanf("%d %d",&x,&y);s[x] = y;}s[2] = s[2] == 100 ? s[1] : s[2];int a = s[1] + s[2];int b = a, pre = 0;for(int i = n ; i >= 3 ; i--){if(!s[i]) s[i] = pre;else pre = s[i];b += s[i];}int g = __gcd(a,b);printf("%d/%d\n",a / g,b / g);} return 0;}
ai
0 0
- HDU 5742 It's All In The Mind(思维水)
- HDU 5742 It's All In The Mind(贪心?)
- HDU 5742 It's All In The Mind(贪心)
- (HDU 5742) It's All In The Mind <思维水题> 2016 Multi-University Training Contest 2
- It's All In The Mind HDU
- hdu 5742 It's All In The Mind(2016 Multi-University Training Contest 2——思维题)
- 贪心-HDU-5742-It's All In The Mind
- hdu 5742 It's All In The Mind
- HDU 5742 It's All In The Mind (水题)
- hdu 5742 It's All In The Mind
- 【HDU】5742 It's All In The Mind
- hdu 5742 It's All In The Mind
- HDU 5742 It's All In The Mind
- HDU 5742 It's All In The Mind 水题
- HDU 5742 It's All In The Mind 贪心
- 5742 ( It's All In The Mind )
- hdu5742 It's All In The Mind(水)
- HDU 5742 It's All In The Mind(水题【多校联合】)
- 文章标题
- HDU 5735 Born Slippy
- POJ2377-Bad Cowtractors
- [172] Factorial Trailing Zeroes
- 【几何】平面线段交
- HDU 5742 It's All In The Mind(思维水)
- C++ pure virtual function call
- Unity全面的面试题(包含答案)
- 1074. Reversing Linked List (25)
- 国内一线互联网公司面试题库
- 机器学习之k近邻法
- @RequestMapping测试各种访问方式
- gradle 神器编译不同的渠道包
- jquery中css()与animate()