Codeforces Round #296 (Div. 2) A B C D
A:模拟辗转相除法时记录答案
B:3种情况:能降低2,能降低1。不能降低分别考虑清楚
C:利用一个set和一个multiset,把行列分开考虑。利用set自带的排序和查询。每次把对应的块拿出来分成两块插入回去。然后行列分别取最大相乘的作为这次询问的答案
D:一个区间覆盖问题的变形。注意公式的话。非常easy发现事实上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的更多相关文章
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper
题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- CodeForces Round #296 Div.2
A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...
- Codeforces Round #296 (Div. 2) A. Playing with Paper
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...
- Codeforces Round #296 (Div. 1) B - Clique Problem
B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...
- Codeforces Round #296 (Div. 1) B. Clique Problem 贪心
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
随机推荐
- Ch06 验证
6.1 服务器端验证 6.1.1 Data Annotations验证 6.1.2 扩展ModelMetadtaProvider 6.2 客户端验证 6.2.1 客户端验证初步 6.2.2 ...
- Ch03 视图基础
3.1 视图简介 3.1.1 选择待渲染视图 3.1.2 重写视图名 3.2 给视图传递数据 3.2.1 ViewDataDictionary 3.2.2 ViewBag 3.2.3 带 ...
- Oracle管道函数(Pipelined Table Function)介绍
一 概述: 1.管道函数即是能够返回行集合(能够使嵌套表nested table 或数组 varray)的函数,我们能够像查询物理表一样查询它或者将其 赋值给集合变量. 2.管道函数为并行运行,在普 ...
- android5.0(Lollipop) BLE Central牛刀小试
转载请表明作者:http://blog.csdn.net/lansefeiyang08/article/details/46482073 昨天写了android L BLE Peripheral的简单 ...
- SDUT 2893-B(DP || 记忆化搜索)
B Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 有n块地板排成一条直线,从左到右编号为1,2,3. . . n-1,n,每 ...
- asp.net2.0安全性(1)--用户角色篇(类)--转载来自车老师
Membership.MembershipUser和Roles类 用户与角色管理在asp.net2.0中是通过Membership和Roles两个类来实现的. Membership:用户成员账号管理, ...
- InsertOnSubmit、InsertAllOnSubmit等区别 (转)
a. InsertOnSubmit: 将一个实体添加到datacontext对象中,并在SubmitChange()的时候执行更改. b. InsertAllOnSubmit:将一个实体集合添加到da ...
- 基于visual Studio2013解决C语言竞赛题之1051数的顺序
题目 解决代码及点评 /* 功能:自然数N一般写成如下形式: N=d[k]d[k-1]d[1] (d[1]-d[k] 均是十进制数字) 如果d[i+1]>d[i] (i=k-1 ...
- 基于visual Studio2013解决C语言竞赛题之1089牛虎过河
题目 解决代码及点评 /************************************************************************/ /* ...
- “add measurements”(添加度量)菜单问题