UVaLive 7500 Boxes and Balls (数学)
题意:给定 n 个球,每次从每篮子里拿出来一个放在一个新篮子里,并移除相同的,按球的个数进行排序,问你用最多几个球能完成循环。
析:数学问题,很容易发现前n项和就是最多的球数,所以我们只要找最大的n项就好了。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef unsigned long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0}; int main(){
int T; cin >> T;
LL x;
for(int kase = 1; kase <= T; ++kase){
cin >> x;
LL y = (LL)sqrt(2.0*x*1.0);
LL ans = y*(y-1)/2;
for(LL i = y-1; ; ++i){
if(i * (i+1) <= 2*x) ans = max(ans, i*(i+1)/2);
else break;
}
printf("Case #%d: ", kase);
cout << ans << endl;
}
return 0;
}
UVaLive 7500 Boxes and Balls (数学)的更多相关文章
- uvalive 7500 Boxes and Balls
https://vjudge.net/problem/UVALive-7500 题意: 找到规律之后发现给出一个数n,要求找到1 + 2i + ... + x <= n,找出1到x的和. 思路: ...
- UVALive 7500 Boxes and Balls 2015EC final 签到题 二分
分析题目后,得到要求的是最接近n的一个数,并且这个数字能写成1+2+3+....+x = ans这种形式. 要求的是最大的值. 这题就直接二分去做吧.二分出一个f(mid)<=n的最大值. 最后 ...
- 【CF884D】Boxes And Balls 哈夫曼树
[CF884D]Boxes And Balls 题意:有n个箱子和若干个球,球的颜色也是1-n,有ai个球颜色为i,一开始所有的球都在1号箱子里,你每次可以进行如下操作: 选择1个箱子,将里面所有的球 ...
- Educational Codeforces Round 31- D. Boxes And Balls
D. Boxes And Balls time limit per test2 seconds memory limit per test256 megabytes 题目链接:http://codef ...
- Boxes and Balls UVALive - 7500(练习赛爆零)
原因: 自身: 1.自己并没有考虑过精度所带来的问题. 2.一定要自己读题,独立思考,末被队友带偏(矛盾出真理). 3.加强自身基础,提高自身实力. 队伍: 1.队友缺乏独立思考,需要加强. 题目描述 ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- CodeForces-884D:Boxes And Balls(合并石子)
Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
随机推荐
- 进程描述符task_struct
1.进程状态 volatile long state; int exit_state; state成员的可能取值如下: #define TASK_RUNNING 0 #define TA ...
- Maven之 环境搭建
这几天开始了maven的学习,看了孔浩老师的视频(http://pan.baidu.com/s/1o7bg2h0),以及黄勇大牛的博客(http://my.oschina.net/huangyong/ ...
- hihoCoder #1176 : 欧拉路·一 (简单)
题意:给出n个岛,每个岛都有桥到达其他岛,且桥数可多可少(即使两岛有多桥),判断是否是欧拉路(即每条桥只能走一次,所有桥都能遍历1遍). 思路: 满足如下条件之一者即为欧拉路: 1.连通图,每个岛的度 ...
- 使用phantomjs生成网站快照
http://phantomjs.org/ 昨天(2013/08/12)在代码区看到一个生成站点快照的代码,看了半天才发现,作者仅仅贴出来业务代码,最核心的生成快照图片的代码反而没有给出来. 以前记得 ...
- In App Purchase翻译
一.In App Purchase概览 Store Kit代表App和App Store之间进行通信.程序将从App Store接收那些你想要提供的产品的信息,并将它们显示出来供用户购买.当用户需要购 ...
- Python定时调度--多任务同一时间开始跑 scheduler.enterabs
Event Priorities If more than one event is scheduled for the same time their priority values are use ...
- canvas小知识
清单 1. 绘制 canvas 矩形 function drawRect(){ var canvas = document.getElementById('canvas'); if (canvas.g ...
- 浅谈MySQL Replication(复制)基本原理
1.MySQL Replication复制进程MySQL的复制(replication)是一个异步的复制,从一个MySQL instace(称之为Master)复制到另一个MySQL instance ...
- shell脚本中一些特殊符号
在shell中常用的特殊符号罗列如下: # ; ;; . , / \\ 'string'| ! $ ${} $? $$ $* \"string\"* ** ...
- 利用COPYDATASTRUCT传递命令行参数给驻留内存的进程(SendMessage应用)
我们知道Window进程之间通过API的SendMessage方法传递消息.但是方法参数lParam是Long型,那么如果传递一个字符串(譬如命令行参数)应该怎么办呢,甚至一个对象.结构呢.VB的发送 ...