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的更多相关文章

  1. POJ 3911:Internet Service Providers

    Internet Service Providers Time Limit: 2MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I ...

  2. Laravel 之Service Providers

    Service providers are the central place of all Laravel application bootstrapping. Your own applicati ...

  3. Custom Data Service Providers

    Custom Data Service Providers Introduction Data Services sits above a Data Service Provider, which i ...

  4. 自定义Data Service Providers

    自定义Data Service Providers 作者:AlexJ 翻译:谈少民 原文链接:http://blogs.msdn.com/b/alexj/archive/2010/01/07/data ...

  5. Hyperledger Fabric Membership Service Providers (MSP)——成员服务

    Membership Service Providers (MSP) 本文将介绍有关MSPs的设置和最佳实践的详细方案. Membership Service Providers (MSP)是一个旨在 ...

  6. 使用SAP云平台 + JNDI访问Internet Service

    以Internet Service http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Walldorf&destin ...

  7. LightOJ-1275-Internet Service Providers(数学)

    链接: https://vjudge.net/problem/LightOJ-1275 题意: A group of N Internet Service Provider companies (IS ...

  8. Laravel 文档中的 Service Providers

    $this->app->singleton('ReportServices', function () { return new \App\Services\ReportServices( ...

  9. Membership Service Providers (MSP)

    https://blog.csdn.net/baidu_39649815/article/details/76468249 Membership service provider (MSP)是一个提供 ...

随机推荐

  1. php操作mongodb手册地址

    php操作mongodb手册地址: http://php.net/manual/zh/class.mongocollection.php

  2. go 函数进阶

    目录 回调函数和闭包 高阶函数示例 回调函数(sort.SliceStable) 闭包 最佳闭包实例 回调函数和闭包 当函数具备以下两种特性的时候,就可以称之为高阶函数(high order func ...

  3. 【编程思想】【设计模式】【行为模式Behavioral】状态模式State

    Python版 https://github.com/faif/python-patterns/blob/master/behavioral/state.py #!/usr/bin/env pytho ...

  4. 【Linux卷管理】LVM创建与管理

    安装LVM 首先确定系统中是否安装了lvm工具: [root@jetsen ~]# rpm -qa|grep lvm system-config-lvm-1.1.5-1.0.el5 lvm2-2.02 ...

  5. 封装一个按Key排序的Map工具

    Map是集合的存放顺序是按哈希值定的,有时候不是我们需要的,当想要一个按自己规定顺序存放顺序,可以用LinkedHashMap,这里自己把LinkedHashMap封装了一次 package test ...

  6. [PROC FREQ] 单组率置信区间的计算

    本文链接:https://www.cnblogs.com/snoopy1866/p/15674999.html 利用PROC FREQ过程中的binomial语句可以很方便地计算单组率置信区间,SAS ...

  7. jenkins实例 nodejs项目

    目录 一.案例1 二.案例2 一.案例1 使用shell方式 #清理上一次版本,拉取新代码 rm -rf /server/admin-web cd /server git clone http://g ...

  8. Nginx状态码和日志

    目录 一.Nginx状态返回码 二.Nginx日志统计 一.Nginx状态返回码 http返回状态码(Status-Code), 以3位数字组成 200 成功 301 永久重定向(redirect) ...

  9. shell脚本 系统状态信息查看

    一.简介 源码地址 日期:2018/6/23 介绍:显示简单的系统信息 效果图: 二.使用 适用:centos6+,ubuntu12+ 语言:中文 注意:无 下载 wget https://raw.g ...

  10. [BUUCTF]REVERSE——[BJDCTF2020]BJD hamburger competition

    [BJDCTF2020]BJD hamburger competition 附件 步骤: 例行检查,64位程序,无壳儿 由于unity是用C++开发的,这里就不用IDA了,直接用dnspy看源码 在B ...