第 45 屆國際大學生程式設計競賽(ICPC)亞洲區域賽(濟南)
阿新 • • 發佈:2021-10-19
Xor Transformation
思路:
兩種方法,首先是最重要的一個式子:X^K=Y -> K=X^Y,所以先求出這個k,然後普通方法就是二進位制列舉k,把最高位的1當做一個數,然後之後的1加起來當做另一個數,由於每次k都會變大,所以先輸出小的再輸出大的。第二種方法就是先看看k和x的大小,由於k要小於x,所以如果k大於x的話,由於xor一個k和xor一個x再xor一個y是一樣的,所以先輸出y再輸出x即可
二進位制:
#include <iostream> #include <cstdio> #include <algorithm> #include<cstring> #include <cmath> #include <map> #include <vector> #include <set> #include <unordered_map> #include <sstream> #define ll long long #define Endl '\n' #define endl '\n' using namespace std; const int N = 1e5 + 10; const int M = 1e5 + 10; const ll mod = 3; const int INF = 0x3f3f3f3f; int main() { ll x, y; scanf("%lld%lld", &x, &y); ll k = x ^ y; vector<ll> res; ll tmp = 0; for (ll i = 63; i >= 0; i -- ) if(((k >> i) & 1)) { res.push_back((ll)1 << i); tmp= k - ((ll)1 << i); break; } res.push_back(tmp); printf("%lld\n", res.size()); sort(res.begin(), res.end()); for (ll i = 0; i < res.size(); i++ ) printf("%lld ", res[i]); return 0; }
思維:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <map> #include <vector> #include <set> #include <unordered_map> #include <sstream> #define ll long long #define Endl '\n' #define endl '\n' using namespace std; const int N = 1e5 + 10; const int M = 1e5 + 10; const ll mod = 3; const int INF = 0x3f3f3f3f; int main() { ll x, y; scanf("%lld%lld", &x, &y); ll k = x ^ y; if(k < x){ cout << 1 << endl; cout << k << endl; } else{ cout << 2 << endl; cout << y << ' ' << x << endl; } return 0; }
Cook Pancakes!
a/b上取整公式:(a+b-1)/b
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; int main() { int n, k; cin >> n >> k; int res = 0; if(k >= n) res = 2; else res = (2 * n + k - 1) / k; cout << res << endl; return 0; }
Stone Game
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 1000010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; string g[N]; bool st[N]; int dx[] = {-1, 0}, dy[] = {0, -1}; int main() { IOS; int a1, a2, a3; cin >> a1 >> a2 >> a3; int tmp = min(a1, a2); int res = tmp * 2; a1 -= tmp; a2 -= tmp; if(a1) { res += a1 / 3 * 3; a1 %= 3; if(a1 == 2) res ++; } if(a2) { res += a2 / 3 * 6; a2 %= 3; if(a2 == 2) res += 4; } cout << res << endl; return 0; }
Fight against involution
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; string g[N]; bool st[N]; struct Node{ int l, r; bool operator< (const Node& t) const { if(r == t.r) return l > t.l; else return r < t.r; } } w[N]; int main() { IOS; int n; cin >> n; for (int i = 0; i < n; i ++ ) cin >> w[i].l >> w[i].r; sort(w, w + n); LL res = 0, L = 0; for (int i = 0; i < n; i ++ ) { if(w[i].l > L)//遇到更大的L時,意味著此時R也改變了 L = w[i].l; res += L; } cout << res << endl; return 0; }