Codeforces Round #296 (Div. 2) A B C D
2015-03-19 01:41
274 查看
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;
}
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 , b ; 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 ; 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. 1) E. Triangles 3000
- Codeforces Round #296 (Div. 2) C(STL_set)
- Codeforces Round #296 (Div. 2)——A.B.C.D
- Codeforces Round #296 (Div. 2) A, B, C, D
- Codeforces Round #296 (Div. 2) —— C(set/multiset)
- Codeforces Round #296 (Div. 1) E. Triangles 3000
- Codeforces Round #296 (Div. 2) C. Glass Carving
- codeforces round# 296 (div1 D)(bitmasks)
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
- Codeforces Round #240 (Div. 2) C Mashmokh and Numbers
- Codeforces Round #Pi (Div. 2) ——B. Berland National Library
- Codeforces Round #375 (Div. 2) D. Lakes in Berland
- Codeforces Round #240 (Div. 2) E分治算法探究1
- Codeforces Round #313 (Div. 2) Gerald's Hexagon
- Codeforces Round #202 (Div. 2) B.Color the Fence
- Codeforces Round #294 (Div. 2)-C. A and B and Team Training
- Codeforces Round #211 (Div. 2)B. Fence
- Codeforces Round-#458 (Div. 2 && Div. 1) [Codeforces914]
- Codeforces Round #203 (Div. 2) C------Bombs
- Codeforces Round #169 (Div. 2):E - Little Girl and Problem on Trees