hdu-5742 It's All in the Mind (math)

Source: Internet
Author: User

Topic Links:

It's all on the mind

Time limit:2000/1000 MS (java/others)

Memory limit:65536/65536 K (java/others)


problem DescriptionProfessor Zhang has a number sequencea1,a2,.. . ,an . However, the sequence isn't complete and some elements is missing. Fortunately, Professor Zhang remembers some properties of the sequence:

1. For everyi∈{1,2,.. . ,N} ,0≤ai≤ .
2. The sequence is non-increasing, i.e.a1≥a2≥. . ≥an .
3. The sum of all elements in the sequence are not zero.

Professor Zhang wants to know the maximum value ofA1+ a2 ∑n i =1ai Among all the possible sequences.

InputThere is multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case:

The first contains and the integersNandm (2≤n≤,0≤m≤n) -The length of the sequence and the number of known elements.

In the nextmLines, each contains, integersxi andyi (1≤XI≤N,0≤YI≤100,XI<xi+1,yi≥yi+1) , indicating that axi=yi.

OutputFor each test case, the output of the answer as an irreducible fraction "P/Q", where P, q is integers, q>0.

Sample Input 22 03 13 1

Sample output 1/1200/201  Test Instructions:  gives a part of a monotone sequence that allows you to find the maximum value of this equation;  the minimum value of:  (A1+A2)/(∑ai); it is ∑ai/(a1+ A2) is the maximum value of 1+ (a3+a4+...an)/(A1+A2), then the numerator is as small as possible, the denominator of the largest, equivalent to the reduction of inequalities; &NBSP;AC Code:
#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) {C Har 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 (math)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.