跳到正文

个人记录

3.13

TchongS1010C约 9 分钟
原文
文章信息与版本

文章信息

发布
2026年3月13日
收录
2026年3月16日
更新
2026年11月17日
篇幅
约 9 分钟

版本

  1. v2当前
  2. v1

比赛结果出炉(翻车了)

ABCDE总分排名
10010065654040000020420422

P10835

第三个条件就是因为他很简单的原因,每个元素都相同,我们知道a⨁a=0,0⨁a=aa \bigoplus a = 0 , 0 \bigoplus a = a,所以如果mm是偶数的话,不管怎么样结果都是00,否则如果ai=na_i=n结果就是nn

C++
#include <bits/stdc++.h>
using namespace std ;
int t , n , m ;
int main()
{
	cin >> t ;
	while(t --)
	{
		cin >> n >> m ;
		if(n == 0)
		{
			if(m % 2 == 0) cout << "Yes\n" ;
			else cout << "No\n" ; 
		}
		else
		{
			if(m % 2 == 0) cout << "No\n" ;
			else cout << "Yes\n" ;
		}
	}	
	return 0 ;
}

2.P14664

如果直接求解的话会很困难,所以我们可以求出最优的a,ba,b,初始化a=n,b=0a=n,b=0,后面从高位到低位贪心调整

用Ai,BiA_i,B_i表示a,ba,b二进制的ii位,ansans表示a+ba+b

  1. 如果Ai=0A_i=0,因为1⨁1=0,0⨁0=01\bigoplus1=0,0\bigoplus0=0,所以当a+2i≤n,b+2i≤na+2^i\le n,b+2^i\le n时设Ai=Bi=1,ans←ans+ai+1A_i=B_i=1,ans \gets ans + a^{i+1}
  2. 如果Ai=1A_i=1,当且仅当 ∣(a−2i)−(b+2i)∣<∣a−b∣|(a-2^i)-(b+2^i)|<|a-b|是把(Ai,Bi)=(1,0)←(0,1)(A_i,B_i)=(1,0)\gets(0,1)
为什么正确

2进制有个性质:2x−∑i=1x−12i2^x-\sum^{x-1}_{i=1}2^i,那么肯定从高位开始贪心更优,如果a,ba,b越接近,越易满足低位扩容条件。

代码如下:

C++
#include <bits/stdc++.h>
using namespace std;
long long t , n , b[40] , m ;
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;
    cin >> t ;
    while(t --)
    {
        cin >> n ;
        m = 0 ;
        long long x = n , y = 0 , t = n ;
        while(n > 0)
        {
            b[++ m] = n % 2 ;
            n /= 2 ;
        }
        n = t ;
        for(int i = m ; i >= 1 ; i --)
        {
            long long p = (1 << (i - 1)) ;
            if(b[i] == 0 && x + p <= t && y + p <= t)
            {
                y += p;
                x += p;
            }
            else if(b[i] == 1)
            {
                if(abs(x - y) > abs((x - p) - (y + p)))
                {
                    x -= p;
                    y += p;
                }
            }
        }
        cout << x + y << "\n";
    }
    return 0;
}

3.T740903

首先异或有规律,设s=⨁i=1i=nais=\bigoplus_{i=1}^{i=n} a_i,则s⨁a−x=ax(1≤x≤n)s \bigoplus a-x=a_x(1\le x \le n)

我们可以手推几个数组就会发现其实他是一个结论题

  1. 如果nn是奇数,那么如果k>0k>0,数组只会变化一次(1,2,4→6,5,3→6,5,3...{1,2,4}\to{6,5,3}\to{6,5,3}...)
  2. 否则(请参见样例)
    1. 当kk是奇数,数组相当于变化一次
    2. 否则,相当于不变化
C++
#include <bits/stdc++.h>
using namespace std ;
long long t , n , a[100005] , k ;
int main()
{
	cin >> t ;
	while(t --)
	{
		long long sum = 0 ;
		cin >> n >> k ;
		for(int i = 1 ; i <= n ; i ++)
		{
			cin >> a[i] ;
			sum ^= a[i] ;
		}
        if(n % 2 == 0)
        {
    		if(k % 2 == 0)
    		{
    			for(int i = 1 ; i <= n ; i ++)
    			{
    				cout << a[i] << " " ;
    			}
    		}
    		else
    		{
    			for(int i = 1 ; i <= n ; i ++)
    			{
    				cout << (sum ^ a[i]) << " " ;
    			}
    		}
        }
        else
        {
            for(int i = 1 ; i <= n ; i ++)
            {
                cout << (sum ^ a[i]) << " " ;
            }
        }
		cout << "\n" ;
	}
	return 0 ;
}
经过本人现场考试WA总结的经验

别只看样例的偶数就觉得自己懂了一切,你还是要手推一波

4.T417748

我们可以通过or,and和xor的定义和运算发现:一位当且仅当至少有22个11和11个00时可以发现这个机器这一位的工作方式,所以可以直接记录每一位1,01,0的数量在算出最多还需要多少张纸条

C++
#include <bits/stdc++.h>
using namespace std ;
int n , cnt1[105] , cnt0[105] , maxn , ans = 0 ;
string s ;
int main()
{
    cin >> n ;
    while(n --)
    {
        cin >> s ;
        maxn = max(maxn , int(s.size())) ;
        for(int i = 0 ; i < s.size() ; i ++)
        {
            if(s[i] == '0') cnt0[i] ++ ;
            else cnt1[i] ++ ;
        }
    }
    for(int i = 0 ; i < maxn ; i ++)
    {
        if(cnt0[i] && cnt1[i] >= 2)
        {
            ans = max(ans , 0) ;
        }
        else if(cnt0[i])
        {
            ans = max(ans , 2 - cnt1[i]) ;
        }
        else if(cnt1[i] >= 2)
        {
            ans = max(ans , 1) ;
        }
        else
        {
            ans = max(ans , 3 - cnt1[i]) ;
        }
    }
    cout << ans ;
    return 0 ; 
}
易错点(本人没犯)

认为机器所有位的工作方式都一样

5.P7076

  1. 本题本质是二进制位运算,cc和饲料编号为无用条件,直接忽略
  2. 用按位或统计所有动物已存在的二进制位,标记必须为00的二进制位(如果为11那么就有新增饲料),剩余自由位数量为 tt
  3. 总情况=2t−n2^t-n(总数量-已有数量)
特例

当t=64,n=0t=64,n=0,需要手动输出2642^{64}的字符串

C++
#include <bits/stdc++.h>
using namespace std ;
unsigned long long n , m , c , k , a , p , q , flag , g , ans = 1 ;
int main()
{
    cin >> n >> m >> c >> k ;
    for(int i = 1 ; i <= n ; i ++)
    {
        cin >> a ;
        flag |= a ;
    }
    while(m --)
    {
        cin >> p >> q ;
        if((flag >> p & 1) == 0) g |= 1ULL << p ;
    }
    for(int i = 0 ; i < k ; i ++)
    {
        if((g >> i & 1) == 0)
        {
            ans <<= 1 ;
        }
    }
    if(ans == 0 && n == 0) cout << "18446744073709551616" ;
    else cout << ans - n ;
    return 0 ;
}
原文