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. transition与animation

    以前,一直都知道,transition是animation的一个简化版,甚至不算是动画,而是一种过渡. transition的用法 早两天用transition写了一个按钮滑动的效果,类似于IOS的设 ...

  2. 如何捕获winform程序全局异常?(续)

    前言 上篇文章我提供了一种方案可以供我们捕获单线程程序中的所有未处理异常.但是如果程序是多线程,那么新增线程出现了异常上个方案就无能为力了.本着方案总比问题多的态度,我再给大家提供一种新的方案,供大家 ...

  3. 基于visual Studio2013解决C语言竞赛题之1012连接字符串

         题目 解决代码及点评 /* 编写一个函数JOIN,让它实现字符串连接运算功能. */ #include <stdio.h> #include <stdl ...

  4. jquery mobile左右滑动切换页面

    jquery mobile左右滑动切换页面 $(function() {$("body").bind('swiperight', function() {  $.mobile.ch ...

  5. 按钮的图标 Button icons-JQUERY MOBILE 1.0正式版中文手册

    按钮的图标 Button icons-JQUERY MOBILE 1.0正式版中文手册 data-icon属性可以被用来创建如下所示的图标 左箭头data-icon="arrow-l&quo ...

  6. ArcGIS 10.3 for Desktop新特性介绍

    ArcGIS 10.3是一个完整公布的ArcGIS平台,它包含新的产品(ArcGIS Pro),针对10.2版本号产品进行了功能增强和稳定性的改进. ArcGIS 10.3 for Server新特性 ...

  7. [每日一题] OCP1z0-047 :2013-08-28 DELETE..........................................................160

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/10475707 正确答案:ACD 根据题库,操作如下: A答案能删除: oe@OCM> ...

  8. EasyUI - 操作 Tree 控件

    效果: HTML代码: 使用了模板页 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHo ...

  9. java 中通过label跳出双重for 循环

    java 中如何跳出双重for 循环 java跳出循环是使用break语句的,break默认跳出当前循环(包括for循环.while循环),当使用双层循环时,可通过label从内层循环跳出.有关对比的 ...

  10. TCP/IP笔记 二.网络层(2)——ICMP,RIP,OSPF,BGP

    1. ICMP ICMP (Internet Control Message Protocol) 作用:提高 IP 数据报交付成功的机会. 1.1 特点 ICMP 允许主机或路由器报告差错情况和提供有 ...