Codeforces #256 Div.2
B. Suffix Structure
1. 先判断s去掉一些元素是否能构成t,如果可以就是automaton
判断的方法也很简单,two pointer,相同元素同时++,不相同s的指针++,如果t能全找到,那么s能够去掉元素构成t。
bool f(string s, string t) {
int i = 0, j = 0;
while (i < s.size() && j < t.size()) {
if (s[i] == t[j]) {
i++;
j++;
} else {
i++;
}
}
if (j == t.size()) return true;
else return false;
}
2. 对s和t排序,如果s和t相等,那么就是array
3. 如果s和t排序之后还是不相等,但是s可以通过去掉一些元素构成t,那么就是both
4. 否则,就是need tree
C. Painting Fence
D. Multiplication Table
矩阵,第(i, j)格子中是i*j,求在矩阵中的第k大数。
通过二分答案来实现,假设第k个数的值为val,我们可以发现对于矩阵来说,每一行也都是有序的,所以我们用O(min(m,n))的遍历可以找到所有行(列)中,小于等于val的数之和。
具体对于第 r 行来说,这一行小于等于val值的数量为min(val/r, 列的个数).
那么二分的具体过程如下:
int64 lo = 1, hi = n*m;
while (lo <= hi) {
int64 md = lo + (hi-lo)/2;
if (f(md) < k) lo = md+1;
else hi = md-1;
}
cout << lo << endl;
进行判断的方法:
int64 f(int64 k) {
int64 r, w;
if (n < m) {r = n; w = m;}
else {r = m; w = n;}
int64 cnt = 0;
for (int64 i = 1; i <= r; i++) {
cnt += min(k / i, w);
}
return cnt;
}
Codeforces #256 Div.2的更多相关文章
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- codeforces #577(Div.2)
codeforces #577(Div.2) A Important Exam A class of students wrote a multiple-choice test. There are ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
随机推荐
- Lua 5.1 参考手册
Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 云风 译 www.codingno ...
- (Forward) Music Player: From UI Proposal to Code
Some developers have difficult to code when the UI proposal is a bit “sophisticated” or “complex”. M ...
- C#占位符和格式化字符串
static void Main() { string c=Console.ReadLine(); string d=Console.ReadLine(); Console.WriteLine(c+& ...
- MapReudce中常见join的方案
两表join在业务开发中是经常用到,了解了大数据join的原理,对于开发有很大的好处. 1.reduce side join reduce side join是一种简单的join的方法,具体思想如下: ...
- 无法连接到已配置的开发web服务器
http://jingyan.baidu.com/article/29697b91099847ab20de3c8b.html 这是防火墙造成的,将防火墙关闭即可
- 邮件江湖群狼环伺 U-Mail邮件系统防狼有术
小时候听过一首儿歌<小兔子乖乖>,里面说到有条恶狼,常常冒充小兔子的“妈妈”,要求小兔 子开门,但小兔子谨守妈妈的训诫,就是不开门,直到辨别出妈妈在窗外的声音,才打开房门.如果我们将一些似 ...
- ZOJ 2770火烧连营——差分约束
偶尔做了一下差分约束. 题目大意:给出n个军营,每个军营最多有ci个士兵,且[ai,bi]之间至少有ki个士兵,问最少有多少士兵. ---------------------------------- ...
- (十一) 一起学 Unix 环境高级编程 (APUE) 之 高级 IO
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...
- FragmentTabHost
FragmentTabHost public class FragmentTabHost extends TabHost implements TabHost.OnTabChangeListener ...
- 比较两个Long对象值
比较两个Long对象的值是否相等,不可以使用双等号进行比较,(long int Integer可以用双等号进行比较)可以采用如下方式: 1.使用equals方法进行比较 Long a=new Long ...