Time Limit: 2MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Status

Description

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 - TN). The problem is to compute T_optim, 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 T_optim are integer numbers.

Input

Each data set corresponds to an instance of the problem above and contains two integral numbers – N and C – with values in the range from 0 to 10 9. The input data are separated by white spaces, are correct, and terminate with an end of file.

Output

For each data set the program computes the value of T_optim according to the problem instance that corresponds to the data set. The result is printed on the standard output from the beginning of a line. There must be no empty lines on the output.

Sample Input

1 0
0 1
4 3
2 8
3 27
25 1000000000

Sample Output

0
0
0
2
4
20000000

求一个一元二次方程取极值时x的值。-b/(2*a)。。。

因为程序里面除法可能消掉了一部分小数,所以还要判断x+1时的情况,比较一下再输出。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout); long long n,c;
while(scanf("%lld%lld",&n,&c)!=EOF)
{
if(n==0)
{
cout<<0<<endl;
continue;
}
else
{
long long x=c/(2*n);
long long y=x+1;//一开始竟写成了减1。。。
cout<<(x*(c-n*x)<y*(c-n*y)?y:x)<<endl;
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3911:Internet Service Providers的更多相关文章

  1. 1275 - Internet Service Providers

    1275 - Internet Service Providers    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory L ...

  2. 自定义Data Service Providers

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

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

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

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

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

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

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

  6. Angular:ViewProviders和Providers的区别

    在Angular中使用依赖注入(DI)的时候,我们一般会使用providers.其实要做同样的事我们还有另外一个选择:viewProviders. viewProviders允许我们定义只对组件的vi ...

  7. SSRS2:Reporting Service 配置Service Account

    1,Service Account SSRS以一个Service方式实现,有三部分组成:Web Service,Report Manager和一个后台的进程,这个Service运行的账号就是Servi ...

  8. Android总结篇系列:Android Service

    Service通常总是称之为“后台服务”,其中“后台”一词是相对于前台而言的,具体是指其本身的运行并不依赖于用户可视的UI界面,因此,从实际业务需求上来理解,Service的适用场景应该具备以下条件: ...

  9. WCF分布式开发必备知识(3):Web Service 使用

    参考地址:http://www.cnblogs.com/zhili/p/WebService.html 一.WebService概述 SOAP.WSDL.UDDISOAP(Simple Object ...

随机推荐

  1. 题目:给定一数组 例如:a = [1,2,3,5,2,1] 现用户提供一个数字 请返回用户所提供的数字的所有下标

    def test(ary): ds = {} for i in range(len(ary)): if ds.get(ary[i]): ds[ary[i]].append(i) else: ds[ar ...

  2. Tcp 3次握手 4次挥手

    Tcp 3次握手 4次挥手 标签(空格分隔): Java基础 报文介绍: SYN(synchronous建立联机) ACK(acknowledgement 确认) FIN(finish结束) PSH( ...

  3. 006-PHP检测是否为整数

    <?php function checkInteger($Number) { if ($Number > 1) { /* 整数减1仍然是整数 */ return (checkInteger ...

  4. leetcode1162 As Far from Land as Possible

    """ Given an N x N grid containing only values and , represents water and represents ...

  5. linux 查看运行进程详细信息

    Linux在启动一个进程时,系统会在/proc下创建一个以PID命名的文件夹,在该文件夹下会有我们的进程的信息 通过ll或ls –l命令即可查看. ll /proc/PID cwd符号链接的是进程运行 ...

  6. NO7 利用三剑客awk-grep-sed-head-tail等7种方法实践

    ·seq   sequence  #序列·sed   stream editor  #(三剑客老二)流编辑器.实现对文件的增删改替换查.        -n #取消默认输出.sed -n '20,30 ...

  7. 使用 mtd-utils 烧写Arm Linux 系统各个部分

    有关博客:<Arm-Linux 移植 mtd-utils 1.x>.<mtd-utils 的 使用> 背景: 作为一项技术储备,可用于增强系统可维护性. 要求: 要求主板以mt ...

  8. K最邻近算法(下)

    import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_blobs from skle ...

  9. PHP笔记02

    PHP数组 能够在一个变量存储多个值 取值用下标,下标从0开始计算 好处:在处理物品清单等大量相同属性的变量内容时可以集中存取 <?php $arr=array("like" ...

  10. 吴裕雄--天生自然C++语言学习笔记:C++ 多线程

    多线程是多任务处理的一种特殊形式,多任务处理允许让电脑同时运行两个或两个以上的程序.一般情况下,两种类型的多任务处理:基于进程和基于线程. 基于进程的多任务处理是程序的并发执行. 基于线程的多任务处理 ...