• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LyonLys
愿意在角落唱沙哑的歌 再大声也都是给你 请用心听 不要说话 Contact me via E-mail: lyon.lys@gmail.com
博客园    首页    新随笔    联系   管理    订阅  订阅

hdu 4476 Cut the rope (2-pointer && simulation)

Problem - 4476

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

  代码中,s是最大切割长度,而当前切割长度为t/2.

代码如下:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 
 6 using namespace std;
 7 
 8 const int N = 111111;
 9 int cnt[N];
10 
11 int main() {
12     int T, n;
13     cin >> T;
14     while (T-- && cin >> n) {
15         memset(cnt, 0, sizeof(cnt));
16         for (int i = 0, x; i < n; i++) {
17             scanf("%d", &x);
18             cnt[x]++;
19         }
20         int s = 1, t = 1, mx = 0;
21         while (s < N) {
22             while (t < N && t <= (s << 1)) {
23                 mx = max(mx, cnt[t] + n);
24                 t++;
25             }
26             n -= cnt[s++];
27         }
28         cout << mx << endl;
29     }
30     return 0;
31 }
View Code

 

——written by Lyon

posted @ 2013-07-04 02:18  LyonLys  阅读(239)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3