hdu 4476 Cut the rope (2-pointer && simulation)
题意是,给出若干绳子,对同一根绳子只能切割一次,求出最多能获得多少长度相同的绳子。
代码中,s是最大切割长度,而当前切割长度为t/2.
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N = ;
int cnt[N]; int main() {
int T, n;
cin >> T;
while (T-- && cin >> n) {
memset(cnt, , sizeof(cnt));
for (int i = , x; i < n; i++) {
scanf("%d", &x);
cnt[x]++;
}
int s = , t = , mx = ;
while (s < N) {
while (t < N && t <= (s << )) {
mx = max(mx, cnt[t] + n);
t++;
}
n -= cnt[s++];
}
cout << mx << endl;
}
return ;
}
——written by Lyon
hdu 4476 Cut the rope (2-pointer && simulation)的更多相关文章
- Cut the rope
http://acm.nyist.net/JudgeOnline/problem.php?pid=651 描述We have a rope whose length is L. We will cut ...
- HDU 4762 Cut the Cake(公式)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4655 Cut Pieces(数学分析题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给出n个石子,第i个石子可以染ai种颜色.对于每种颜色,比如颜色1221,我们称有3段.连 ...
- hdu 4655 Cut Pieces 找规律
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给你一组整数,代表每个木块所能涂成的颜色种数(编号1~ai),相邻的两块所能涂成的颜色如果是一 ...
- HDU 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
- 2013长春网赛1004 hdu 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake(高精度)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- 组合数取模(lucas定理+CRT合并)(AC)
#include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inlin ...
- OSGi教程:Resource API Specification
此教程基于OSGi Core Release 7 OSGi Resource API规范 详细内容上面英文教程有详细解答 下面主要是一些个人见解,若有不当之处,欢迎指出: Resource:就是能够被 ...
- Permutations 全排列 回溯
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- 【软件安装】Linux下安装OpenSSL
安装环境: 操作系统:Ubuntu14.04 OpenSLL Version:openssl-1.0.2n.tar.gz(1.0.2版本为稳定版本,1.1.0为开发版本) OpenSLL下载地址为:h ...
- height自适应
如果子元素没有设置 float 属性啥的,父元素就是自动适应子元素宽高的. 子元素如果全是浮动属性(float),那么父元素就没有高度. 除非,你在子元素最后加一个清除浮动( <div styl ...
- More Effective C++: 03异常
C++的异常机制使得程序付出某些代价:资源泄漏的可能性增加了:写出具有你希望的行为的构造函数与析构函数变得更加困难:执行程序和库程序尺寸增加了,同时运行速度降低了等等. 但是为什么使用异常呢?C程序使 ...
- js cookies 的写入、读取、删除
//写cookies //escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串.function setCookie(name,value) { var Days ...
- closest和parents方法区别
今天第一次看到closest方法,以前也从来没用过. 该方法从元素本身开始往上查找,返回最近的匹配的祖先元素. 1.closest查找开始于自身,parents开始于元素父级 2.closest向上查 ...
- Add Binary字符数字相加,字符串合成
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- 【Leetcode链表】旋转链表(61)
题目 给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: 1->2->3->4->5->NULL, k = 2 输出: ...