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. springboot整合logback集成elk实现日志的汇总、分析、统计和检索功能

    在Spring Boot当中,默认使用logback进行log操作.logback支持将日志数据通过提供IP地址.端口号,以Socket的方式远程发送.在Spring Boot中,通常使用logbac ...

  2. springmvc 后台实体类接受前端json字符串时,其中一个属性content 接受富文本内容时 标签<p>、<span> 这些标签丢失问题解决

    问题描述: 前端一个字段 <script id="editor" type="text/plain" name="content" s ...

  3. 微信小程序循环中点击一个元素,其他的元素不发生变化,类似点击一个循环中的语音,其他的不发生点击事件

    类似语音,因为都在一个数据内,所以点击第一个,所有的语音都变化,解决方法就是 把整个数据都获取下来,然后更改其中一个需要更改的值,然后再把整个数据都setdata回去,如果需要动画的话,wxml里面放 ...

  4. 【C】揭秘rand()函数;

    原文地址:http://www.cnblogs.com/ngnetboy/archive/2012/11/23/2784078.html 相信只要是程序猿都会知道rand()函数是用来取随机数的一个库 ...

  5. 0-java概述

    目录 Java发展历史 java规范 Java三大分支 Java SE学习路径 HelloWorld 1.Java发展历史 - Java出身于sun公司 - sun公司被Oracle公司收购 2.ja ...

  6. 012-PHP创建一个多维数组

    <?php $Cities = array( //二维数组array() "华北地区"=>array( "北京市", "天津市" ...

  7. js封装ajax

    //封装ajax function ajax(obj) { //创建xhr对象; var xhr = new XMLHttpRequest(); obj.method = obj.method.toU ...

  8. 04 MySQL数据类型

    MySQL支持的数据类型   1.数值类型:       a.整数类型    TINYINT 1字节 有符号(-128~127); 无符号(0~255) SMALLINT 2字节  有符号(-3276 ...

  9. [BJDCTF2020]Cookie is so stable

    0x00 知识点 Twig模板注入 链接: https://www.k0rz3n.com/2018/11/12/%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A ...

  10. UVA - 1451 Average (斜率优化)

    题意:由01组成的长度为n的子串,AT由0表示,GC由1表示,求一段长度大于等于L且GC率最高的子串的起始终止坐标,若GC率相同,取长度较小,若长度相同,取起始坐标最小. 分析: 1.一个子串(i+1 ...