标签:
#include<iostream> #include<stdio.h> using namespace std; int gcd(int a , int b) { if(b==0) return a; a%=b; return gcd(b,a); } int main(){ int t; int num[1005]; scanf("%d",&t); while(t--){ int n,m; scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) num[i]=-1; for(int i=0;i<m;i++ ){ int tmp1,tmp2; scanf("%d%d",&tmp1,&tmp2); num[tmp1]=tmp2; } int sum=0; if(num[1]==-1) num[1]=100; if(num[2]==-1) num[2]=num[1]; int tmp=0; for(int i=n;i>2;i--){ if(num[i]==-1) num[i]=tmp; else{ tmp=num[i]; } sum+=num[i]; } int div=gcd(sum+num[1]+num[2],num[1]+num[2]); if(div) printf("%d/%d\n",(num[1]+num[2])/div,(sum+num[1]+num[2])/div); else printf("0/1\n"); } return 0; }
首先判断 最后到结果是关于a1,a2的增函数,关于剩余和到减函数,令a1,a2尽可能大,其余数的和尽可能小就可以了。
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 565 Accepted Submission(s): 247
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/5694631.html