Yra's blog Yra's blog
Homepage
  • LeetCode周赛
  • Acwing周赛
  • 刷题整理
  • 题解
  • CPP
  • Golang
  • System

    • MIT6.S081 Labs
  • Computer Networking

    • CS144: Computer Networking
  • DataBase

    • MySQL
    • Redis
  • Others

    • ......
  • Paper Reading

    • Petri Net
  • Static Analysis

    • NJU Course Notes
  • Deep Learning

    • Dive into Deep Learning
Casual Records
Archives

Yra

Only a vegetable dog.
Homepage
  • LeetCode周赛
  • Acwing周赛
  • 刷题整理
  • 题解
  • CPP
  • Golang
  • System

    • MIT6.S081 Labs
  • Computer Networking

    • CS144: Computer Networking
  • DataBase

    • MySQL
    • Redis
  • Others

    • ......
  • Paper Reading

    • Petri Net
  • Static Analysis

    • NJU Course Notes
  • Deep Learning

    • Dive into Deep Learning
Casual Records
Archives
  • LeetCode周赛

  • Acwing周赛

    • Contests

      • Acwing 64th Weekly Contest
        • A
          • 题意
          • 思路
          • 代码
        • B
          • 题目
          • 思路
          • 代码
        • C
          • 题目
          • 思路
          • 代码
        • D
          • 题目
          • 思路
          • 代码
  • 刷题日寄

  • 题解

  • Competitive Programming
  • Acwing周赛
  • Contests
Yra
2022-08-14
目录

Acwing 64th Weekly Contest

# A

# 题意

求 A + B

# 思路

测试题

# 代码


      #include <bits/stdc++.h>
    
      using ll = long long;
    
      int main() {	
      	std::ios::sync_with_stdio(0); 
      	std::cin.tie(0);
    
      	ll a, b;
      	std::cin >> a >> b;
      	std::cout << a + b << "\n";
    
      	return 0;
      }	
    
    // Make sure to add code blocks to your code group

    # B

    # 题目

    4506. 三国语言 - AcWing题库 (opens new window)

    # 思路

    只需要判断输入字符串的最后一个字符即可。

    # 代码


      #include <bits/stdc++.h>
      
      using ll = long long;
      
      int main() {	
        std::ios::sync_with_stdio(0); 
        std::cin.tie(0);
      
        int n;
        std::cin >> n;
        while (n --) {
        	std::string s;
        	std::cin >> s;
        	if (s.back() == 'u') puts("JAPANESE");
        	else if (s.back() == 'o') puts("FILIPINO");
        	else puts("KOREAN");
        }
      
        return 0;
      }	
      
      // Make sure to add code blocks to your code group

      # C

      # 题目

      4507. 子数组异或和 - AcWing题库 (opens new window)

      # 思路

      • 补充一下异或的性质:对任意数字 来说,

      对于符合条件的子数组满足:所有元素的异或和为 0 并且 数组长度为偶数。

      在这里我们采用前缀异或和的思路,输入数据时维护一个数组 ,对于 表示异或前缀和为,并且下标为偶数的个数。

      例如某个奇数下标的前缀异或和为,我们只需要知道将答案加上 即可。

      需要注意的是,对于前缀异或和为 0 的偶数项,需要额外加上 1,也可以建立完 数组后进行初始化 。

      PS:本题需要开long long

      # 代码


        #include <bits/stdc++.h>
        
        using ll = long long;
        constexpr int N = 1 << 21 + 5;
        int mp[N][2];
        
        int main() {	
          std::ios::sync_with_stdio(0); 
          std::cin.tie(0);
        
          int n;std::cin >> n;
          std::vector<int> a(n + 1);
          std::vector<int> suf(n + 1);
          ll res = 0;
          for (int i = 1; i <= n; i ++) {
              std::cin >> a[i];
              suf[i] = a[i] ^ suf[i - 1];
              int s = i & 1;
              res += mp[suf[i]][s] + (suf[i] == 0 && !s);
              mp[suf[i]][s] ++;
          }
          std::cout << res <<"\n";
          
          return 0;
        }	
        
        // Make sure to add code blocks to your code group

        # D

        # 题目

        4508. 移动的点 - AcWing题库 (opens new window)

        # 思路

        本题我们考虑点之间的相对速度。

        image-20220814220634503

        图中黑线是两点的运动轨迹,红线是斜率为 a 的直线。很显然的可以看出,两点之间的连线始终与红线平行,因此如果两点能够相遇,则一定满足两点纵轴速度差与横轴速度差之比为 a,即

        因此我们对于每个点 只需要计算 ,并且用哈希表维护数量。同时在计算答案是要减去相对静止的两个点,可以发现当两点的速度分量都相同时,两点相对静止,我们也用哈希表进行维护。

        最后答案记得乘二,因为两个点发生相遇时,它们的 值都会增加。

        PS:本题需要开long long

        # 代码


          #include <bits/stdc++.h>
          
          using ll = long long;
          
          int main() {	
            std::ios::sync_with_stdio(0); 
            std::cin.tie(0);
          
            int n, a, b;
            std::map<ll, int> cnt;
            std::map<std::pair<int, int>, int> para;
            ll res = 0;
            std::cin >> n >> a >> b;
            for (int i = 0; i < n; i ++) {
            	int x, vx, vy;
            	std::cin >> x >> vx >> vy;
            	int t = a * vx - vy;
            	res += cnt[t] - para[{vx, vy}];
            	cnt[t] ++, para[{vx, vy}] ++;
            }
            std::cout << res * 2 << "\n";
          
            return 0;
          }	
          
          // Make sure to add code blocks to your code group

          #Competitive Programming#Acwing周赛#Contests
          Last Updated: 3/4/2023, 5:38:14 PM
          LeetCode 321th Weekly Contest
          简简单单刷个题⑧

          ← LeetCode 321th Weekly Contest 简简单单刷个题⑧→

          最近更新
          01
          408 计组笔记
          07-19
          02
          Dive into Deep Learning
          01-27
          03
          25 考研随记
          11-27
          更多文章>
          Theme by Vdoing | Copyright © 2022-2025
          • 跟随系统
          • 浅色模式
          • 深色模式
          • 阅读模式