Buy Tickets(线段树)】的更多相关文章

线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, h…
[poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here…
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10478   Accepted: 5079 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a lo…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19725   Accepted: 9756 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year wa…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16607   Accepted: 8275 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year wa…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12930   Accepted: 6412 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year wa…
题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容易就确定了,那最后第二个人的位置也可以推(与最后一个人的位置无关)...依次就都可以确定所有的人了. 用前缀和的思想,要是这个人的位置确定了,那么就标记这个人位置的值为0,然后回溯更新,跟求逆序对个数的思想比较类似. 线段树: #include <iostream> #include <cs…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 22097   Accepted: 10834 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year w…
题意: 给你n次插队操作,每次两个数,pos,w,意为在pos后插入一个权值为w的数; 最后输出1~n的权值 题解: 首先可以发现,最后一次插入的位置是准确的位置 所以这个就变成了若干个子问题, 所以用线段树维护一下每个区间剩余多少位置可选 对于一个pos 如果左儿子的剩余超过当前位置,就递归进左子树 反之就相当于留出了左儿子剩余的位置,递归进右子树,当前位置变成pos-左儿子剩余位置 请注意是在后面插入 #include<cstdio> #include<algorithm> #…
题意  n个人排队  每一个人都有个属性值  依次输入n个pos[i]  val[i]  表示第i个人直接插到当前第pos[i]个人后面  他的属性值为val[i]  要求最后依次输出队中各个人的属性值 从头到尾看的话  队列是动态的   无法操作  可是反过来看时  pos[i]就能够表示第i个人前面有多少个空位了  然后想到了用线段树做就简单了  线段树维护相应区间还有多少个空位  每次把i放到前面刚好有pos[i]个空位的位置即可了  详细看代码 #include <cstdio> #d…