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 ...
随机推荐
- linux一些配置的记录
ssh 登录设置主机的别名 这样不用写那么多东西了 在/etc/ssh/ 下的ssh_config 和 sshd_config 两个文件 前一个是配置客户端的配置文件 另一个是服务器端的配置文件 主要 ...
- day38 05-Spring的BeanFactory与ApplicationContext区别
ApplicationContext怎么知道它是一个工厂呢? BeanFactory也可以做刚才那些事情,只不过ApplicationContext对它有扩展.ApplicationContext间接 ...
- iview 中table列 一列显示多个数据(后台返回数组显示在列内)
一.首先出现的是比较复杂的一种情况(多个key) 1.首先页面显示效果如下 2.后台返回数据格式如下: 3.在iview中table的columns中的render函数: 4.具体代码 render: ...
- WPF DrawingVisual详解
在WPF中,如果需要绘制大量图形元素,并且对性能要求严苛的话,最好使用DrawingVisual,当然,你也可以选用 Path类和比Path类更轻量级的Geometry(几何形状)来实现你的需求,但是 ...
- Linux下安装zookeeper-3.4.13
转载至:https://yq.aliyun.com/articles/662422 1.zookeeper官网下载安装包http://mirrors.hust.edu.cn/apache/zookee ...
- npm run dev 和 npm run serve
1.ERR引发的思考 创建好的 vue 项目直接执行 vue run dev 报错?运行 vue run serve 就可以启动...如下 npm run dev npm ERR! missing s ...
- LintCode_68 二叉树后序遍历
题目 给出一棵二叉树,返回其节点值的后序遍历. 思路 后序比较麻烦 需要另外一个变量来记录当前节点入栈的次数 设计pair<TreeNode*, int> p; p.first 为二叉树节 ...
- R语言-组间差异的非参数检验
R语言-组间差异的非参数检验 7.5 组间差异的非参数检验 如果数据无法满足t检验或ANOVA的参数假设,可以转而使用非参数方法.举例来说,若结果变量在本质上就严重偏倚或呈现有序关系,那么你可能会希望 ...
- Directx教程(30) 如何保证渲染物体不会变形
原文:Directx教程(30) 如何保证渲染物体不会变形 在Directx11教程(6)中, 我们曾经实现过这个功能,但那时是在SystemClass中,处理WM_SIZE时候,重新调用m ...
- CF789D Mike and distribution
题目连接 一道人类智慧题.... 这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值 我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一 ...