1001:
一句话题意: 找到最小的c使得 ( a ⨂ c ) & ( b ⨂ c ) 最 小 (a\bigotimes c)\&(b\bigotimes c) 最小 (a⨂c)&(b⨂c)最小
zjx话说:整个式子最小可以看成a反转某些1后异或上反转同样的1的b最小, 一个很贪的想法就是, a和b都是1 的情况我就翻掉(a&b), 然后特判没有的情况
@author:zjx
#include <bits/stdc++.h>
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rev(i, a, b) for (int i = (a); i >= (b); --i)
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rof(i, a, b) for (int i = (a); i > (b); --i)
#define ll long long
#define db double
#define oo 0x3f3f3f3f
#define eps 0.00001
#define all(x) x.begin(), x.end()
#define met(a, b) memset(a, b, sizeof(a))
#define bin(x) cerr << #x << " is " << bitset<15>(x) << endl
#define what_is(x) cerr << #x << " is " << x << endl
#define lowbit(x) x &(-x)
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int main(){
ios::sync_with_stdio(0);
//FILE *o = freopen("C:\\Users\\Jason.Z\\OneDrive\\out.txt", "w", stdout);
int t;
cin >> t;
while(t--){
ll a, b;
cin >> a >> b;
if((a&b) == 0){
cout << __gcd(a, b) << endl;
}else cout << (a & b) << endl;
}
}
1002:
1003:
1004:
1005:
1006:
CX 说: 我只记得鱼了,也是水题, 注意输出格式
@author CX
#include <iostream>
using namespace std;
#define maxn 100010
#define ll long long
int main()
{
ll numn[maxn] = {0};
ll s[maxn] = {0};
bool bm[maxn] = {0};
ll n = 0, m = 0;
scanf("%lld%lld", &n, &m);
for(ll i = 1; i <= n; i++)
{
scanf("%lld", &numn[i]);
}
for(ll i = m; i > 0; i--)
{
scanf("%lld", &s[i]);
}
for(ll i = 1; i <= m; i++)
{
if(bm[s[i]])
{
continue;
}
printf("%lld ", numn[s[i]]);
bm[s[i]] = 1;
}
for(ll i = 1; i <= n; i++)
{
if(!bm[i])
{
printf("%lld ", numn[i]);
}
}
return 0;
}
1007:
dzh说水题一道
@author dzh
#include<cstdio>
int dp[5000][5000];
int cur_sz = 2;
void deal()
{
for (int i = 1; i <= cur_sz; i++)
for (int j = 1; j <= cur_sz; j++)
if (dp[i][j] == 1)
dp[i + cur_sz][j] = 0, dp[i][j + cur_sz] = 1, dp[i + cur_sz][j + cur_sz] = 1;
else
dp[i + cur_sz][j] = 1;
cur_sz *= 2;
}
void solve()
{
int t;
scanf("%d", &t);
while (t--)
{
dp[1][1] = dp[1][2] = dp[2][2] = 1;
cur_sz = 2;
int k;
scanf("%d", &k);
for (int i = 2; i <= k; i++)
deal();
for (int i = 1; i <= cur_sz; i++)
{
for (int j = 1; j <= cur_sz; j++)
if (dp[i][j] == 1) putchar('C');
else putchar('P');
putchar('\n');
}
}
}
int main()
{
//freopen("Testin.txt", "r", stdin);
//freopen("Testout.txt", "w", stdout);
solve();
return 0;
}
1008
CX说: 鱼来了, 注意sort的第二个参数…
@author CX
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 100010
#define ll long long
int main()
{
int t = 0;
scanf("%d", &t);
while (t--)
{
ll n = 0, k = 0;
scanf("%lld%lld", &n, &k);
ll t[maxn] = {0};
ll w[maxn] = {0};
ll fish = 1;
ll ans = k;
for (ll i = 1; i <= n; i++)
{
scanf("%lld", &t[i]);
ans += t[i];
fish += (t[i] / k);
w[i] = k - (t[i] % k);
}
sort(w + 1, w + n + 1);
for (int i = 1; i <= n - fish; i++)
ans += w[i];
printf("%lld\n", ans);
}
return 0;
}
1009:
1010:
1011:
占坑