zoukankan      html  css  js  c++  java
  • 2793 [Poi2012]Vouchers

    我们直接模拟就可以了= =

    now[x]表示x的倍数已经取到x * i了,于是每次读入x,直接向上枚举x个没取过的数即可。

     1 /**************************************************************
     2     Problem: 2793
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:5296 ms
     7     Memory:14476 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <algorithm>
    12  
    13 using namespace std;
    14 typedef long long ll;
    15 const int N = 1000005;
    16  
    17 int n, m, mx;
    18 int now[N];
    19 ll tot, ans[N], cnt;
    20 bool f[N], vis[N];
    21  
    22 inline int read() {
    23     int x = 0, sgn = 1;
    24     char ch = getchar();
    25     while (ch < '0' || '9' < ch) {
    26         if (ch == '-') sgn = -1;
    27         ch = getchar();
    28     }
    29     while ('0' <= ch && ch <= '9') {
    30         x = x * 10 + ch - '0';
    31         ch = getchar();
    32     }
    33     return sgn * x;
    34 }
    35  
    36 int main() {
    37     int i, x, t, C;
    38     for (m = read(), i = 1; i <= m; ++i) {
    39         x = read();
    40         f[x] = 1, mx = max(mx, x);
    41     }
    42      
    43     n = read();
    44     while (n--) {
    45         x = t = read();
    46         for (i = now[x] + x, C = 0; i <= mx; i += x) {
    47             if (!vis[i]) {
    48                 ++cnt, --t, vis[i] = 1;
    49                 if (f[i]) ans[++tot] = cnt;
    50                 if (++C == x) break;
    51             }
    52             now[x] = i;
    53         }
    54         cnt += t;
    55     }
    56     printf("%lld
    ", tot);
    57     for (i = 1; i <= tot; ++i)
    58         printf("%lld
    ", ans[i]);
    59 }
    View Code

    (p.s. 没有的搞懂,一开始各种WA,把ans数组改成long long就AC了?蒟蒻跪求大神求教)

    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    GET POST区别
    http1.0 1.1 2.0区别
    分布式系统理论之Quorum机制
    MySQL解析过程、执行过程
    redis常见问题和解决方案
    Windows下安装Linux虚拟机的用途和好处
    ping,telnet,ssh命令的理解
    强化学习入门 第五讲 值函数逼近
    强化学习入门第四讲 时间差分方法
    强化学习基础 第三讲 蒙特卡罗方法
  • 原文地址:https://www.cnblogs.com/rausen/p/4130050.html
Copyright © 2011-2022 走看看