比赛结果出炉(翻车了)
| A | B | C | D | E | 总分 | 排名 |
|---|---|---|---|---|---|---|
P10835
第三个条件就是因为他很简单的原因,每个元素都相同,我们知道,所以如果是偶数的话,不管怎么样结果都是,否则如果结果就是
#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
如果直接求解的话会很困难,所以我们可以求出最优的,初始化,后面从高位到低位贪心调整
用表示二进制的位,表示
- 如果,因为,所以当时设
- 如果,当且仅当 是把
为什么正确
2进制有个性质:,那么肯定从高位开始贪心更优,如果越接近,越易满足低位扩容条件。
代码如下:
#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
首先异或有规律,设,则
我们可以手推几个数组就会发现其实他是一个结论题
- 如果是奇数,那么如果,数组只会变化一次()
- 否则(请参见样例)
- 当是奇数,数组相当于变化一次
- 否则,相当于不变化
#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的定义和运算发现:一位当且仅当至少有个和个时可以发现这个机器这一位的工作方式,所以可以直接记录每一位的数量在算出最多还需要多少张纸条
#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
- 本题本质是二进制位运算,和饲料编号为无用条件,直接忽略
- 用按位或统计所有动物已存在的二进制位,标记必须为的二进制位(如果为那么就有新增饲料),剩余自由位数量为
- 总情况=(总数量-已有数量)
特例
当,需要手动输出的字符串
#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 ;
}