Contestant. Unrated, with problem C removed.
A. Hayato and School
题意
给定一个数组 
思路
分类讨论:
- 奇数元素数量大于 
,直接输出前三个奇数。  - 偶数只有 
个,或者没有奇数,无解。  - 输出一对”奇,偶,偶“即可。
 
时间复杂度:
对应AC代码
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
pair<int, int> a[N], b[N];
#define ll long long
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t --){
        int n;
        cin >> n;
        int o = 0, e = 0;
        for(int i=1;i<=n;i++){
            int p;
            cin >> p;
            if(p % 2 == 0) a[e ++] = {p, i};
            else b[o ++] = {p, i};
        }
        if(o >= 3){
            cout << "YES" << '\n';
            cout << b[0].second << " " << b[1].second << " " << b[2].second << '\n';
        }else if(o == 0 || e == 1){
            cout << "NO" << '\n';
        }else{
            cout << "YES" << '\n';
            cout << b[0].second << " " << a[0].second << " " << a[1].second << '\n';
        }
    }
} 这么签的题居然WA了,淦
B. GCD Partition
题意
给定一个数组 
思路
可以证明,分隔为两段后可以保证取到 
若需略微证明,因求出的 
既然分两段,暴力即可。
时间复杂度:
对应AC代码
import java.math.BigInteger;
import java.util.*;
public class Main{
    private static long gcd(long a, long b) {
        while(b != 0) {
            long tmp = a;
            a = b;
            b = tmp % b;
        }
        return a;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while (t-- > 0) {
            int n = scanner.nextInt();
            long tot = 0;
            long[] a = new long[n + 1];
            for(int i=1;i<=n;i++) tot += a[i] = scanner.nextInt();
            long ans = 1, sum = 0;
            for(int i=1;i<n;i++){
                sum += a[i];
                ans = Math.max(ans, gcd(sum, tot - sum));
            }
            System.out.println(ans);
        }
    }
} 怎么还会去想分段怎么分呢,真是,淦
D. Bit Guessing Game
题意
互动游戏,对于一个未知数 
思路
我们考虑到题给范围为 
首先,对于一个二进制数,我们引入一个结论:
若某一位为 
而若某一位为 
因此,我们可以从低位向高位枚举,若满足条件,那么将目标数字的该位标为 
时间复杂度:
对应AC代码
import java.math.BigInteger;
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while (t-- > 0) {
            int cnt = scanner.nextInt();
            int ans = 0, b = 0, on = 0;
            while(cnt > 0){
                System.out.printf("- %d\n", (1 << on) - b);
                System.out.flush();
                int now = scanner.nextInt();
                if(now == -1) return; //wa了...
                if(cnt - now == 1) {
                    b = 0;
                    cnt = now;
                    ans += 1 << on;
                }
                else b += (1 << on) - b;
                on ++;
            }
            System.out.printf("! %d\n", ans);
            System.out.flush();
        }
    }
} 我跟自己写的代码玩游戏.jpg
- 本文链接 https://floating-ocean.github.io/blog_old/posts/871658605/
 - 版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!