LightOJ-1275-Internet Service Providers(数学)

链接:

https://vjudge.net/problem/LightOJ-1275

题意:

A group of N Internet Service Provider companies (ISPs) use a private communication channel that has a maximum capacity of C traffic units per second. Each company transfers T traffic units per second through the channel and gets a profit that is directly proportional to the factor T(C - T*N). The problem is to compute the smallest value of T that maximizes the total profit the N ISPs can get from using the channel. Notice that N, C, T, and the optimal T are integer numbers.

思路:

函数最大值,直接计算,顺便再求下误差。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

int main()
{
    int t, cnt = 0;
    int n, c;
    scanf("%d", &t);
    while(t--)
    {
        printf("Case %d: ", ++cnt);
        scanf("%d%d", &n, &c);
        if (n == 0)
        {
            puts("0");
            continue;
        }
        int res = c/(2*n);
        if ((res+1)*(c-(res+1)*n) > (res*(c-res*n)))
            res = res+1;

        printf("%d\n", res);
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/11841373.html