• VP Atcoder Beginner Contest 265


    VP Atcoder Beginner Contest 265

    Problem A

    题意:有 n n n 个苹果,你可以 x x x 元买一个,也可以 y y y 元买三个,问你最少话多少钱恰好买下这些苹果。

    思路:暴力枚举买的个数即可。

    #include 
    
    using namespace std;
    
    signed main() {
      int x, y, n, mi = 1e9;
      cin >> x >> y >> n;
      for (int i = 0; i <= 100; i ++) {
        int si = i;
        int sj = n - i;
        if (sj >= 0 && sj % 3 == 0) {
          int j = sj / 3;
          mi = min(i * x + j * y, mi);
        }
      }
      cout << mi << '\n';
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    Problem B

    题意:有 n n n 个洞穴,第 i i i 个洞穴到第 i + 1 i+1 i+1 个洞穴需要花费 a i a_i ai 分钟。初始时间限制为 T T T,有 m m m 个奖励洞穴,进入这个洞穴 x i x_i xi T T T 增加 y i y_i yi。是否可以在时间限制内从 1 1 1 到达 n n n 号洞穴?

    思路:暴力模拟即可。坑比较多。

    #include 
    #define int long long
    
    using namespace std;
    
    const int N = 1e6 + 10;
    int a[N], b[N];
    
    signed main() {
      int n, m, t;
      cin >> n >> m >> t;
      for (int i = 1; i < n; i ++)
        cin >> a[i];
      while (m --) {
        int x, y;
        cin >> x >> y;
        b[x] += y;
      }
      for (int i = 1; i < n; i ++) {
        t -= a[i];
        if (t <= 0) {
          cout << "No\n";
          return 0;
        }
        t += b[i + 1];
      }
      cout << "Yes\n";
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    Problem C

    题意:

    给你一个正方形网格, ( i , j ) (i,j) (i,j) 位置上有一个字符:

    如果字符为 U 向上走。
    如果字符为 D 向下走。
    如果字符为 L 向左走。
    如果字符为 R 向右走。

    一开始你在 ( 1 , 1 ) (1,1) (1,1)。如果走的时候出了界,那么输出最后一次在棋盘里的坐标;如果永远无法走完输出 − 1 -1 1

    题解:暴力枚举即可。无法走完就是死循环,开一个标记数组记录所有走过的坐标即可。

    #include 
    #define int long long
    
    using namespace std;
    
    char s[555][555];
    
    void print(int x, int y) {
      cout << x << ' ' << y << '\n';
      exit(0);
    }
    
    signed main() {
      int h, w;
      cin >> h >> w;
      for (int i = 1; i <= h; i ++)
        cin >> (s[i] + 1);
      set <pair <int, int> > se;
      int x = 1, y = 1;
      while (true) {
        if (s[x][y] == 'U') {
          if (x > 1)
            x --;
          else
            print(x, y);
        }
        else if (s[x][y] == 'D') {
          if (x < h)
            x ++;
          else
            print(x, y);
        }
        else if (s[x][y] == 'L') {
          if (y > 1)
            y --;
          else
            print(x, y);
        }
        else if (s[x][y] == 'R') {
          if (y < w)
            y ++;
          else
            print(x, y);
        }
        else {
          cout << "-1\n";
          return 0;
        }
        if (se.count(make_pair(x, y))) {
          cout << "-1\n";
          return 0;
        }
        se.insert(make_pair(x, y));
      }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    Problem D

    题意:给你一个长度为 n n n 的序列,问你是否存在四元组 ( a , b , c , d ) (a,b,c,d) (a,b,c,d) 满足 ∑ i = a b − 1 = P \sum_{i=a}^{b-1}=P i=ab1=P ∑ i = b c − 1 = Q \sum_{i=b}^{c-1}=Q i=bc1=Q ∑ i = c d − 1 = R \sum_{i=c}^{d-1}=R i=cd1=R。如果有输出 Yes,否则输出 No。注意数组下标从 0 0 0 开始。

    思路1:前缀和套三个二分查找,时间复杂度 O ( n × log ⁡ n ) O(n\times \log n) O(n×logn)。没调出来。

    #include 
    #define int __int128
    
    using namespace std;
    
    const int N = 2e6 + 10;
    int a[N];
    __int128 s[N];
    set <pair <int, char> > se[N];
    const int zlt = 1e18;
    
    int read(){
    	int x=0,flag=0;
    	char a=getchar();
    	while(a>'9'||a<'0'){
    		if(a=='-')flag=1;
    		a=getchar();
    	}
    	while(a>='0'&&a<='9'){
    		x=x*10+a-'0';
    		a=getchar();
    	}
    	return flag?-x:x;
    }
    void write(int x){
    	if(x<0){
    		putchar('-');
    		x=-x;
    	}
    	if(x>9){
    		write(x/10);
    	}
    	putchar(x%10+'0');
    }
    
    signed main() {
      int n, p, q, rr;
      n = read();
      p = read();
      q = read();
      rr = read();
      int id = 0;
      for (int i = 0; i < n; i ++) {
        a[i] = read();
        if (!i) {
          s[i] = a[i];
        } else {
          s[i] = s[i - 1] + a[i];
          int l = id, r = i;
          int best = -1;
          while (l <= r) {
            int mid = l + r >> 1;
            __int128 qz = mid - 1;
            if (qz < 0)
              qz = 0;
            else
              qz = s[qz];
            if (s[i] - qz == p) {
              best = mid;
              break;
            }
            else if (s[i] - qz > p)
              l = mid + 1;
            else
              r = mid - 1;
          }
          if (best != -1)
            se[i].insert(make_pair(best - 1, 'P'));
          l = id, r = i;
          best = -1;
          while (l <= r) {
            int mid = l + r >> 1;
            __int128 qz = mid - 1;
            if (qz < 0)
              qz = 0;
            else
              qz = s[qz];
            if (s[i] - qz == q) {
              best = mid;
              break;
            }
            else if (s[i] - qz > q)
              l = mid + 1;
            else
              r = mid - 1;
          }
          if (best != -1)
            se[i].insert(make_pair(best - 1, 'Q'));
          l = id, r = i;
          best = -1;
          while (l <= r) {
            int mid = l + r >> 1;
            __int128 qz = mid - 1;
            if (qz < 0)
              qz = 0;
            else
              qz = s[qz];
            if (s[i] - qz == rr) {
              best = mid;
              break;
            }
            else if (s[i] - qz > rr)
              l = mid + 1;
            else
              r = mid - 1;
          }
          if (best != -1)
            se[i].insert(make_pair(best - 1, 'R'));
        }
      }
      for (int i = 1; i < n; i ++) {
        for (auto &[u, v] : se[i]) {
          if (v == 'R' && u != -1) {
            for (auto &[u1, v1] : se[u]) {
              if (v1 == 'Q' && u1 != -1) {
                for (auto &[u2, v2] : se[u1]) {
                  if (v2 == 'P') {
                    cout << "Yes\n";
                    return 0;
                  }
                }
              }
            }
          }
        }
      }
      cout << "No\n";
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129

    思路 2 2 2:用一个 set 记录前缀和,然后累加即可。

    #include 
    #define int long long
    
    using namespace std;
    
    int a[2323233];
    
    signed main() {
      int n, p, q, r;
      cin >> n >> p >> q >> r;
      int sum = 0;
      set <int> se;
      se.insert(0);
      for (int i = 1; i <= n; i ++) {
        int x;
        cin >> x;
        sum += x;
        a[i] = sum;
        se.insert(sum);
      }
      for (int i = 0, x = a[0]; i <= n; i ++, x = a[i])
        if (se.count(x) && se.count(x + p) && se.count(x + p + q) && se.count(x + p + q + r)) {
          cout << "Yes\n";
          return 0;
        }
      cout << "No\n";
      return 0;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    2022-08-27 10:02:22 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 400 557 Byte 152 ms 14528 KB Detail
    2022-08-27 10:01:31 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 540 Byte 151 ms 14508 KB Detail
    2022-08-27 09:57:39 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 540 Byte 156 ms 14592 KB Detail
    2022-08-27 09:56:12 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 538 Byte 113 ms 14536 KB Detail
    2022-08-27 09:35:23 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2578 Byte 164 ms 144816 KB Detail
    2022-08-27 09:32:05 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2227 Byte 194 ms 135124 KB Detail
    2022-08-27 09:29:32 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2249 Byte 181 ms 133388 KB Detail
    2022-08-27 09:27:47 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2254 Byte 197 ms 135064 KB Detail
    2022-08-27 09:26:33 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2248 Byte 189 ms 133548 KB Detail
    2022-08-27 09:24:44 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2259 Byte 184 ms 133432 KB Detail
    2022-08-27 09:07:50 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 1990 Byte 181 ms 133516 KB Detail
    2022-08-27 09:03:57 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 1982 Byte 181 ms 133408 KB Detail
    2022-08-27 09:02:46 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 1994 Byte 186 ms 133388 KB Detail
    2022-08-27 08:58:06 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2169 Byte 182 ms 133392 KB Detail
    2022-08-27 08:55:46 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2161 Byte 260 ms 133256 KB Detail
    2022-08-27 08:51:33 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2161 Byte 181 ms 133588 KB Detail
    2022-08-27 08:42:56 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2138 Byte 265 ms 133160 KB Detail
    2022-08-27 08:42:02 D - Iroha and Haiku (New ABC Edition) ****** C++ (GCC 9.2.1) 0 2101 Byte 215 ms 48860 KB Detail

  • 相关阅读:
    .NET 如何阻止线程执行上下文的传递
    【沐风老师】3dMax快速平铺纹理插件QuickTiles教程
    LLaMA Adapter和LLaMA Adapter V2
    想转行做产品经理的人为什么这么多?
    centos7安装mongodb
    OpenHarmony 3.1 Beta版本关键特性解析——分布式DeviceProfile
    大数据在电力行业的应用案例100讲(二十六)-分布式ID微服务实现及应用
    跟TED演讲学英文:Entertainment is getting an AI upgrade by Kylan Gibbs
    C++ 移动构造函数
    virualBox虚拟机系统磁盘fdisk无损扩容
  • 原文地址:https://blog.csdn.net/lxylluvio/article/details/126554765