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. C++中vector的实现

     注意几点: 分配内存不要使用new和delete,由于new的同一时候就把对象构造了.而我们须要的是原始内存. 所以应该使用标准库提供的allocator类来实现内存的控制.当然也能够重载ope ...

  2. JCL学习

    JCL基本概念 定义:job control language 用户与操作系统的接口,用户通过JCL语句按照自己的意图来控制作业的执行. JOB的概念:把大机要实现的每一项任务,称为一个JOB或作业. ...

  3. 【Android开源项目分析】android轻量级开源缓存框架——ASimpleCache(ACache)源代码分析

    转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46379055 ASimpleCache框架源代码链接 https://github ...

  4. CentOS6 yum源支持更多rpm包的升级(使用第三方软件库EPEL、RPMForge与RPMFusion)

    转载于http://blog.csdn.net/erazy0/article/details/6878153 在CentOS下运行yum install flash-plugin或yum instal ...

  5. Jquery文本框小例(必填框)

    <script src="../JavaScript/jquery-2.0.2.min.js"></script> <script type=&quo ...

  6. 服务确定(服务类收货ML81N)

    FUNCTION zrfc_mm005. *"---------------------------------------------------------------------- * ...

  7. HDU--杭电--3790--最短路径问题

    最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. fzu 1913 Easy Comparison(字符串)

    题目链接:fzu 1913 Easy Comparison 题目大意:给出一个字符串,计算与它按照字典序排序排列后的字符串有多少个位置不同. 解题思路:水体,sort一下,然后遍历一遍就好. #inc ...

  9. Java与C#的语法区别(不断更新中...)

    1.static关键字: 在java中静态成员能够被对象和类名调用: 在C#中,静态成员只能被类调用不能被对象调用. 2.for循环: 在java中可以在for前面添加标记,然后在for循环中可以br ...

  10. 基于visual Studio2013解决C语言竞赛题之1081shell排序

        题目 解决代码及点评 /************************************************************************/ /* ...