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. c# 应用程序部署发布

    转自:http://blog.csdn.net/chenyujing1234/article/details/7558185 最近做了C#软件,发布给客户用时,发现客户运行不起来,原因是客户电脑上没有 ...

  2. JAVA里的String、Timestamp、Date相互转换(转)

    转自:http://blog.sina.com.cn/s/blog_6675493d0100lbfl.html Timestamp转化为String: SimpleDateFormat df = ne ...

  3. mysql memory

    mysql memory engine 创建: mysql> create table mt engine = memory select * from information_schema.t ...

  4. 一个有趣的 SQL 查询(查询7天连续登陆)

    一个有趣的 SQL 查询 一个朋友有这样一个SQL查询需求: 有一个登录表(tmp_test),包含用户ID(uid)和登录时间(login_time).表结构如下: . row ********** ...

  5. c++ 时间格式化

    struct tm tm_time; strptime(time.c_str(), "%Y%m%d %H:%M:%S", &tm_time); time_t tt = mk ...

  6. Ext学习-基础概念,核心思想介绍

    1.目标   本阶段的目标是通过学习一些基础知识来对EXTJS有个整体的了解,知道EXTJS的基础语法,核心设计思想等等 2.内容   1.基础部分学习   2.EXTJS类系统介绍   3.EXTJ ...

  7. 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别

    一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...

  8. win7旗舰版安装office2007后打开文件提示找不到proplusww.msi

    今天第一次打开2007的excel,出现错误如下: 解决办法: 转自:http://blog.163.com/huacai9420@126/blog/static/521585422011911524 ...

  9. Unity3D角色攻击范围判定和攻击判定

    原地址:http://www.unity蛮牛.com/blog-1801-479.html 第一种方法:运用点乘 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...

  10. 2016,除了 DevOps,企业还应该知道 CMDB!

    CMDB 是 Configuration Management Database(配置管理数据库)的简称,CMDB 存储与管理企业 IT 架构中设备的各种配置信息,它与所有服务支持和服务交付流程都紧密 ...