随笔分类 - 树状数组&& 线段树
摘要:Luck and LoveTime Limit: 10000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2438Accepted Submission(s): 627Problem Description世界上上最远的距离不是相隔天涯海角而是我在你面前可你却不知道我爱你―― 张小娴前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪,可是天文数字了啊,不知多少MM蜂拥而至,顿时万人空巷,连扫地的大妈都来凑热闹来了。―_―|||由于人数太多,Wiskey
阅读全文
摘要:Mobile phonesTime Limit:5000MSMemory Limit:65536KTotal Submissions:9263Accepted:4154DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered f
阅读全文
摘要:MatrixTime Limit:3000MSMemory Limit:65536KTotal Submissions:10544Accepted:3945DescriptionGiven an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N).We can change the matrix in the following w
阅读全文
摘要:Problem B: Ultra-QuickSortIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence9 1 0 5 4,Ultra-QuickSort produce
阅读全文
摘要:BillboardTime Limit: 20000/8000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1619Accepted Submission(s): 809Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the
阅读全文
摘要:题目:给定一个数字串0 - N-1,每次可以移动首位数字到末尾,求最少的逆序对的组合方式。先求出原序列的逆序对,再用数学公式算出最佳值。 假设有 10 个数,依题义为 0 - 9,那么首位为4的话,从首位移动到末尾产生新的逆序对为0 - 9中大于4的数字减去少于4的数。 代码如下:#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int N, num[5005];void getint( int &t ){ char c; while( c= getcha
阅读全文
摘要:以下代码G++超时,C++勉强过,果然是链式的伤不起啊!!!#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int N, M, rec[200010];struct Node{ int l, r, best; Node *lch, *rch; Node( int ll, int rr ) { l= ll, r= rr, best= 0, lch= rch= NULL; } int mid( ) { return ( l+ r )>> 1; }};in
阅读全文
摘要:该题也算是最基础的线段树了,由于没有很好的理解Lazy思想,导致前面为了写出一个正确的程序花了半天功夫啊。前面是这样想的,对于某一段区间,如果已经赋了值,那么后面的修改就在这个值上进行,例如前面如果1 - 3 赋为2,后面如果又有一次 2 - 3赋为1的话,那么就在 2- 3的区间上赋值为 -1,因为前面已经在1-3算作 2 了。虽说思路出来了,但后面一直还是WA,原因在于经过多次的更新后,有些应该被舍弃的值被重复利用了,比如上例中再出现一组1 - 3 赋值为3,后面的 2- 3区间值就不对了,于是又加了时间戳,最后写出来AC的代码也便是搓不可言了。#include <cstdio>
阅读全文
摘要:写的这个伪线段树花了一个下午,为什么说是伪线段树呢,因为这道题目其实并没有对一定域进行更新,而只是找的某个点,所以这里的程序在找的时候无论是要更新的结点还是经过的路径都统一的 " += update " 了,加油,今天晚上在写点题目,写一个完整版的出来。小结也就等到下个完整版再一一写出来。 代码如下:#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <queue>#include <algorithm&g
阅读全文
摘要:入门级的树状数组直接应用,题目内容可以用数组来来模拟,意思是对下标为1~N的数组动态进行修改和统计某一特定区间[a,b]的数据总和。 树状数组之所以会比普通示和表述的动态求和快,是因为其保留了存和(开辟数组保留多项的和)的特性,但是其并不像普通示和数组那样将数组的每一项的意义都看做一样的,树状数组中下标为[2^0],[2^1],[2^2]......的意义和普通数组一致,但其他的数组项则只是表示局部(左邻区域)的和值,例如下标为[3]单单表示第三个数据的值,下标为[6]的表示第五和第六个数据和,我们要明确,树状数组是利于处理动态求和的数据存储结构,意思是说他存储的数据是完整的。#include
阅读全文


浙公网安备 33010602011771号