A. Playing with Paper

如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形。

时间复杂度和欧几里得算法一样。

 #include <iostream>
#include <cstdio>
using namespace std; //const int maxn = ; int main()
{
//freopen("in.txt", "r", stdin); long long a, b, ans = ;
scanf("%I64d%I64d", &a, &b);
while(a % b != )
{
ans += a / b;
long long ta = b;
long long tb = a % b;
a = ta; b = tb;
}
ans += a / b;
printf("%I64d\n", ans); return ;
}

代码君

B. Error Correct System

代码略矬。。

贪心,建一个有向图G[a][b] = i,代表第i个字符“想”从字母a变成字母b,也就是说s1[i] == a, s2[i] == b,如果s1中第i个字母从a变成b后,题中定义的那个Hamming distance就会减小1.如果有G[a][b] 和 G[b][a]的话,直接将这两个字符交换就好了,Hamming distance一共减少2。

否则,退而求其次,交换一下只满足G[a][b] G[b][c]的两个位置的字符,这样Hamming distance减小1.

再否则,,,直接输出-1 -1

 #include <iostream>
#include <cstdio>
using namespace std; const int maxn = + ; int n;
char s1[maxn], s2[maxn]; int G[][]; int main()
{
//freopen("in.txt", "r", stdin); scanf("%d", &n); getchar();
gets(s1+); gets(s2+); int ans = , p1 = -, p2 = -;
for(int i = ; i <= n; i++) if(s1[i] != s2[i]) ans++; for(int i = ; i <= n; i++) if(s1[i] != s2[i])
{
int x = s1[i]-'a', y = s2[i]-'a';
G[x][y] = i;
if(G[y][x]) { p1 = i; p2 = G[y][x]; ans -= ; break; }
} bool flag = false;
if(p1 + p2 == -)
{
for(int i = ; i < ; i++)
{
for(int j = ; j < ; j++) if(G[i][j])
{
for(int k = ; k < ; k++) if(G[j][k])
{
flag = true;
ans--;
p1 = G[i][j]; p2 = G[j][k];
break;
}
if(flag) break;
}
if(flag) break;
}
} printf("%d\n%d %d\n", ans, p1, p2); return ;
}

代码君

C. Glass Carving

果然,熟练使用STL是很有必要的,减小编码复杂度,速度上也不会太慢。

话说有一个人对着一块玻璃横着或者竖着切来切去。

每次切完都要询问一下最大的一块玻璃的面积是多少。

将所有切割的位置放在一个集合中,还有所有相邻位置之间的距离放在一个多重集合里面。

每一次切割位置x,都将a<x<b这个区间分成了两个,同时将x加入到对应的切割位置集合;然后更新一下距离集合,具体就是删除b-a这段距离(如果有多个,只要删除一个就好了),然后分别插入(x-a) 和 (b-x)这两段被分隔开的距离。

 #include <bits/stdc++.h>
using namespace std; int main()
{
//freopen("in.txt", "r", stdin); set<int> sh, sv;
multiset<int> mh, mv;
set<int>::iterator l, r; int w, h, n;
scanf("%d%d%d", &w, &h, &n); getchar();
sh.insert(); sh.insert(h);
sv.insert(); sv.insert(w);
mh.insert(h); mv.insert(w); while(n--)
{
char op; int cut;
scanf("%c %d", &op, &cut); getchar();
if(op == 'H')
{
l = sh.lower_bound(cut);
r = l; l--;
sh.insert(cut);
mh.insert(cut-(*l));
mh.insert((*r)-cut);
mh.erase(mh.find((*r) - (*l)));
}
else
{
l = sv.lower_bound(cut);
r = l; l--;
sv.insert(cut);
mv.insert(cut - (*l));
mv.insert((*r) - cut);
mv.erase(mv.find((*r) - (*l)));
} printf("%I64d\n", (long long)(*mh.rbegin()) * (*mv.rbegin()));
} return ;
}

代码君

最后再说一点题外话:这次是只要删除multiset中一个元素,只要S.erase(S.find(val))就行了。

如果我们想要删除所有multiset中值为val的元素该怎么办?

有一个equal_range的成员函数,调用S.equal_range(val)就会返回一个pair<multiset::iterator, multiset::iterator>类型的值ret,它代表了一个区间,这个区间中就包含了multiset中所有值为val的元素。最后删除的时候,直接S.erase(ret.first, ret.second)

下面是http://www.cplusplus.com/reference/set/multiset/equal_range/ 中的实例:

 // multiset::equal_elements
#include <iostream>
#include <set> typedef std::multiset<int>::iterator It; // aliasing the iterator type used int main ()
{
int myints[]= {,,,,,};
std::multiset<int> mymultiset (myints, myints+); // 2 16 30 30 30 77 std::pair<It,It> ret = mymultiset.equal_range(); // ^ ^ mymultiset.erase(ret.first,ret.second); std::cout << "mymultiset contains:";
for (It it=mymultiset.begin(); it!=mymultiset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n'; return ;
}

代码君

CodeForces Round #296 Div.2的更多相关文章

  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. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...

  6. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

  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. win7 telnet命令无法使用

    很多做网络测试的同学发现安装win7后,无法使用telnet命令了,提示“telnet不是内部或外部命令,也不是可运行的程序”,但是很需要在win7中使用telnet工具,怎么办? 首先你要要确认你的 ...

  2. ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL/SQL Statement ignored 问题

    前段时间由于修改SMES系统,出现了一个问题. ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL ...

  3. 【转】获取android设备 id

    关于本文档 Android的开发者在一些特定情况下都需要知道手机中的唯一设备ID.例如,跟踪应用程序的安装,生成用于复制保护的DRM时需要使用设备的唯一ID.在本文档结尾处提供了作为参考的示例代码片段 ...

  4. Python Socket File Transfer

    I have a RPi which I intented to use it to crawl data. The development environment in RPi is very ba ...

  5. JS实现Web网页打印功能(IE)

    问题描述:     JS实现Web网页打印功能 问题解决:     这里主要使用WebBrowser控件的ExeWB在IE中打印功能的实现 WebBrowser介绍:         WebBrows ...

  6. 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon

    组合数学+容斥原理 Orz zyf-zyf 多重集组合数0.0还带个数限制?  ——>  <组合数学>第6章  6.2带重复的组合 组合数还要模P 0.0? ——> Lucas ...

  7. jQuery+css+div一些值得注意的常用语句

    一.div页面布局 一个好的页面布局很重要,这会让你写代码的时候层次分明: 以2列左侧固定右侧自适应宽度为例子: 这是HTML代码: <!DOCTYPE html PUBLIC "-/ ...

  8. Filter及FilterChain的使用详解(转)

    一.Filter的介绍及使用 什么是过滤器? 与Servlet相似,过滤器是一些web应用程序组件,可以绑定到一个web应用程序中.但是与其他web应用程序组件不同的是,过滤器是"链&quo ...

  9. TensorFlow 基本使用

    使用 TensorFlow, 你必须明白 TensorFlow: 使用图 (graph) 来表示计算任务. 在被称之为 会话 (Session) 的上下文 (context) 中执行图. 使用 ten ...

  10. 盘点 DevOps 世界的杰出女性(一)

    [编者按]IT 领域从来不缺乏杰出的女性存在,近日,DevOps.com 主编 Alan Shimel 盘点了 DevOps 领域的杰出女性,首期为六个,本文系 OneAPM 工程师编译整理. 以下为 ...