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. Python 基础编程

    Python 打印九九乘法表: for i in range(1,10): for j in range(1,i+1): print j,'*',i,'=',j*i,' ', print '\n' P ...

  2. Andorid时间控件和日期控件

      

  3. EasyUI - DataGrid 组建 - [ 排序功能 ]

    效果: 红框的字段看,为设置了,列排序,向后台Post数据sort/order. 原理:向后台POST数据,sort/post数据. html代码: <table id="tab&qu ...

  4. 简单的javascript抽奖程序

    <html>  <head>   <title>手机号码抽奖程序</title>   <script>    //声明一个数组装住号码,可根 ...

  5. NX-bridge,可以实现无线XBee控制的Arduino板

    ”今天Elecfreaks Studio给你介绍一个新的.很实用的朋友:带有一些奇幻色彩的神秘设备.它是什么呢?它可以完成什么功能呢?它对我们的生活有哪些促进呢?非常感兴趣吧?别着急,我们这就给您详细 ...

  6. C语言sendto()函数-经socket传送数据以及recvfrom函数《转》

    相关函数:send, sendmsg, recv, recvfrom, socket 头文件:#include <sys/types.h>   #include <sys/socke ...

  7. 【ASP.NET Web API教程】2.3.5 用Knockout.js创建动态UI

    原文:[ASP.NET Web API教程]2.3.5 用Knockout.js创建动态UI 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容 ...

  8. Transformations 方块转换

    题目是中文题,就不做什么解释了,纯模拟题,主要要搞清楚这几种装换方式下标的变化: 第一种:顺时针旋转90度: c[j][n-i+1]=a[i][j]; 第二种:旋转180度: c[n-i+1][n-j ...

  9. 算法设计与分析——多边形游戏(DP)

    1.问题描述:   给定N个顶点的多边形,每个顶点标有一个整数,每条边上标有+(加)或是×(乘)号,并且N条边按照顺时针依次编号为1~N.下图给出了一个N=4个顶点的多边形. 游戏规则 :(1) 首先 ...

  10. POJ2031Building a Space Station (最小生成树之prim)

    Problem Description You are a member of the space station engineering team, and are assigned a task ...