• BZOJ1110 [POI2007]砝码Odw


    话说这题。。。是贪心、、、

    Orz JCVB(虽然这是hzwer的blog。。。Jcvb的不知道则么回事打不开。。。囧)

     1 /**************************************************************
     2     Problem: 1110
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:984 ms
     7     Memory:1588 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <cctype>
    12 #include <algorithm>
    13  
    14 using namespace std;
    15 const int N = 100005;
    16 const int M = 55;
    17  
    18 int n, m, tot;
    19 int a[N], b[N];
    20 int c[M], cnt[M];
    21  
    22 inline int read() {
    23     int x = 0, sgn = 1;
    24     char ch = getchar();
    25     while (!isdigit(ch)) {
    26         if (ch == '-') sgn = -1;
    27         ch = getchar();
    28     }
    29     while (isdigit(ch)) {
    30         x = x * 10 + ch - '0';
    31         ch = getchar();
    32     }
    33     return sgn * x;
    34 }
    35  
    36  
    37 bool check(int now) {
    38     int i;
    39     for (i = now + 1; i <= tot; ++i)
    40         if (cnt[i]) {
    41             cnt[now] += c[i] / c[now];
    42             --cnt[i];
    43             return 1;
    44         }
    45     return 0;
    46 }
    47  
    48 int main() {
    49     int i, j, now;
    50     n = read(), m = read();
    51     for (i = 1; i <= n; ++i)
    52         a[i] = read();
    53     for (i = 1; i <= m; ++i)
    54         b[i] = read();
    55     sort(b + 1, b + m + 1);
    56     for (i = 1; i <= m; ++i)
    57         if (b[i] != b[i - 1]) c[++tot] = b[i];
    58     for (i = 1; i <= n; ++i)
    59         for (j = tot; j; --j)
    60             while (c[j] <= a[i])
    61                 a[i] -= c[j], ++cnt[j];
    62     now = 1;
    63     for (i = 1; i <= m; ++i) {
    64         while (b[i] > c[now]) ++now;
    65         if (cnt[now]) --cnt[now];
    66         else if (check(now)) --cnt[now];
    67         else {
    68             printf("%d
    ", i - 1);
    69             return 0;
    70         }
    71         if (i == m) printf("%d
    ", m);
    72     }
    73     return 0;
    74 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    问题——虚拟机连接,查本地DNS,查软件位置,payload生成,检测注册表变化
    nmap命令解释
    SMB扫描,SMTP扫描
    操作系统识别,SNMP扫描
    服务扫描——查询banner信息,服务识别
    nmap之扫描端口(附加hping3隐藏扫描)
    scapy简单用法——四层发现
    转载 界面组装器模式
    设计模式=外观模式
    如何进行自动化测试和手工测试
  • 原文地址:https://www.cnblogs.com/rausen/p/4101693.html
Copyright © 2020-2023  润新知