Codeforces Round #499 (Div. 2) - 赛后补题
Posted zgglj-com
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #499 (Div. 2) - 赛后补题相关的知识,希望对你有一定的参考价值。
题解:二分答案,然后模拟验证。
//#include<bits/stdc++.h> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bitset> #include<vector> #include<queue> #include<set> #define ll long long #define P pair<int, int> #define PP pair<int,pair<int, int>> #define pb push_back #define pp pop_back #define lson root << 1 #define INF (int)2e9 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; const int N = 1e5 + 5; int n, m; int a[1005], b[1005]; bool check(double mid) { double x = m * 1.0 + mid; if(mid * a[1] * 1.0 < x) return false; for(int i = 1; i <= n; i++) { x -= x / (1.0 * a[i]); if(x < 1.0 * m) return false; x -= x / (1.0 * (i == n ? b[1] : b[i + 1])); if(x < 1.0 * m) return false; } return true; } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; double l = 0, r = 1000000007.0; double ans = -1; for(int i = 1; i <= 100; i++) { double mid = (l + r) / 2.0; if(check(mid)) { ans = mid; r = mid; } else l = mid; } if(ans == -1) puts("-1"); else printf("%.7f ", ans); return 0; }
待填
题解:① a1 * x1 + a2 * x2 + a3 * x3 + ···· + an * xn = C,令 k = gcd( a1, a2, a3, ····· , an ),那么①式等价于 k * M = C,M是某个正整数。即用k可以构造出①式中所有可能出现的C。
//#include<bits/stdc++.h> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bitset> #include<vector> #include<queue> #include<set> #define ll long long #define P pair<int, int> #define PP pair<int,pair<int, int>> #define pb push_back #define pp pop_back #define lson root << 1 #define INF (int)2e9 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; const int N = 1e5 + 5; int n, k; int gcd(int a, int b) { if(a < b) swap(a, b); return (b == 0 ? a : gcd(b, a % b)); } int main() { cin >> n >> k; int g = 0; for(int i = 1; i <= n; i++) { int t; cin >> t; g = gcd(g, t); } set<int> ans; for(ll i = 0, s = 0; i < k; i++, s += g) ans.insert(s % k); cout << (int)ans.size() << endl; for(auto &i : ans) cout << i << " "; cout << endl; return 0; }
以上是关于Codeforces Round #499 (Div. 2) - 赛后补题的主要内容,如果未能解决你的问题,请参考以下文章
codeforces round #499(div2) 做题记录
Codeforces Round #499 (Div. 2)D. Rocket
Codeforces Round #436 E. Fire(背包dp+输出路径)