zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    redis 持久化
    Linux 配置 FastDFS
    查询相关
    外键查询
    pycharm 使用git
    比较时间
    文件导入import
    切分,字符串转列表
    时间相关
    django 自带序列化组件效果
  • 原文地址:https://www.cnblogs.com/LyonLys/p/hdu_4476_Lyon.html
Copyright © 2011-2022 走看看