标签:
A:模拟辗转相除法时记录答案
B:3种情况:能减少2,能减少1,不能减少分别考虑清楚
C:利用一个set和一个multiset,把行列分开考虑,利用set自带的排序和查询,每次把相应的块拿出来分成两块插入回去,然后行列分别取最大相乘的作为这次询问的答案
D:一个区间覆盖问题的变形,注意公式的话,很容易发现其实x,w对应的就是一个[x - w, x + w]的区间,然后求最多不重合区间即可
代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll a, b, ans; ll gcd(ll a, ll b) { if (!b) return a; ans += a / b; return gcd(b, a % b); } int main() { scanf("%lld%lld", &a, &b); gcd(a, b); printf("%lld\n", ans); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 200005; int n; char a[N], b[N]; int g[30][30]; int vis[30]; int main() { scanf("%d%s%s", &n, a + 1, b + 1); int sum = 0; for (int i = 1; i <= n; i++) if (a[i] != b[i]) sum++; for (int i = 1; i <= n; i++) { if (a[i] != b[i]) { if (g[b[i] - 'a'][a[i] - 'a']) { printf("%d\n%d %d\n", sum - 2, i, g[b[i] - 'a'][a[i] - 'a']); return 0; } g[a[i] - 'a'][b[i] - 'a'] = i; } } for (int i = 1; i <= n; i++) { if (a[i] != b[i]) { vis[b[i] - 'a'] = i; } } for (int i = 1; i <= n; i++) { if (a[i] != b[i] && vis[a[i] - 'a']) { printf("%d\n%d %d\n", sum - 1, i, vis[a[i] - 'a']); return 0; } } printf("%d\n-1 -1\n", sum); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <set> using namespace std; int w, h, n; set<int> x[2]; multiset<int> xx[2]; char op[2]; int v; set<int>::iterator it, l, r; multiset<int>::iterator tmp; long long gao(int tp) { x[tp].insert(v); it = x[tp].find(v); l = it; l--; r = it; r++; xx[tp].erase(xx[tp].find(*r - *l)); xx[tp].insert(v - *l); xx[tp].insert(*r - v); long long ans = 1; tmp = xx[tp].end(); tmp--; ans *= *tmp; tmp = xx[!tp].end(); tmp--; ans *= *tmp; return ans; } int main() { scanf("%d%d%d", &w, &h, &n); x[0].insert(0); x[0].insert(w); x[1].insert(0); x[1].insert(h); xx[0].insert(w); xx[1].insert(h); while (n--) { scanf("%s%d", op, &v); printf("%lld\n", gao(op[0] == 'H')); } return 0; }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 200005; const int INF = 0x3f3f3f3f; struct Seg { int l, r; Seg() {} Seg(int l, int r) { this->l = l; this->r = r; } } seg[N]; int n, x, w; bool cmp(Seg a, Seg b) { return a.r < b.r; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x, &w); seg[i] = Seg(x - w, x + w); } sort(seg, seg + n, cmp); int ans = 0; int r = -INF; for (int i = 0; i < n; i++) { if (seg[i].l >= r) { r = seg[i].r; ans++; } } printf("%d\n", ans); return 0; }
Codeforces Round #296 (Div. 2) A B C D
标签:
原文地址:http://blog.csdn.net/accelerator_/article/details/44435629