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的更多相关文章

  1. 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 ...

  2. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  3. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  4. 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  5. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  6. 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 ...

  7. Codeforces Round #296 (Div. 1) B - Clique Problem

    B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 服务启动错误1053,一例解决方案(给用户添加NetworkService权限)

    WIndows XP的服务中,有一个服务需要以NT  AUTHORITY/NetworkService用户启动,但怎么也启动不起来,使用本地系统帐户启动没有任何问题,但是换成NetworkServic ...

  2. C++能在三个地方创造对象,而Delphi只有一个地方

    C++能在堆栈.堆.资料区创造对象. 但是Delphi只能在堆上创造对象

  3. 11.ThinkPHP 3.1.2 连贯操作

    ==================================================== 一.常用连贯操作 1.where 帮助我们设置查询条件 2.order 对结果进行排序 $ar ...

  4. 用c++开发基于tcp协议的文件上传功能

    用c++开发基于tcp协议的文件上传功能 2005我正在一家游戏公司做程序员,当时一直在看<Windows网络编程> 这本书,把里面提到的每种IO模型都试了一次,强烈推荐学习网络编程的同学 ...

  5. hdu1370-Biorhythms

    http://acm.hdu.edu.cn/showproblem.php?pid=1370 中国剩余定理 已知(n+d)%23=a;   (n+d)%28=b;   (n+c)%33=i       ...

  6. Python爬虫入门三之Urllib库的基本使用

    转自http://cuiqingcai.com/947.html 1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由 ...

  7. Effective C++_笔记_条款09_绝不在构造和析构过程中调用virtual函数

    (整理自Effctive C++,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 为方便采用书上的例子,先提出问题,在说解决方案. 1 问题 1: ...

  8. sql为数字添加千分位(也就是钱的格式)

    感觉这个东西在项目中用得挺多的,之前在前台页面是用正则来处理,现在由于是数据查询,所以直接在查出数据的时候将其转为指定的千分位格式,省的前台再处理,不讲原理,因为我也看不懂,不过会用就行了,在网上找了 ...

  9. 延迟函数 比sleep效果好

    sleep是会阻塞线程的 网上有些延迟函数测试下来还是会阻塞,而接下来推荐的代码则不会   1 2 3 4 5 6 7 8 9 procedure delay(dwMilliseconds:integ ...

  10. cryptography

    密码关还是有很多变态的题的,整理一下力所能及的吧. Circular Crypto(Asis-CTF2013) 这题只给了一张图片 仔细看一下就知道,这是几个单独的环,把它们分别整理出来.因为看着眼花 ...