hdu_5742_It's All In The Mind
题目链接:hdu_5742_It's All In The Mind
题意:
有一个部分的数列,让你找一个满足他给的三个条件的数列,使前两个数的和除这个数列的sum最大
题解:
xjb贪心一下就行了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cmath> 3 #define F(i,a,b) for(int i=a;i<=b;i++) 4 5 int gcd(int a,int b){return b?gcd(b,a%b):a;} 6 7 int a[110],t,n,m,x,y; 8 9 int main() 10 { 11 scanf("%d",&t); 12 while(t--) 13 { 14 scanf("%d%d",&n,&m); 15 F(i,1,n)a[i]=-1; 16 F(i,1,m)scanf("%d%d",&x,&y),a[x]=y; 17 int sum=0,pre=0,zi=0,gc; 18 for(int i=n;i>2;i--) 19 { 20 if(a[i]==-1)a[i]=pre; 21 else pre=a[i]; 22 sum+=a[i]; 23 } 24 pre=100; 25 F(i,1,2)if(a[i]==-1)sum+=pre,zi+=pre; 26 else pre=a[i],sum+=a[i],zi+=a[i]; 27 gc=gcd(sum,zi),sum/=gc,zi/=gc; 28 printf("%d/%d\n",zi,sum); 29 } 30 }