UVALive 7500 Boxes and Balls(模拟,二分)
来源:互联网 发布:nginx 访问目录 403 编辑:程序博客网 时间:2024/05/17 02:52
题目地址:点击打开链接
题意:你手里有N个球,现在需要用你手里尽可能多的球使得这个游戏经过多次游戏后形成一种恒定状态
思路:最后形成一种恒定状态的情况是每个盒子里放得球数一定是个连续的序列,1, 1 2, 1 2 3, 1 2 3 4....因为只有这样从任意一个框里取出一个球放到另一框后再排序,得到的还是原来的序列。
所以知道这后只要求比n小的最大前n项和即可,可以用二分来找。
代码:
#include<iostream>#include<cstdio>using namespace std;typedef long long ll;int main(void){ int t, ca = 1; cin >> t; while(t--) { ll n, l = 0, r = 2e9, ans; scanf("%lld", &n); while(l <= r) { ll mid = (l+r)/2; ll sum = (1+mid)*mid/2; if(sum <= n) ans = sum, l = mid+1; else r = mid-1; } printf("Case #%d: %lld\n", ca++, ans); } return 0;}
0 0
- UVALive 7500 Boxes and Balls(模拟,二分)
- UVALive 7500 Boxes and Balls (二分)
- UVALive 7500 Boxes and Balls
- UVALive-7500-Boxes and Balls
- Boxes and Balls UVALive
- Boxes and Balls UVALive
- hdu 5810 Balls and Boxes (数学)
- hdu5810 Balls and Boxes(数学)
- HDU 5810 Balls and Boxes(概率)
- HHU Boxes and Balls(找规律)
- Balls and Boxes
- Boxes and Balls
- HDU5810 Balls and Boxes
- HDU5810-Balls and Boxes
- Balls and Boxes CodeForces
- Boxes And Balls CodeForces
- Codeforces Round #158 (Div. 2)C. Balls and Boxes(模拟)
- UVALive 6694 - Toy Boxes(思维+二分)
- android studio 引入so文件 出现找不到so文件的解决办法
- Queueing at Bank
- 如何让一段代码tomcat启动就运行
- AJAX入门基础
- 常用的git命令和它与github的那些事
- UVALive 7500 Boxes and Balls(模拟,二分)
- 【9605】智力大冲浪
- 安装Python及爬虫入门介绍
- nginx 中 相关配置信息
- 一步一步学调试——gdb命令小结
- 在 Sublime Text 3 中配置编译和运行 Java 程序
- zabbix监控memcache状态
- msysgit和github 结合使用
- spring 的"零配置"支持