摘要:
题目链接题意: 有一字符串只包含0和1,然后又m组操作,I L R是将从L到R的字符进行翻转操作0变为1、1变为0,Q x表示询问第x的字符。思路: 我们只需要计算对询问的字符进行了多少次翻转,如果是偶数次,该字符变,否则翻转。对于区间的更新,我们可以使用线段树,不过对于这个题,因为只是对点的查询,而且每个节点的初始值都相同,为0,因此我们可以直接使用树状数组。下面是一个很巧妙的做法,而且很容易理解。用了树状数组的区间更新 单点查找(一般为单点更新 区间查找)例如 区间(2,4)加1则Updata(2,1) Updata(4+1,-1)实现了更新(2,4)的值而不改变其他值求Sum时即可得.. 阅读全文
posted @ 2013-04-12 18:58
xindoo
阅读(196)
评论(0)
推荐(0)
摘要:
题目链接DescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from theN(1 ≤N≤ 3,402) available charms. Each charmiin the supplied list has a weightWi(1 ≤Wi≤ 400), a 'desirability' factorDi(1 ≤Di≤ 阅读全文
posted @ 2013-04-12 16:54
xindoo
阅读(147)
评论(0)
推荐(0)
摘要:
题目链接DescriptionA train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the train. Therefore, the office of railroads decided to distribute three mini locomotives to each station. A mini locomotive can pull only a few passe 阅读全文
posted @ 2013-04-12 16:28
xindoo
阅读(159)
评论(0)
推荐(0)
摘要:
题目链接线段树解法#include #include using namespace std;const int maxn = 100010;struct node{ int l, r, mid, minn;}tree[maxn> 1; tree[o].mid = m; if (l == r) { tree[o].minn = a[l]; return ; } build(l, m, o tree[o].mid) return query(l, r, (o#include using namespace std;co... 阅读全文
posted @ 2013-04-12 13:24
xindoo
阅读(164)
评论(0)
推荐(0)

浙公网安备 33010602011771号