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

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:

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

Professor Zhang wants to know the maximum value of among 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 integers and – the length of the sequence and the number of known elements.

In the next lines, each contains two integers and , 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 <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <cmath>
#include <algorithm>
#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<m; ++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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值