A. Neko Finds Grapes
思路:奇偶配对一下
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 5; 4 int main() 5 { 6 std::ios::sync_with_stdio(false); 7 int n, m; 8 int a; 9 int o1 = 0,e1 = 0; 10 int o = 0, e = 0; 11 cin >> n >> m; 12 for(int i = 0;i < n;i++) 13 { 14 cin >> a; 15 if(a % 2) e++; 16 else o++; 17 } 18 for(int i = 0;i < m;i++) 19 { 20 cin >> a; 21 if(a % 2) e1 ++; 22 else o1++; 23 } 24 int ans = 0; 25 ans += min(e1, o); 26 ans += min(o1, e); 27 cout << ans << endl; 28 return 0; 29 }
B. Neko Performs Cat Furrier Transform
思路:找到最高位的0,然后改成1,一直重复直到满足即可。
AC代码:
#include<bits/stdc++.h> using namespace std; int f(int x) { int res = 0, pos = 0; while(x) { if(x % 2 == 0)res = pos; pos ++; x >>= 1; } return res; } int vis[29]; int sum[50]; void init() { vis[0] = 1; for(int i = 1;i < 29;i++) { vis[i] = vis[i-1] * 2; } } bool check(int x) { for(int i = 0;i < 29;i++) { if(x == vis[i] - 1) return true; } return false; } int main() { init(); int x; cin >> x; int cnt = 1; while(!check(x)) { if(cnt % 2) { sum[cnt] = f(x) + 1; x ^= vis[sum[cnt]] - 1; } else x++; cnt++; } cout << cnt - 1 << endl; for(int i = 1;i < cnt;i++) { if(i % 2) cout << sum[i] << " "; } return 0;C. Neko does Maths
C. Neko does Maths
题意:求最小的k 使 a+ k 和 b + k 的最小公倍数最小。
思路:看了好久才有点理解。
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main() 5 { 6 ll a, b; 7 cin >> a >> b; 8 ll d = abs(a - b); 9 vector<ll> v; 10 for(ll i = 1;i*i <= d;i++) 11 { 12 if(d % i == 0) 13 { 14 v.push_back(i); 15 if(i * i != d) v.push_back(d / i); 16 } 17 } 18 ll lcm = a*b/__gcd(a,b); 19 ll k = 0; 20 for(ll i:v){ 21 ll d = a % i; 22 ll x = i - d; 23 ll ans = (a + x)*(b + x) / __gcd(a+x,b+x); 24 if(ans < lcm){ 25 lcm = ans; 26 k = x; 27 } 28 else if(ans==lcm&&k>x){ 29 k=x; 30 } 31 } 32 cout<<k<<endl; 33 return 0; 34 }