UVa 10170 - The Hotel with Infinite Rooms
题目:求从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的更多相关文章
- 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 ...
- 二维数组模拟实现酒店管理系统-java
业务分析 1.需要一个房间类,包含房间的属性,比如房间编号.房间类型.是否占用. 2.需要一个旅馆类,旅馆有房间,提供的方法需要有 预订房间.打印房间信息.初始化房间.退房. 3.测试类,测试预订房间 ...
- 转载:Practical UML™: A Hands-On Introduction for Developers
原文:http://edn.embarcadero.com/article/31863 By: Randy Miller Abstract: This tutorial provides a quic ...
- UVA 10627 - Infinite Race(数论)
UVA 10627 - Infinite Race option=com_onlinejudge&Itemid=8&page=show_problem&category=516 ...
- ACM: Hotel 解题报告 - 线段树-区间合并
Hotel Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description The ...
- HDU - Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- 【POJ3667】Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- UVa 102 - Ecological Bin Packing(规律,统计)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- poj 3667 Hotel(线段树,区间合并)
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...
随机推荐
- vsftpd安装及虚拟用户配置
服务器环境:CentOS6.9 Linux 2.6.32-696.10.1.el6.x86_64 安装vsftpd.db4.db4-utils # yum -y install vsftpd db4 ...
- HTML学习笔记 CSS文本及字体及连接及列表(a标签使用及缩进) 案例 第七节 (原创)参考使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 532. K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in t ...
- Mybatis按顺序获取数据
sql语句select * from producttg where hospitalcode in (1,2,3) 获取到的数据并不是按照条件1,2,3的顺序排列,如果要成下面形式(mybatis ...
- SQL Server 通过SQL脚本启动Broker并设置兼容性
SQL Server数据库中通过SQL启用Broker 并建立相关队列和服务 兼容代码使其可以在2000库中执行不报错 针对的是2008版本, 如果是其他版本可以改相关版本号和兼容性标记 /***** ...
- MarkdownPad2使用高亮插件
MarkdownPad 2有插入代码块的功能,但样式却不尽人意,但又不想换个编辑器,找了挺多相关资料,最后在MarkdownPad 2集成prettify高亮插件. 如下相关资料: [HTML] Pr ...
- java SE 基础概念梳理(一)
(一)First 摘要:Java概述.Java开发环境搭建.程序开发流程 Java概述 Java的应用 开发QQ.迅雷程序(桌面应用软件)开发淘宝.京东(互联网应用软件) Java的擅长 互联网: ...
- java对象拷贝和复制
参考文章:http://blog.csdn.net/XIAXIA__/article/details/41652057 解决问题:深拷贝.浅拷贝 和普通的对象赋值有什么区别? 对象复制 例如:Pers ...
- Ansible(一) 配置安装
puppet ruby开发 salt python开发,有客户端,使用Rabbitmq消息队列,支持并发,在机器数量很多时效果比ansible好. ansible python开发, 没有客户端,基于 ...
- 【二十】mysqli基于面向过程与面向对象的编程
面向过程的方式 musqli扩展库操作mysql数据库步骤: 1.获取连接并选择数据库 //语法 mysqli_connect(host,username,password,dbname,port,s ...