2014年百度之星程序设计大赛 - 初赛(第二轮)
树状数组貌似是考察点。我目前只会模拟,闲了再说。...
分类:
其他好文 时间:
2014-06-05 08:46:59
阅读次数:
201
题目来源:POJ 2155 Matrix
题意:开始矩阵都是0 2种操作 把某个子矩阵翻转 0变1 1变0 查询x y 是0还是1
思路:树状数组 记录翻转次数就行 奇数次是1 偶数次是0
这题是区间更新 点查询 向上求和 向下更新 而且是二维的
#include
#include
using namespace std;
const int maxn = 1300;
i...
分类:
其他好文 时间:
2014-06-05 01:59:00
阅读次数:
287
DescriptionInputOutputSample InputSample
Output12HINT一开始还想什么离线做,其实不用,空间足够,我们直接开100个二维树状数组,然后就行了但是如果c范围很大就离线做好一些 1 type 2
tree=array[0..300,0..300]...
分类:
Web程序 时间:
2014-06-03 12:26:54
阅读次数:
277
以前用树状数组做过一次,现在用线段树再刷一次。。。
首先必须先离散化。。。
然后建立2颗线段树,第一颗表示往左走,每个节点的值的分布。
第二颗表示往右走,每个节点的值的分布。
然后根据左右走的关系,判断出x,y的值。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include
#include
#inclu...
分类:
其他好文 时间:
2014-06-03 01:25:54
阅读次数:
315
这道题可以用线段树或者树状数组,我在网上看有些大神竟然没用线段树和树状数组就把这道题搞出来了。。汗。。。线段树:线段树不能更新到叶子,否则超时。代码:
1 #include 2 #include 3 #include 4 #include 5 #define N 100005 6 using...
分类:
其他好文 时间:
2014-05-25 23:17:40
阅读次数:
287
1.RMQ问题
RMQ (Range Minimum/Maximum Query):对于长度为n的数组A,回答若干询问RMQ(A,i,j)(i,jRMQ问题是指求区间最值的问题。最简单的方法,就是遍历数组直接搜索,但是这种方式时间复杂度是O(n)。对于数组长度较大,性能要求高的场景不适用。
2.ST(Sparse Table)算法
ST算法是一种更加高效的算法,以O(nlog...
分类:
其他好文 时间:
2014-05-25 22:28:29
阅读次数:
375
题目来源:POJ 2019 Cornfields
题意:求正方形二维区间最大最小值的差
思路:直接二维ST搞 试模版而已
#include
#include
#include
using namespace std;
const int maxn = 255;
int dp[maxn][maxn][8][8];
int dp2[maxn][maxn][8][8];
int a[...
分类:
其他好文 时间:
2014-05-25 10:21:07
阅读次数:
246
ST
int dp[maxn][20];
int a[maxn];
void RMQ_init(int n)
{
int i,j,k;
for(i = 1; i <= n; i++)
dp[i][0] = a[i];
k = (int) (log((double)n + 0.2) / log(2.0));
for(j = 1; j <= k; j++)
for(i =...
分类:
其他好文 时间:
2014-05-25 09:45:08
阅读次数:
227
题目链接:点击打开链接
题意:有两种操作,合并集合,查询第K大集合的元素个数。(总操作次数为2*10^5)
Treap模板(静态数组)
#include
#include
#include
#include
#include
const int maxNode = 500000 + 100;
const int inf = 0x3f3f3f3f;
struct Tr...
分类:
其他好文 时间:
2014-05-24 23:18:09
阅读次数:
522
设两线段为(x1,y1) ,(x2,y2),
若使两线段相交,需使x1y2||x1>x2&&y1 2 #include 3 #include 4 #define MAXH 1005 5
using namespace std; 6 7 int n, m, k; 8 struct mem{ 9 ...
分类:
其他好文 时间:
2014-05-24 12:43:55
阅读次数:
333