lightoj 1275 - Internet Service Providers 【求导】
来源:互联网 发布:白凡泄露天机知乎 编辑:程序博客网 时间:2024/05/16 01:38
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.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a line containing two integers N and C (0 ≤ N, C ≤ 109).
Output
For each case, print the case number and the minimum possible value of T that maximizes the total profit. The result should be an integer.
Sample Input
Output for Sample Input
6
1 0
0 1
4 3
2 8
3 27
25 1000000000
Case 1: 0
Case 2: 0
Case 3: 0
Case 4: 2
Case 5: 4
Case 6: 20000000
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN 500000+10#define MAXM 50000000#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long longusing namespace std;int main(){ int t, kcase = 1; Ri(t); W(t) { LL N, C; Rl(N); Rl(C); LL ans; if(N == 0) ans = 0; else if(C % (2*N) == 0) ans = C / 2 / N; else { LL a = C / 2 / N; LL b = a + 1; if(a*(C-a*N) >= b*(C-b*N)) ans = a; else ans = b; } printf("Case %d: %lld\n", kcase++, ans); } return 0;}
- lightoj 1275 - Internet Service Providers 【求导】
- LightOJ 1275 - Internet Service Providers
- LIGHTOJ-1275 - Internet Service Providers
- LightOJ 1275 Internet Service Providers
- LightOJ 1275 - Internet Service Providers
- LightOJ 1275:Internet Service Providers
- LightOJ 1275 - Internet Service Providers (简单数学)
- lightoj 1275 - Internet Service Providers 一元二次方程
- poj 3911--Internet Service Providers【求导】
- 【数学-二元一次方程求最值】LightOJ Internet Service Providers 1275
- LightOJ 1275 Internet Service Providers(数学求解)
- lightoj 1275 - Internet Service Providers (基本数学-二元一次方程)
- 【Light】[1275]Internet Service Providers
- LightOJ 1275 Internet Service Providers <一元二次函数的最值>
- Light OJ: 1275 - Internet Service Providers【数学】
- E - Internet Service Providers
- Internet Service Providers
- WOJ1406-Internet Service Providers
- android 蓝牙断开监听
- assert()函数用法
- PAT-PAT (Advanced Level) Practise 1012 The Best Rank (25) (简单模拟)【二星级】
- HDOJ 2540 遮挡判断(数学)
- mongodb 性能测试
- lightoj 1275 - Internet Service Providers 【求导】
- 1008 Elevator
- leetcode 65:Valid Number 使用字符串匹配的细致分析
- leetcode-Implement Queue using Stacks
- 1009 product of Ploynomials
- 【面试题】:兄弟字符串
- 拓扑排序
- Swift中的!和?
- 软件开发中设计为什么应该只有一个所有人?