Acwing 第 85 场周赛

文章介绍了三道Acwing编程竞赛中的题目,包括死或生、最大价值和危险程度。对于死或生问题,通过比较两种状态的计数来决定结果。最大价值题解是通过贪心策略将最高价值的字母放在字符串末尾以最大化总价值。危险程度问题解决方法是找出所有不产生反应的物质序列以最大化试管的危险值。

Powered by:NEFU AB-IN

B站直播录像!

Link

Acwing 第 85 场周赛

  • A AcWing 4791. 死或生

    • 题意

    • 思路

      模拟即可

    • 代码

      #include <bits/stdc++.h>
      using namespace std;
      #define int long long
      #undef int
      
      #define SZ(X) ((int)(X).size())
      #define ALL(X) (X).begin(), (X).end()
      #define IOS                                                                                                            \
          ios::sync_with_stdio(false);                                                                                       \
          cin.tie(nullptr);                                                                                                  \
          cout.tie(nullptr)
      #define DEBUG(X) cout << #X << ": " << X << '\n'
      typedef pair<int, int> PII;
      
      const int N = 1e5 + 10, INF = 0x3f3f3f3f;
      
      int n, cnt11, cnt12, cnt21, cnt22;
      
      signed main()
      {
          IOS;
          cin >> n;
          for (int i = 1; i <= n; ++i)
          {
              int t, x, y;
              cin >> t >> x >> y;
              if (t == 1)
                  cnt11 += x, cnt12 += y;
              else
                  cnt21 += x, cnt22 += y;
          }
          if (cnt11 >= cnt12)
              cout << "LIVE\n";
          else
              cout << "DEAD\n";
      
          if (cnt21 >= cnt22)
              cout << "LIVE\n";
          else
              cout << "DEAD\n";
          return 0;
      }
      
  • B AcWing 4792. 最大价值

    • 题意

      已知,小写字母 a∼z的价值分别为 wa,wb,…,wz
      对于一个由小写字母构成的长度为 l的字符串 S=s1s2…sl,其价值为 ws1×1+ws2×2+…+wsl×l
      现在,给定一个由小写字母构成的字符串 S,请你在这个字符串中插入 k 个小写字母,要求最终得到的字符串的价值尽可能大。
      输出最大可能价值。

    • 思路

      贪心 (当时未证明),思路是将k个w最大的放在最后面即可

    • 代码

      /*
      * @Author: NEFU AB-IN
      * @Date: 2023-02-02 18:39:23
      * @FilePath: \Acwing\85cp\b\b.cpp
      * @LastEditTime: 2023-02-02 19:09:55
      */
      #include <bits/stdc++.h>
      using namespace std;
      #define int long long
      #undef int
      
      #define SZ(X) ((int)(X).size())
      #define ALL(X) (X).begin(), (X).end()
      #define IOS                                                                                                            \
          ios::sync_with_stdio(false);                                                                                       \
          cin.tie(nullptr);                                                                                                  \
          cout.tie(nullptr)
      #define DEBUG(X) cout << #X << ": " << X << '\n'
      typedef pair<int, int> PII;
      
      const int N = 1e5 + 10, INF = 0x3f3f3f3f;
      
      string s;
      int k, mx;
      unordered_map<char, int> mp;
      
      signed main()
      {
          IOS;
          cin >> s >> k;
          for (char i = 'a'; i <= 'z'; ++i)
          {
              int x;
              cin >> x;
              mp[i] = x;
              mx = max(mx, x);
          }
      
          int ans = 0;
          for (int i = 0; i < SZ(s); ++i)
          {
              ans += (i + 1) * mp[s[i]];
          }
          // DEBUG(ans);
          for (int i = SZ(s) + 1; i < SZ(s) + 1 + k; ++i)
          {
              ans += i * mx;
          }
      
          cout << ans;
          return 0;
      }
      
  • C AcWing 4793. 危险程度

    • 题意

      有 n种化学物质,编号 1∼n
      其中,有 m对物质之间会发生反应。
      现在,要将这些化学物质逐个倒入同一个试管之中,具体倒入顺序不限。
      我们需要计算一下试管的危险值。
      已知,空试管的危险值为 1,每倒入一种化学物质,如果该物质能够与之前倒入试管中的一种或多种物质发生反应,则试管的危险值将乘以 2
      请你计算并输出,通过合理安排所有化学物质的倒入顺序,能够得到的试管的最大危险值。

    • 思路

      思路:找所有的连通块,每个连通块的祖先节点放入试管时,试管是不乘2的,其余情况都乘2

    • 代码

      /*
      * @Author: NEFU AB-IN
      * @Date: 2023-02-02 18:39:23
      * @FilePath: \Acwing\85cp\b\b.cpp
      * @LastEditTime: 2023-02-02 19:09:55
      */
      #include <bits/stdc++.h>
      using namespace std;
      #define int long long
      #undef int
      
      #define SZ(X) ((int)(X).size())
      #define ALL(X) (X).begin(), (X).end()
      #define IOS                                                                                                            \
          ios::sync_with_stdio(false);                                                                                       \
          cin.tie(nullptr);                                                                                                  \
          cout.tie(nullptr)
      #define DEBUG(X) cout << #X << ": " << X << '\n'
      typedef pair<int, int> PII;
      
      const int N = 1e5 + 10, INF = 0x3f3f3f3f;
      
      string s;
      int k, mx;
      unordered_map<char, int> mp;
      
      signed main()
      {
          IOS;
          cin >> s >> k;
          for (char i = 'a'; i <= 'z'; ++i)
          {
              int x;
              cin >> x;
              mp[i] = x;
              mx = max(mx, x);
          }
      
          int ans = 0;
          for (int i = 0; i < SZ(s); ++i)
          {
              ans += (i + 1) * mp[s[i]];
          }
          // DEBUG(ans);
          for (int i = SZ(s) + 1; i < SZ(s) + 1 + k; ++i)
          {
              ans += i * mx;
          }
      
          cout << ans;
          return 0;
      }
      
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NEFU AB-IN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值