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. git 新建分支并切换到该分支_Git 从master拉取代码创建新分支 并且再将修改合并到master...

    开发过程中会从master主分支copy到另一个开发分支: 1.切换到master分支 git  checkout  master 2.获取最新的代码 git pull origin master 3 ...

  2. LeetCode398-随机数索引

    原题链接:[398. 随机数索引]:https://leetcode-cn.com/problems/random-pick-index/ 题目描述: 给定一个可能含有重复元素的整数数组,要求随机输出 ...

  3. 转Android service 启动篇之 startForegroundService

    本文转自:https://blog.csdn.net/shift_wwx/article/details/82496447 前言: 在官方文档 Android 8.0 行为变更 中有这样一段话: An ...

  4. Linux基础命令---alias别名

    alias Alias不带参数或使用-p选项在标准输出上以"name=value"的形式打印别名列表.当提供参数时,为其值给定的每个名称定义一个别名.值中的尾随空格将导致在扩展别名 ...

  5. 【Linux】【Web】【Nginx】配置nginx日志到远程syslog服务器

    1. 概述: 主要是用于吧nginx的日志直接传送到远程日志收集的服务器上.远程日志服务器只要能够支持syslog协议都能够收到日志,本文的syslog服务器是IBM的日志收集系统Qradar. 2. ...

  6. Redis-5种基础数据结构

    Redis基础数据结构 知识整理源于<Redis深度历险 核心原理与应用实践>这本书 Redis 有的数据结构都以 唯一的 key 字符串作为名称,然后通过这个唯一 key 值来获取相应的 ...

  7. list.jsp页面

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><%@tag ...

  8. 车载以太网第二弹|测试之实锤-1000BASE-T1物理层PMA测试实践

    背景 100BASE-T1方兴未艾,国内外OEM量产车型纷至沓来:为了满足高带宽的应用场景需求(如图像.雷达等数据传输),1000BASE-T1将至已至,如大众MEB平台采用1000BASE-T1总线 ...

  9. 转: iPhone屏幕尺寸、分辨率及适配

    1.iPhone尺寸规格 设备 iPhone 宽 Width 高 Height 对角线 Diagonal 逻辑分辨率(point) Scale Factor 设备分辨率(pixel) PPI 3GS ...

  10. greeting-150

    拿到程序例行检查,可以看出程序是32位的程序 将程序放入ida中进入主函数查看 但是我们将程序运行一次后发现程序还运行了nao的程序 说明程序在中间还引用了nao函数,通过代码审计我们可以很直接的看到 ...