hdu5742——It's All In The Mind(模拟)

2016-12-02 12:52:55来源:网络收集作者:路过秋天人点击

第七城市

Problem Description
Professor Zhang has a number sequence . However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:


For every , .
The sequence is non-increasing, i.e. .
The sum of all elements in the sequence is not zero.

Professor Zhang wants to know the maximum value ofamong all the possible sequences.


Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:


The first contains two integersand – the length of the sequence and the number of known elements.


In the nextlines, each contains two integersand, indicating that .


Output
For each test case, output the answer as an irreducible fraction “/”, where ,are integers, .


Sample Input
2
2 0
3 1
3 1


Sample Output
1/1
200/201


题意很简单,前两个数要尽可能大,后面的数要尽可能小,序列又是非递增的,最大值为200


#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f
#define MAXN 1010
#define mod 1000000007
using namespace std;
long long gcd(long long a,long long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int a[MAXN];
int main()
{
int t,n,m,x,y;
scanf("%d",&t);
while(t--)
{
memset(a,-1,sizeof(a));
scanf("%d%d",&n,&m);
if(m==0)
{
printf("1/1/n");
continue;
}
for(int i=0; i {
scanf("%d%d",&x,&y);
a[x]=y;
}
int ans1=0,ans2=0;
if(a[1]==-1&&a[2]==-1)
ans1=200;
if(a[1]!=-1&&a[2]==-1)
ans1=2*a[1];
if(a[1]==-1&&a[2]!=-1)
ans1=100+a[2];
if(a[1]!=-1&&a[2]!=-1)
ans1=a[1]+a[2];
int p=2;
for(int i=3; i<=n; ++i)
{
if(a[i]!=-1)
{
ans2+=(i-p)*a[i];
p=i;
}
}
ans2+=ans1;
if(ans1==0&&ans2==0)
ans2++;
int c=gcd(ans1,ans2);
ans1/=c,ans2/=c;
printf("%d/%d/n",ans1,ans2);
}
return 0;
}
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台