离散化求RECT1】的更多相关文章

本文转载至点击打开链接 #include<stdio.h> struct node{ int x1,y1,x2,y2,c; }; struct node s[1010]; int px[2010],py[2010],ux[10010],uy[10010],p[10000]; short a[2010][2010],c[2510]; int main(){ int i,j,k,m,n; scanf("%d%d%d",&n,&m,&k); for(i=1…
3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MB Submit: 2171  Solved: 891 [Submit][Status][Discuss] Description Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是加密过的,只能用Mato自己写的程序才能访问.Mato每天随机选一个区间[l,r],他今天就看编号在此区间内的这些资料.M…
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数相加 因为只有后面的数比自己笑才能交换 但是暴力求逆序数也会超时 于是用树状数组求 从最后往前看 每次求sum相加 但是数据的范围根本开不出来树状数组... 但是由于n最多只有五十万 所以把它离散化一下 把这n个数变成1~n 技巧就是先按大小排序 然后把他们变成1~n 然后按照结构体中的顺序再排回来…
题意:给出一个序列,求至少需要用到多少次操作,才能将序列从小到大排序. 思路: 数据量很大,n<500000,所以用冒泡模拟是超时的. 接下来就想到了求顺序数,总共需要交换的次数为每个数后面有多少个小于它的数的累加和. 如9 1 0 5 4,9后面比它小的有4个,1后面比它小的有1个,5后面比它小的有1个,总共为6个,即为答案. 求顺序数自然而然就是想到用树状数组. 但是这里有一点,那就是整数是0~999999999,数据太大,开不了那么大的数组. 由于n最多只有500000,所以最多有50万个…
http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会树状数组求逆序数的话,这个推一下就能出结果: 做法: 1.离散化,由于a[i]能够达到1e9 2.插入a[i]的时候,记录x[i]=i-sum(a[i]); a[i]之前比a[i]大的有x[i]个 3.插入完毕后,求a[i] 之后比a[i]小的数的个数y[i] ans=segma(x[i]*y[i])   注…
对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们通过树状数组可以明显提高时间效率. 我们可以按照排列的顺序依次将数字放入树状数组中,并依次更新预与之相关联的树状数组元素.那么在将其更新完毕后,我们知道每个数对应的树状数组元素的左边的数肯定比它小,我们在以序列顺序依次更新树状数组时,如果有值在它前面出现,那么它对应的树状数组元素(在这个题目里存放的…
题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形下面那条边则插入到线段树中,遇到矩形上面的边则将相应的边删除掉 根据线段树当前的状态统计长度 第二点是本题的核心思想,偶再举个例:   第一次求出的部分很好理解. 第二次求出的为什么会少了中间那部分.那是因为插入的新线段覆盖了第一条,此时线段树返回的长度是新的那一条的长度,将这个值再减去上次的就少了…
In 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 sequence 9 1 0 5…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11551    Accepted Submission(s): 4906 Problem Description There are several ancient Greek texts that contain descriptions of the fabled…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1次的长度变量即可 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> using namespace std;…
题目链接: D - Coconuts  HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点分成多个联通块,然后问你白色联通块的个数和每一个连通块里面白色的点的个数. 具体思路:输入的点坐标比较大,但是个数比较小,所以离散化坐标就可以了.标记每一个整块里面的白色的点的个数就可以了. AC代码: #include<bits/stdc++.h> using namespace std; #…
/*第一道离散化的题目,虽然是水题,不过还是很高兴...*/ #include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct rect { double x1,x2,y1,y2; }; #define max 103<<1 rect a[max>>]; double x[max],y[max]; bool flag[max][max]; int…
#include<cstdio> #include<map> #include<algorithm> using namespace std; ; struct Node { double x,yl,yh; int w; bool operator<(Node t)const { return x<t.x; } }edge[N]; struct { int l,r,cover; }tr[N]; double ys[N]; void build(int u,i…
题目链接:http://poj.org/problem?id=1151 很经典的题目,网上有很多模板代码,自己理解了一天,然后很容易就敲出来了... 代码: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #define maxn 110 using namespace std; int n; class nod…
点我看题目 题意 : 就是给你n个矩形的最左下角和最右上角的点的坐标,然后将这n个矩形的面积求出来. 思路 : 离散化求矩形面积并.离散化具体介绍.将横纵坐标离散开来分别存,然后排序,也可以按照黑书上411页写的两个算法中,有一个说是用二分,效率比较好,不过我用的不是二分,而是普通的循环查找. #include<iostream> #include <algorithm> #include <string.h> #include <stdio.h> usin…
题目链接:POJ 2299 Ultra-QuickSort Description In 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 ascend…
模板题,树状数组加上离散化求逆序对. 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int N=5e5+10; 5 int n,a[N],b[N],c[N]; 6 LL ans; 7 8 int lowbit(int x){ 9 return x&(-x); 10 } 11 12 void ins(int x){ 13 while(x<=n){ 14 c[x]++;…
http://acm.hdu.edu.cn/showproblem.php?pid=4911 一场多校的签到题,树状数组离散化求逆序数 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; typedef __int64 ll ; int n,k ; ],b[] ; struct node { int num,id…
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include<stack> #include<math.h> #include<map> using namespace…
思路: 以y的值进行离散化 根据x的值 对每一条y轴边进行处理,如果是"左边"则插入,是"右边"则删除. /* 扫描线+线段树+离散化 求多个矩形的周长 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include…
开始逐渐习惯被多校虐orz  菜是原罪 1004  Game    (hdoj 6312) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 虽然披着博弈的外壳 但是也算是结论题 一开始开题的时候一看到博弈就不想写了 但是大佬们过题太快了 所以想到可能是结论题 题意:有A和B两个人可以对一个1-n的全排列进行操作 每一次都可以删去一个数和它所有质子 A和B轮流进行操作 先删光全排列为赢 A先手 给出n 判断A的输赢 因为每一次删数操作都会删去1…
http://poj.org/problem?id=2299 Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 62894   Accepted: 23442 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct inte…
瘋耔C++笔记 欢迎关注瘋耔新浪微博:http://weibo.com/cpjphone 参考:C++程序设计(谭浩强) 参考:http://c.biancheng.net/cpp/biancheng/cpp/rumen_8/ 博客原文:http://www.cnblogs.com/Ph-one/p/3974707.html 一.C++初步认识 1.C++输入.输出.头文件解释 #include<iostream> using namespace std ; int mian() { cout…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为这题中的数列有重复的而且范围特别大,所以要进行离散化,离散化的方法是, 首先按照输入的数字排个序,然后把整个数列扫一遍,得出每个数字离散化的结果,然后再按照输入的顺序把顺序调整回来就OK 了.线段树部分就不说了. #include<cstdio> #include<cstring> #…
DQUERY - D-query #sorting #tree English Vietnamese Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elements in the…
Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5101    Accepted Submission(s): 2339 Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping abilit…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47905   Accepted: 13903 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin…
Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88994#problem/J Description The mafia is finally resting after a year of hard work and not so much money. Mafianca, the little mascot of the…
题目链接:http://poj.org/problem?id=2299 Description In 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…