The 2022 ICPC Asia Regionals Online Contest (I)

2022 ACM-ICPC 网络赛(1) 个人题解 更新至5题 - 知乎

 H. Step Debugging

有一个自己写的语言,由固定的语法。问library执行了多少次。

实际上,我们可以理解为对下面的字符串进行求值

(((1+1+1)∗3)∗3+1)∗12


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 20220911;

string s;
ll sum, t, a, b;
deque<ll> q;

int main()
{
    while (cin >> s)
    {
        if (s == "fin")
            break;
        else
            getchar();
        if (s == "repeat")
            q.push_back(-1);
        else if (s == "library")
            q.push_back(1ll);
        else if (s == "for")
        {
            cin>>a;
            getchar();
            sum = 0;
            while (!q.empty())
            {
                b = q.back();
                if (b != -1)
                    sum = ((sum % mod) + (b % mod)) % mod, q.pop_back();
                else if (b == -1)
                {
                    q.pop_back();
                    t = (sum % mod) * (a % mod) % mod;
                    q.push_back(t);
                    break;
                }
            }
        }
    }
    sum = 0;
    while (!q.empty())
    {
        b = q.back();
        sum = ((sum % mod) + (b%mod)) % mod;
        q.pop_back();
    }
    cout << sum << endl;
    return 0;
}

D Find the Number

题解:一共 1e9 个数,但是满足描述中严格限制的只有 5e5 个数。

一共30位,暴搜+剪枝完全可以求出所有满足的数。所有数预处理出来。

后面对于每个询问,找到第一个大于等于左端点的满足的数,判断是否在区间中。

ICPC 2022网络赛(1) - D Find the Number(暴搜预处理)_小酒窝.的博客-CSDN博客

加了点注释方便理解

#include<bits/stdc++.h>
using namespace std;
#define int long long 
//csdn

const int N = 2e6 + 10;
int a[N], sum;
vector<int> v;//存放的就是那些好的数
void dfs(int u)
{
    if (u > 30)
    {
        if (sum)
            return;
        int x, res = 0;
        for (int i = 1; i <= 30; i++)
        {
            if (i == 1)
                x = 1;
            else
                x *= 2;
            if (a[i])
                res += x;
        }
        v.push_back(res);
        return;
    }
    if (sum)
    {
        sum--;
        a[u] = 1;
        dfs(u + 1);
        sum++;
    }
    a[u] = 0;
    dfs(u + 1);
}

signed main()
{
    for (int i = 1; i <= 16; i++)//后缀0的个数
    {
        for (int j = 1; j <= i; j++)
            a[j] = 0;
        a[i + 1] = 1;
        sum = i - 1;//0~15 根据后缀0还有多少个1
        dfs(i + 2);//3~18
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int t;
    int cnt  = 0;
    for(auto i : v)
    {
        cnt ++;
        cout<<i<<endl;
        if(cnt >= 50) break;
    }
    cin >> t;
    while (t--)
    {
        int l, r;
        cin >> l >> r;
        auto it = lower_bound(v.begin(), v.end(), l);
        if (it == v.end())
            cout << -1;
        else
        {
            int x = *it;
            if (x > r)
                cout << -1;
            else
                cout << x;
        }
        if (t)
            cout << endl;
    }
    return 0;
}

ICPC 网络赛 D 的几种枚举方式 - 知乎

知乎上这个解法我还没看懂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值