题目:求从s開始的递增序列(每次加1)。求出他们加和不小于D的那个最后的加数。

分析:数学题。分治。s + s+1 + ... + n = n*(n+1)/2 - s*(s-1)/2 = (n+s)*(n-s+1)/2。

直接二分答案就可以(二分范围0~10^8)。

说明:(⊙_⊙)。

#include <iostream>
#include <cstdlib> using namespace std; long long sum(long long s, long long n)
{
return (n-s+1LL)*(n+s)/2LL;
} long long bs(int S, long long D)
{
long long mid,l = 1LL,r = 100000000LL;
while (l < r) {
mid = l+(r-l)/2LL;
if (sum(S, mid) >= D)
r = mid;
else l = mid+1LL;
}
return r;
} int main()
{
long long s,D;
while (cin >> s >> D)
cout << bs(s, D) << endl; return 0;
}

UVa 10170 - The Hotel with Infinite Rooms的更多相关文章

  1. Problem H. Hotel in Ves Lagos

    Problem H. Hotel in Ves Lagos Input le: hotel.in Output le: hotel.out Time limit: 1 second Memory li ...

  2. 二维数组模拟实现酒店管理系统-java

    业务分析 1.需要一个房间类,包含房间的属性,比如房间编号.房间类型.是否占用. 2.需要一个旅馆类,旅馆有房间,提供的方法需要有 预订房间.打印房间信息.初始化房间.退房. 3.测试类,测试预订房间 ...

  3. 转载:Practical UML™: A Hands-On Introduction for Developers

    原文:http://edn.embarcadero.com/article/31863 By: Randy Miller Abstract: This tutorial provides a quic ...

  4. UVA 10627 - Infinite Race(数论)

    UVA 10627 - Infinite Race option=com_onlinejudge&Itemid=8&page=show_problem&category=516 ...

  5. ACM: Hotel 解题报告 - 线段树-区间合并

    Hotel Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description The ...

  6. HDU - Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  7. 【POJ3667】Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  8. UVa 102 - Ecological Bin Packing(规律,统计)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  9. poj 3667 Hotel(线段树,区间合并)

    Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...

随机推荐

  1. ECMAScript 6 proxies

    在ECMAScript 5里面,可以通过(writable 和 configurable)内部属性把属性设置为不可修改和不可删除的,可以通过(Object.preventExtensions() )让 ...

  2. JAVAscript学习笔记 jsDOM 第五节 (原创) 参考js使用表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. android 横竖屏切换不重走生命周期

    android在系统配置发生改变时,Activity会被重新创建,但是某些情况下我们希望系统配置改变时不会重新创建Activity,这个时候我们可以给Activity指定相对应的configChang ...

  4. 【机器学习】TensorFlow学习(一)

    感谢中国人民大学胡鹤老师,课讲得非常好~ 首先,何谓tensor?即高维向量,例如矩阵是二维,tensor是更广义意义上的n维向量(有type+shape) TensorFlow执行过程为定义图,其中 ...

  5. 通过geotools读写shp文件

    依赖jar包 读取shp public static void main(String[] path) { DbaseFileReader reader = null; try { reader = ...

  6. div内长串数字或字母不断行处理

    比如: <div>1111tryrt645645rt4554111112324353453454364</div> <div>qwewretrytuytuiyiuo ...

  7. nginx的5个特点

    nginx的5个特点(2017/11/16 白杨整理) 1.动静分离 Nginx是一种轻量级,高性能,多进程的Web服务器,非常适合作为静态资源的服务器使用,而动态的访问操作可以使用稳定的Apache ...

  8. [转载] 从Hadoop到Spark的架构实践

    转载自http://www.csdn.net/article/2015-06-08/2824889 http://www.zhihu.com/question/26568496 当下,Spark已经在 ...

  9. Node学习笔记 http

    node url querystring 第二个参数指定分隔符 也可以指定三个参数,效果和两个参数类似 不同于querystring,下面是querystringfy的用法 queryescape与e ...

  10. [转]如何监测谁用了SQL Server的Tempdb空间

    Tempdb 系统数据库是一个全局资源,供连接到 SQL Server 实例的所有用户使用.在现在的SQL Server里,其使用频率可能会超过用户的想象.如果Tempdb空间耗尽,许多操作将不能完成 ...