1275 - Internet Service Providers
| Time Limit: 2 second(s) | Memory Limit: 32 MB |
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 |
思路:求导加二分
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<string.h>
6 #include<math.h>
7 #include<queue>
8 #include<set>
9 #include<stack>
10 #include<map>
11 #include<set>
12 using namespace std;
13 typedef long long LL;
14 LL ask(LL n,LL m, LL z)
15 {
16 return n*(z-n*m);
17 }
18 int main(void)
19 {
20 int i,j,k;
21 scanf("%d",&k);
22 int s;
23 for(s=1; s<=k; s++)
24 {
25 LL x,y;
26 scanf("%lld %lld",&x,&y);
27 LL l=-y;
28 LL r=y;
29 LL ac=0;
30 while(l<=r)
31 {
32 LL mid=(l+r)/2;
33 if(y-2*mid*x<=0)
34 {
35 ac=mid;
36 r=mid-1;
37 }
38 else l=mid+1;
39 }
40 LL ck=ac-1;
41 LL sum1=ask(ac,x,y);
42 LL sum2=ask(ac-1,x,y);
43 if(sum2>=sum1)
44 ac=ck;
45 printf("Case %d:",s);
46 printf(" %lld\n",ac);
47 }
48 return 0;
49 }
1275 - Internet Service Providers的更多相关文章
- POJ 3911:Internet Service Providers
Internet Service Providers Time Limit: 2MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I ...
- Laravel 之Service Providers
Service providers are the central place of all Laravel application bootstrapping. Your own applicati ...
- Custom Data Service Providers
Custom Data Service Providers Introduction Data Services sits above a Data Service Provider, which i ...
- 自定义Data Service Providers
自定义Data Service Providers 作者:AlexJ 翻译:谈少民 原文链接:http://blogs.msdn.com/b/alexj/archive/2010/01/07/data ...
- Hyperledger Fabric Membership Service Providers (MSP)——成员服务
Membership Service Providers (MSP) 本文将介绍有关MSPs的设置和最佳实践的详细方案. Membership Service Providers (MSP)是一个旨在 ...
- 使用SAP云平台 + JNDI访问Internet Service
以Internet Service http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Walldorf&destin ...
- LightOJ-1275-Internet Service Providers(数学)
链接: https://vjudge.net/problem/LightOJ-1275 题意: A group of N Internet Service Provider companies (IS ...
- Laravel 文档中的 Service Providers
$this->app->singleton('ReportServices', function () { return new \App\Services\ReportServices( ...
- Membership Service Providers (MSP)
https://blog.csdn.net/baidu_39649815/article/details/76468249 Membership service provider (MSP)是一个提供 ...
随机推荐
- Excel-满足指定条件并且包含数字的单元格数目,DCOUNT()
DCOUNT函数 函数名称:DCOUNT 主要功能:返回数据库或列表的列中满足指定条件并且包含数字的单元格数目. 使用格式:DCOUNT(database,field,criteria) 参数说明:D ...
- Python中的随机采样和概率分布(二)
在上一篇博文<Python中的随机采样和概率分布(一)>(链接:https://www.cnblogs.com/orion-orion/p/15647408.html)中,我们介绍了Pyt ...
- 多线程高级篇1 — JUC — 只弄到处理高并发集合问题
1.线程池 1.1).什么是线程池? 池( pool ),就是一个容器,所以线程池就是把多个线程对象放到一个容器中 1.2).如何创建线程池? 先来了解几个常识 Executor -- 这是一个接口( ...
- dart系列之:HTML的专属领域,除了javascript之外,dart也可以
目录 简介 DOM操作 CSS操作 处理事件 总结 简介 虽然dart可以同时用作客户端和服务器端,但是基本上dart还是用做flutter开发的基本语言而使用的.除了andorid和ios之外,we ...
- mysql-centos8下安装
参考文章 1.下载安装包 客服端与服务端 依赖包 2.linux下检查是否安装 rpm -qa | grep -i mysql 安装过会显示软件名称,没安装过就是空的 3.安装包传到虚拟机 先需要把安 ...
- 带你全面了解 OAuth2.0
最开始接触 OAuth2.0 的时候,经常将它和 SSO单点登录搞混.后来因为工作需要,在项目中实现了一套SSO,通过对SSO的逐渐了解,也把它和OAuth2.0区分开了.所以当时自己也整理了一篇文章 ...
- A Child's History of England.41
When intelligence of this new affront [hit in the face, c-o-n-frontation!] was carried to the King i ...
- CORS 如果需要指定多个域名怎么办
CORS 通过控制 Access-Control-Allow-Origin 控制哪些域名可以共享资源,取值如下 Access-Control-Allow-Origin: <origin> ...
- 2021广东工业大学十月月赛 F-hnjhd爱序列
题目:GDUTOJ | hnjhd爱序列 (gdutcode.cn) 一开始是用双指针从尾至头遍历,但发现会tle!! 后来朋友@77给出了一种用桶的做法,相当于是用空间换时间了. 其中用到的一个原理 ...
- Java发HTTP POST请求(内容为xml格式)
Java发HTTP POST请求(内容为xml格式) 一.POST请求 服务器地址:http://5.0.217.50:17001/VideoSend 服务器提供的是xml格式的http接口,接口定义 ...