HDU_4456_二维树状数组】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=4456 第一道二维树状数组就这么麻烦,题目要计算的是一个菱形范围内的和,于是可以把原来的坐标系旋转45度,就是求一个正方形范围内的和,这里还涉及到坐标系平移和放大,由于题目数据较大,用了离散化来保存需要处理的点,放在h数组内,对应的二维树状数组存在tree数组内. #include<iostream> #include<cstring> #include<cstdio> #includ…
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, m; void init(int n, int m) { memset (c, 0, sizeof (c)); this->n = n; this->m = m; } void updata(int k, int x, int y, int z) { for (int i=x; i<=n;…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2901    Accepted Submission(s): 1454 Problem Description 给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Description Given 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…
Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 Description Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The…
D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this problem asks you for. You are given a matrix a with n rows and n columns. Initially, all values of the matrix are zeros. Both rows and columns are 1-based…
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但是我们处理一下就可以完美解决此问题.区间更新可以使用区间求和的方法,在更新的(x2,y2)记录+1,在更新的(x1-1,y1-1)-1(向前更新到最前方).单点求和就只需要与区间更新相反,向后求一个区间和.这样做的理由是:如果求和的点在某次更新范围内,我们+1但是不执行-1,否者要么都不执行,要么都…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Description Given 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…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Description Given 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…
题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部取反,1->0,0->1 2.Q x y 求n*n矩阵的(x,y)位置上的数 题解: 先看简单的: 给你一个初始全为0的长度为n的序列,有如下操作 1.C x y 把序列x到y位取反1->0,0->1 2.Q x 求序列第x位的数 做法很简单,设计一个数组a[],a[1..i]的和表示…
Description Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gathering of cows from around the world. MooFest involves a variety of events including haybale stacking, fence jumping, pin the tail on the farmer,…
Description Given 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 way. Given a rectangle whose upp…
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of…
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1)修改某个位置的数字:(2)求某个子矩阵中某个数字的个数. 思路:二维树状数组的操作看起来跟一维的差不多,只是循环改为两重而已.主要操作有:(1)增加某个位置的值:(2)询问[1,1,x,y]子矩阵的和.利用(2)操作以及区间的减法操作我们能求出任意一个子矩阵的数字和.这道题用a[i][x][y]来记…
题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn.net/xiamiwage/article/details/8030273 思路: 二维线段树,一维线段树的成段更新需要lazy. 引申到二维线段树应该需要一个lazy,一个sublazy,可是这里什么都不用.    奇妙之处在于这题的操作是异或,当某一段区间需要异或操作时候, 不必更新到它所有的…
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio.h> #include <string.h> #include <iostream> using namespace std ; ][] ; int main() { int N ,S,T ,W,H; while(scanf("%d",&N) !=…
前段时间遇到线段树过不了,树状数组却过了的题.(其实线段树过得了的) 回忆了下树状数组. 主要原理,还是二进制位数,每一项的和表示其为它的前((最后一位1及其后)的二进制数)和,可从二进制图来看.(用线段树想一想其实只是线段树编号不同而已,本质类似) 写了下二维树状数组,几乎和一维相同,也没必要不同. #include <cstdio> #include <cstring> ][]; inline int lowbit(int x) { return x&(-x); } v…
树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: 在一个“打鼹鼠”的游戏中,鼹鼠会不时地从洞中钻出来,不过不会从洞口钻进去(鼹鼠真胆大……).洞口都在一个大小为n(n<=1024)的正方形中.这个正方形在一个平面直角坐标系中,左下角为(0,0),右上角为(n-1,n-1).洞口所在的位置都是整点,就是横纵坐标都为整数的点.而SuperBrother…
P1716 - 上帝造题的七分钟 From Riatre    Normal (OI)总时限:50s    内存限制:128MB    代码长度限制:64KB 背景 Background 裸体就意味着身体. 描述 Description “第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵.第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的操作.第三分钟,k说,要能查询,于是便有了求给定矩形区域内的全部数字和的操作.第…
Description Given 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 way. Given a rectangle whose upp…
Description Suppose 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 from 0 to S-1. Each square contain…
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define BITMAX 1002 //数组大小 typedef int valueType; //元素类型定义 valueType BITree[BITMAX][BITMAX]; //二维树状数组,初始化 /* 2^k k表示节点编号 x 二进制末尾…
Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 785    Accepted Submission(s): 335 Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the p…
Description Suppose 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 from 0 to S-1. Each square contain…
Suppose 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 from 0 to S-1. Each square contains a base sta…
Given 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 way. Given a rectangle whose upper-left corn…
考试最后半个小时才做这道题.十分钟写了个暴力还写挂了..最后默默输出n.菜鸡一只. 这道题比较好看出来是动规.首先我们要明确一点.因为能拔高长度任意的一段区域,所以如果从i开始拔高,那么一直拔高到n比一直拔高到j更优.因为j~n变高了对于答案是有利的. 我们定义f[i][j]表示到第i个点前面拔高j次的最大剩余数.在i点的高度为hei[i]+j(因为前面拔高j次,最终都会拔高到n).所以我们要找在高度小于hei[i]+j,次数小于j里面最大剩余数+1去更新.而找这个有限制的二维前缀最大值,可以用…
                                                                                                               Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15125   Accepted: 5683 Description Given an N*N matrix A, whose element…
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 111 Accepted Submission(s): 54   Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky.To make the problem…
Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 148 Problem Description Given the finite multi-set A of n pairs of integers, an another finite multi-set B …