2 条题解

  • 1
    @ 2023-8-11 23:10:50

    啊首先呢,这道题非常困难,一般情况下仅凭自己的手指是写不出来的,还要用脚趾😄

    就是说,开个数组判断某个高度有没有箭就行.比如说读入气球高度,看看这只气球所在的高度有没有箭.如果有,让这只箭射爆气球,然后箭掉下去一个高度.如果没有,就射一支箭打掉这个气球就刑.非常的困难,建议瞎搞👍


    #include <iostream>
    using namespace std;
    int n,a[10000007],ans = 0;
    //a[n]判断高度n有没有箭
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0),cout.tie(0);
        //老样子关流加速
        cin >> n;
        for(int i = 1;i <= n;i ++)
        {
            int x;
            cin >> x;
            if(!a[x])//如果这个高度没有箭
            {
                ans ++;      //射出去一支箭
                a[x - 1] ++; //箭射掉气球后掉下来一个高度
            }
            else 
            {
                a[x - 1] ++;
                a[x] --;
                //箭掉下来一个高度
            }
        }
        cout << ans;
    }
    
    • 0
      @ 2023-8-9 0:18:16

      C++ :

      #include <bits/stdc++.h>
      using namespace std;
      int n, x, ans, cnt[1000005];
      int main() {
          cin >> n;
          while (n--) {
              cin >> x;
              if (cnt[x])
                  cnt[x]--;
              else
                  ans++;
              cnt[x - 1]++;
          }
          cout << ans << endl;
          return 0;
      }
      
      • 1

      信息

      ID
      472
      时间
      5000ms
      内存
      128MiB
      难度
      7
      标签
      递交数
      24
      已通过
      8
      上传者