二维

Stars POJ - 2352 二维偏序问题CDQ分治

两盒软妹~` 提交于 2019-11-27 05:55:11
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars. For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star

二维动态数组问题

谁说我不能喝 提交于 2019-11-27 04:12:15
声明double (*p)[4] = new double[5][4]; 可以直接 delete[] p; 要是这样声明 double *p[5]; 好像就得这样 int i; for(i=0;i<5;i++) p[i]=new double [4]; for(i=0;i<5;i++) delete[] p[i]; int **a=new [n][3];delete []a;内存释放了,也不能用a访问元素 int (*a)[3]=new int [n][3];delete []a;内存释放了,但能通过a访问元素 转载于:https://www.cnblogs.com/chengtalent/archive/2008/04/21/1164411.html 来源: https://blog.csdn.net/weixin_30793643/article/details/99367550

二维前缀和、差分习题集

佐手、 提交于 2019-11-27 04:04:11
https://blog.csdn.net/K_R_forever/article/details/81775899 1、 HDU6514 Monitor 先给p个矩形,再给q个矩形,q个矩形中若能被p个矩形所在区域包含则YES,否则NO。转化为二维差分问题。 1 #include<iostream> 2 #include<sstream> 3 #include<fstream> 4 #include<algorithm> 5 #include<cstring> 6 #include<iomanip> 7 #include<cstdlib> 8 #include<cctype> 9 #include<vector> 10 #include<string> 11 #include<cmath> 12 #include<ctime> 13 #include<stack> 14 #include<queue> 15 #include<map> 16 #include<set> 17 #define mem(a,b) memset(a,b,sizeof(a)) 18 #define random(a,b) (rand()%(b-a+1)+a) 19 #define ll long long 20 #define ull unsigned long long 21 #define e 2

洛谷 P 2663 (二维费用背包)

…衆ロ難τιáo~ 提交于 2019-11-27 03:48:17
题目描述 班级要组织一场综合能力竞赛,全班同学(N(100以内)个,N是偶数)分成两队互相竞争。老师找到了越越并给了越越一张全班同学综合能力测试的成绩,要求他从全班同学中选出一半(他自己也可能被选),并要求这些同学综合能力测试的成绩之和在不超过班级总分一半的前提下尽量达到最高。这样分成的两队实力是最平均的。越越堆着满脸的笑容找到了你,你就帮他写一个程序吧。 输入格式 第一行:学生个数N;第二行开始的N行每行一个同学的综合能力测试的成绩。 输出格式 输出一个数:N/2个同学的综合能力测试的成绩之和在不超过班级总分一半的前提下尽量达到的最高值。 输入输出样例 输入 #1 复制 8 77 77 56 77 84 77 56 46 输出 #1 复制 273 说明/提示 样例解释:总分550;总分的一半275;选择4名同学56 77 84 56 77 达到总分273;273是不超过275的最大值。(另一队的和是277)两队实力最接近。 二维费用背包: 多开一维表示另一维费用,在一维费用背包的基础上 二重for是时候同时考虑两个费用即可 (丑陋的) Code: #include<bits/stdc++.h> #define debug(x) cout << "[" << #x <<": " << (x) <<"]"<< endl #define pii pair<int,int>

P2742 【模板】二维凸包 / [USACO5.1]圈奶牛Fencing the Cows

风格不统一 提交于 2019-11-27 03:40:28
凸包模板 #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cstring> #include <queue> #include <cmath> using namespace std; const int maxn = 1e4 + 10 ; struct node { double x , y ; }a[maxn]; bool cmp(node x ,node y) { if(x.x!=y.x) return x.x < y.x ; else return x.y < y.y ; } node p[maxn] ; double dfs(node a ,node b,node c,node d) { double x1 = b.x - a.x ; double y1 = b.y - a.y ; double x2 = d.x - c.x ; double y2 = d.y - c.y ; return x1*y2-x2*y1; } double qqq(node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int main() { int n ; scanf("%d"

POJ2019 Cornfields 二维ST表

时光毁灭记忆、已成空白 提交于 2019-11-26 20:35:56
网址: https://vjudge.net/problem/POJ-2019 题意: 给出一个矩阵,求左下角坐标为$(x,y)$,长度为$b$的正方形的包含的数的最大值和最小值。 题解: 一、二维ST表: 一维$ST$表可以快速处理一维$RMQ$问题,这次是二维问题,好,那就上二维$ST$表,构造方法和一维的类似。开一个四维数组,第一维第三维管横行,第二维第四维管纵行即可(反过来也行)。然后处理完之后按照类似于一维$ST$表一样查询,查询四个小矩阵的最值就行,然后取最值,具体看代码。 AC代码: #include <cstdio> #include <cmath> using namespace std; #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) int mat[255][255]; int maxn[255][255][8][8]; int minn[255][255][8][8]; int maxm(int a,int b,int c,int d) { if(a<b) a=b; if(a<c) a=c; if(a<d) a=d; return a; } int minm(int a,int b,int c,int d) { if(a>b) a=b; if(a>c) a=c; if(a>d) a=d;

一维,二维,三维数组,vector 初始化

自闭症网瘾萝莉.ら 提交于 2019-11-26 19:44:27
1. 用memset初始化数组: 1)按照字节赋值 2)头文件在<cstring>中 注:由于memset函数是按照字节赋值的,所以对int型数组用该函数时,只能是0或-1,否则会出错,这里,不管数组是多少维的,语法均为: int dp[84][84][84][2]; memset(dp, 0, sizeof(dp)); //只能赋值0或-1 2. fill 初始化vector和数组: 1)按照变量类型单元赋值,将区间 [first, end) 中的每个单元都赋为同一个值。 2)头文件在<algorithm>中 // fill algorithm example #include <iostream> // std::cout #include <algorithm> // std::fill #include <vector> // std::vector int main () { std::vector<int> myvector (8); // myvector: 0 0 0 0 0 0 0 0 std::fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0 std::fill (myvector.begin()+3,myvector.end()-2,8); //

谈谈 C++ 内存管理

对着背影说爱祢 提交于 2019-11-26 17:38:49
有多少个new就有多少个delete 二维动态数组的写法 首先开辟第一维的空间,第一维是char型的指针 char **s = new char *[ 182 ]; 在第一维的基础上,开辟第二维的空间,第二维是不定长度的char型 s[nCounts] = new char [str.length()]; 释放二维动态数组时,规则是由内到外的,先释放第二维的空间,最后再释放第一维的空间 for ( int i = 0 ; i < nCounts; ++ i) { delete[] s[i]; // delete[col] s[i]; s[i] = NULL; } delete[] s; // delete[row] s; s = NULL; s是二维指针,(声明)定义在main函数内,既然定义时在函数内,那么s指针就存放在内存中的栈区域中,使用new动态开辟的空间是在堆区域,堆区域用于存放数据,当然,每个数据都有它的内存地址,因此数据的地址是堆中的某一块地址,而栈中的s只是一个指针,这个指针指向堆区域的指定一块地址,当使用delete释放第二维的空间时,实质是回收堆上的虚拟地址块,而栈内的指针s并无发生变化 实现代码: 1 /// : handleString 2 #include <cstdlib> 3 #include < string > 4 #include <vector

UVA 11019 - Matrix Matcher(二维hash)

℡╲_俬逩灬. 提交于 2019-11-26 12:12:56
UVA 11019 - Matrix Matcher #include <bits/stdc++.h> using namespace std; #define rint register int #define rll register long long typedef long long ll; const int maxn = 1e3 + 100; const int base1 = 233, base2 = 2333; char a[maxn][maxn], b[maxn][maxn]; unsigned long long ha[maxn][maxn], hb[maxn][maxn]; int main() { freopen("in.txt", "r", stdin); rint _; scanf("%d", &_); while (_--) { rint n, m, x, y; scanf("%d %d", &n, &m); for (rint i = 1; i <= n; i++) scanf("%s", a[i] + 1); scanf("%d %d", &x, &y); for (rint i = 1; i <= x; i++) scanf("%s", b[i] + 1); register unsigned long long p1 = 1, p2 = 1;