Problem - 4476

  题意是,给出若干绳子,对同一根绳子只能切割一次,求出最多能获得多少长度相同的绳子。

  代码中,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)的更多相关文章

  1. Cut the rope

    http://acm.nyist.net/JudgeOnline/problem.php?pid=651 描述We have a rope whose length is L. We will cut ...

  2. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. HDU 4655 Cut Pieces(数学分析题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给出n个石子,第i个石子可以染ai种颜色.对于每种颜色,比如颜色1221,我们称有3段.连 ...

  4. hdu 4655 Cut Pieces 找规律

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给你一组整数,代表每个木块所能涂成的颜色种数(编号1~ai),相邻的两块所能涂成的颜色如果是一 ...

  5. HDU 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...

  6. hdu 4762 Cut the Cake概率公式

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...

  7. 2013长春网赛1004 hdu 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...

  8. 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 ...

  9. HDU 4762 Cut the Cake(高精度)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. SQL Sever实验一 创建和删除数据库数据表

    一. 实验目的 1. 熟悉SQL    Server    2008    中SQL    Server    Management    Studio的环境 2. 了解SQL    Server   ...

  2. 由一道面试题引起的arguments的思考

    写一个按照下面方式调用都能正常工作的 sum 方法 console.log(sum(2,3)); // Outputs 5 console.log(sum(2)(3)); // Outputs 5从这 ...

  3. Android——<uses-sdk>

    语法(SYNTAX): <uses-sdk android:minSdkVersion="integer" android:targetSdkVersion="in ...

  4. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  5. request与response的乱码问题的总结及解决方法

    一. response的乱码问题: 1,使用   字节流  向页面输出中文: 不一定会出现乱码,因为中文字节数组默认是GBK,如果浏览器打开的默认编码也是GBK,就不会出现乱码,否则会乱码. 解决办法 ...

  6. OSGi教程:Framework Namespaces Specification

    此教程基于OSGi Core Release 7 OSGi命名空间规范 详细的教程上面的英文教程里面有详细说明. 我就记录一下自己看完之后的简单理解: OSGi的Namespace规范就是规定了你Ma ...

  7. bnd -buildpath指令的用法

    -buildpath的作用是为项目添加运行时依赖.这个依赖可以是workspace中的另一个项目或者是仓库中的另一个bundle. -buildpath指令只会在编译和构建时起作用,它从来不会被用来运 ...

  8. 廖雪峰Python总结2

    1.切片 L[0:3]表示,从索引0开始,直到索引3为止,但是不包括索引3.如果第一个索引是0,还可以省略L[:3] 倒数切片:L[-n:-1],-1是倒数第一个元素,L[-n:-1]不包括倒数第一个 ...

  9. SQLServer → 09:索引

    一.索引概念 用途 我们对数据查询及处理速度已成为衡量应用系统成败的标准,而采用索引来加快数据处理速度通常是最普遍采用的优化方法. 概念 索引是一个单独的,存储在磁盘上的数据结构,它们包含则对数据表里 ...

  10. VBA 生成带时间戳的随机数字

    Function GenPasswd(length, level) Dim allstr, substr, passwd As String allstr = "0123456789abcd ...