题目链接:hdu_5742_It's All In The Mind
题意:
有一个部分的数列,让你找一个满足他给的三个条件的数列,使前两个数的和除这个数列的sum最大
题解:
xjb贪心一下就行了。
#include<cstdio>
#include<cmath>
#define F(i,a,b) for(int i=a;i<=b;i++) int gcd(int a,int b){return b?gcd(b,a%b):a;} int a[],t,n,m,x,y; int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
F(i,,n)a[i]=-;
F(i,,m)scanf("%d%d",&x,&y),a[x]=y;
int sum=,pre=,zi=,gc;
for(int i=n;i>;i--)
{
if(a[i]==-)a[i]=pre;
else pre=a[i];
sum+=a[i];
}
pre=;
F(i,,)if(a[i]==-)sum+=pre,zi+=pre;
else pre=a[i],sum+=a[i],zi+=a[i];
gc=gcd(sum,zi),sum/=gc,zi/=gc;
printf("%d/%d\n",zi,sum);
}
}