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. 3143: [Hnoi2013]游走 - BZOJ

    Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点, ...

  2. pom配置进行版本号统一管理

    在pom.xml中配置 <properties>在该配置中添加   <project.build.sourceEncoding>UTF-8</project.build. ...

  3. Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi

    Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi This spring, Kaggle hosted two competitions w ...

  4. Scrum敏捷开发简介

    Agile 敏捷开发实践中,强调团队的自我管理.在 Scrum 中,自我团队管理体现在每天的 Scrum 会议中和日常的协同工作,在每天的 Scrum 例会中,团队成员一般回答一下几个问题 : 昨天完 ...

  5. HDU 4509 湫湫系列故事——减肥记II(暴力模拟即可)

    看了题目后,没自己做,直接看别人题解了,这里转一下. 看了之后,突然想起scanf还可以按照自己写的格式输入数据啊,差点连这个都忘记了啊. 注意输入中时间可能有重复的. http://www.cnbl ...

  6. 用cxSelect插件补充一下回显过滤项功能

    这个在DJANGO里,最好在过滤之后,让用户知道自己过滤的选择.所以要定位默认值. 1,在HTML文件里显示默认值: <form class="uk-form" name=& ...

  7. Java Socket 使用BufferedWriter和BufferedReader要注意readLine 以及换行标志的发送

    当接收的类使用的是BufferedReader,发送的类是BufferedWriter的时候,要注意发送的一行要有换行标识符. 请看下面一个例子,服务器接收不到客户端的信息. 服务器: import ...

  8. Thread的第五天学习

    1.如果每个线程执行的代码相同,可以使用同一个Runnable对象,这个Runnable对象中有那个共享数据,例如:卖票系统就可以这么做! package com.thread.demo; publi ...

  9. leetcode 5 :Longest Palindromic Substring 找出最长回文子串

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  10. 第一个java程序(hdu 1001)

    //package yy;不能有 import java.util.*; public class Main {//必须为Main public static void main(String[] a ...