1001.Alice and Bob

签到题*1,只要x * 2 == n && y * 2 == m就满足条件。

 var
m, n, x, y : int64; begin
while not eof do begin
readln(m, n, x, y);
if (m = * x) and (n = * y) then writeln('YES') else writeln('NO');
end;
end.

1002.Bob and math problem

我真是WA的不行,但是很明显我的算法没有问题啊。。。

(2014/9/28 22:36更新 原来是Pascal的eof做的死,早知道以后不再也用P了><)

我的算法:统计0到9的个数,然后找出最小的奇数放到末尾,接着从9到0输出,最后输出选出的那个奇数。

中间要判断输出-1的情况:没有奇数;找出一个奇数以后只剩下0了。

 var
num : array[..] of longint;
n, ch, i, j, x : longint; function find : boolean;
var
i : longint;
flag : boolean; begin
flag := true;
for i := to do
if num[i] > then flag := false;
find := flag and (n <> );
end; begin
while not eof do begin
readln(n);
if n = then exit;//这句话没加我就会WA,不知道为啥子捏~
fillchar(num, sizeof(num), );
for i := to n do begin
read(x);
inc(num[x]);
end;
ch := ;
for i := to do begin
j := i * - ;
if num[j] > then begin
ch := j;
dec(num[j]);
break;
end;
end;
if (ch = ) or find then begin
writeln(-);
continue;
end;
for i := downto do
while num[i] > do begin
write(i);
dec(num[i]);
end;
writeln(ch);
end;
end.

1003.Boring count

这道题看了数据范围就知道要O(n)的算法,因为O(nlogn)的算法有点不大科学。。。

于是我来统计以每个字符s[j]为结尾的满足要求的字符串的个数,不妨设suff[i, j]表示s[i]到s[j]的子串。

又很明显如果suff[i, j]不满足条件了,则suff[i - 1, j]也不满足条件,若令f[j]表示以字符s[j]结尾的最左边满足条件的位置,则f[j]关于j是单调增的。

于是每次枚举j然后查找f[j], ans += j - f[j] +1即可。

 var
i, x, k, len, left, t1 : longint;
first, next, num, last : array[..] of longint;
s : ansistring;
T : longint;
ans : int64; begin
readln(T);
while T > do begin
dec(T);
ans := ;
readln(s);
readln(k);
len := length(s);
left := ;
fillchar(first, sizeof(first), );
fillchar(last, sizeof(last), );
fillchar(num, sizeof(num), ); for i := to len do begin
x := ord(s[i]);
if first[x] = then first[x] := i;
inc(num[x]);
next[last[x]] := i;
last[x] := i;
if num[x] > k then begin
dec(num[x]);
t1 := first[x];
first[x] := next[first[x]];
if t1 > left then left := t1;
end;
inc(ans, i - left);
end;
writeln(ans);
end;
end.

1004.Argestes and Sequence

看我来直播作死:

2014/9/28 22:17  1004在线BIT交到现在都是MLE,于是我把它删了,发誓明天一定要写出离线算法!

2014/9/28 22:51  1004在我无数的WA之后终于A掉了!

这道题一开始我想到的是线段树,后来发现是求段和于是树状数组(BIT)就可以搞定啦。

但是发现会无限MLE,于是需要一些奇怪的技巧:离线做。

因此我们做10次每次做一位即可。

于是我们现在只考虑某一位上的数如何行统计:

令a[i][j]表示前i个数中j出现的次数。于是操作是单点修改和求前缀和,明显拿BIT维护。

其实还可以分开0到9都做一次,这时候只要700k+(标程)的空间。但是给了3WK的空间就要用满嘛。。。

 var
ch : char;
t : longint;
n, m, i, j, di : longint;
bit : array[.., ..] of longint;
opt, l, r, d, p, x, a, b, c, ans : array[..] of longint; function lowbit(x : longint) : longint;
begin
lowbit := x and (-x);
end; procedure add(x, y, del : longint);
begin
while x <= n do begin
inc(bit[x, y], del);
inc(x, lowbit(x));
end;
end; function query(x, y : longint) : longint;
var
res : longint; begin
res := ;
if x <> then
while x > do begin
inc(res, bit[x, y]);
dec(x, lowbit(x));
end;
query := res;
end; procedure main;
begin
readln(n, m);
for i := to n do
read(a[i]);
readln;
for i := to m do begin
read(ch);
if ch = 'Q' then begin
opt[i] := ;
readln(l[i], r[i], d[i], p[i]);
end else begin
opt[i] := ;
readln(x[i], b[i]);
end;
end; for di := to do begin
fillchar(bit, sizeof(bit), );
c := a;
for i := to n do begin
add(i, a[i] mod , );
a[i] := a[i] div ;
end;
for i := to m do begin
if (opt[i] = ) then begin
add(x[i], c[x[i]] mod , -);
add(x[i], b[i] mod , );
c[x[i]] := b[i];
b[i] := b[i] div ;
end else
if d[i] = di then
ans[i] := query(r[i], p[i]) - query(l[i] - , p[i]);
end;
end;
for i := to m do
if opt[i] = then writeln(ans[i]);
end; begin
readln(t);
while t > do begin
dec(t);
main;
end;
end.

BestCoder Round #11 题解集合的更多相关文章

  1. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  3. BestCoder Round #60 题解链接

    题解  题目 1001 GT and sequence 注意先特判000的情况:如果读入的数据有000,那么去掉所有的000且最后答案和000取一个max. 剩下的正数显然全部乘起来比较优. 对于负数 ...

  4. BestCoder Round #11 (Div. 2)

    太菜,仅仅能去Div2.(都做不完 ORZ... 各自是 HDU: 5054pid=5054"> Alice and Bob 5055Bob and math problem 5056 ...

  5. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  6. BestCoder Round #90 A+B题解!

    BestCoder Round #90 A  Kblack loves flag 题意有点迷不造思路很简单但不造怎么求随机数,纠结了一会后直接粘上题目所给的代码稍加修改A了. const int _K ...

  7. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  8. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

随机推荐

  1. eclipse 设置jvm 内存

    Eclipse 中设置JVM 内存 今天在eclipse 中测试把文档转换为图片的时候,报出了下面的错误: java.lang.OutOfMemoryError: Java heap space 从上 ...

  2. iOS - OC NSProcessInfo 系统进程信息

    前言 @interface NSProcessInfo : NSObject NSProcessInfo 类中包含一些方法,允许你设置或检索正在运行的应用程序(即进程)的各种类型的信息. 1.获取系统 ...

  3. C++中关于new及内存地址的思考

    OJ题刷多了,每次都是直接分配内存,那么,你还记得怎么动态分配内存吗? ———————————————————————————————————— 我们知道,使用malloc/calloc等分配内存的函 ...

  4. andriod之摄像头驱动流程

    camera成像原理: 景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过DSP加工出来,然后在通过IO接口传输到CPU处理. 由于摄像头满足总线. ...

  5. Java中的数学运算BigDecimal

    Math类 package ch7; /** * Created by Jiqing on 2016/11/24. */ public class MathDemo { public static v ...

  6. jQuery DOM基础

    jQuery DOM基础 1.对元素内容的获取和修改: 表单用value(),普通元素用html()和text(). html()  html(value)设置和获取html内容,有html标签会自动 ...

  7. PHP 用文件流方式展示图片

    public function index(){ $img = 'http://img.pf.loc/static/images/2016/05/24/21d98edf98bd6c30afe1c838 ...

  8. Bootstrap段落(正文文本)

    一.Bootstrap段落特点 段落是排版中另一个重要元素之一.在Bootstrap中为文本设置了一个全局的文本样式(这里所说的文本是指正文文本): 1.全局文本字号为14px(font-size). ...

  9. HBase的shell命令行界面按退格键(Backspace)无法删除问题

    在HBase的shell命令行界面输入错误项按"退格键"删除,却怎么也删除不了: 解决办法: 第一步,修改SecureCRT的设置参数: 第二步,按"Ctrl+退格键(B ...

  10. stdlib标准库的常用API

    iOS 有如下四种随机数方法,下面以产生 [0,100) 的随机数为例: 1. srand((unsigned)time(0));  //不加这句每次产生的随机数不变 int i = rand() % ...