cf1498D. Bananas in a Microwave(暴力,背包,优化)

转载

题目链接:https://codeforces.ml/contest/1498/problem/D

题意略:近来博客写的是越来越草率了。

总结:

1.小数弄成整数好操作一些

2.很容易想到时间复杂度n*m*m的做法。挺明显是需要n*m的做法。

m~0:如果之前已经有值了,那就一定是操作过了的(或是新操作,但是使用了机会的)。立即跳出循环

所以复杂度期在O(n*m)。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 10;
const double eps = 1e-8;
void read(int &x) {
    int res = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        res = (res << 3) + (res << 1) + (c - '0'), c = getchar();
    x = res * f;
}
void OUT(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) OUT(x / 10);
    putchar(x % 10 + '0');
}
void print(int a, char c) { OUT(a), putchar(c); }

int n, m;
int dp[maxn];
int a[maxn], b[maxn], c[maxn];

signed main() {
    read(n), read(m);
    for (int i = 1; i <= m; i++) dp[i] = -1;
    for (int i = 1; i <= n; i++) read(a[i]), read(b[i]), read(c[i]);
    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= 0; j--) {
            if (dp[j] == -1) continue;
            if (j == 0 && a[i] == 2) continue;
            int x = j;
            for (int tt = 1; tt <= c[i]; tt++) {
                if (a[i] == 1)
                    x = x + (b[i] + 99999) / 100000;
                else
                    x = (x * b[i] + 99999) / 100000;
                if (x > m) break;
                if (dp[x] != -1) break;
                dp[x] = i;
            }
        }
    }
    for (int i = 1; i <= m; i++) print(dp[i], ' ');
    puts("");
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值