博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树状数组
阅读量:6092 次
发布时间:2019-06-20

本文共 3210 字,大约阅读时间需要 10 分钟。

Circle
Description

You are given n points and two circles. The radius of the circle will be dynamical. Your task is to find how many points are under both circles at each time.

A point is under a circle iff the point is strictly inside the circle or on the border of the circle.

Input Description
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases.
For each case, the first line contains two integers n, m.(1 <= n, m <= 100000) Means the number of points and the number of queries.
Next n lines each contains two integer x, y(0 <= x, y <= 80000), describe a point.
Next line contains four integers x1, y1, x2, y2 (0 <= x1, y1, x2, y2 <= 80000), describe the center of two circles.
Next m lines each line contains two integers R1, R2, describe the radius of two circles.(1 <= R1, R2 <= 100000)
Output Description
For each query, output the number of points under both circles.
Sample Input
14 40 00 11 01 10 0 2 21 11 1010 110 10
Sample Output
0304 碰见很多这样的题目了,哎,以为是几何题,题解出来了才发现是树状数组,多做做,多总结
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 10 using namespace std;11 12 #define mnx 10400013 #define ll long long14 #define inf 0x3f3f3f3f15 #define lson l, m, rt << 116 #define rson m+1, r, rt << 1 | 117 18 const int N = mnx;19 struct point{20 int x, y;21 point( int x = 0, int y = 0 ) : x(x), y(y) {}22 point operator - ( const point &b ) const {23 return point( x - b.x, y - b.y );24 }25 int length(){26 ll len = (ll)x * x + (ll)y * y;27 ll pt = sqrt( len );28 if( pt * pt < len ) pt++;29 return (int)pt;30 }31 bool operator < ( const point & b ) const{32 return x < b.x; 33 }34 }p[mnx], A, B;35 struct rad{36 int r1, r2, id;37 bool operator < ( const rad & b ) const{38 return r1 < b.r1;39 }40 }query[mnx];41 int bit[mnx];42 int sum( int x ){43 int ret = 0;44 while( x > 0 ){45 ret += bit[x]; x -= x & -x;46 }47 return ret;48 }49 void add( int i, int x ){50 while( i <= N ){51 bit[i] += x;52 i += i & -i;53 }54 }55 int ans[mnx];56 int main(){57 int cas;58 scanf( "%d", &cas );59 while( cas-- ){60 memset( bit, 0, sizeof(bit) );61 int n, m;62 scanf( "%d %d", &n, &m );63 for( int i = 0; i < n; i++ ){64 scanf( "%d %d", &p[i].x, &p[i].y );65 }66 scanf( "%d %d %d %d", &A.x, &A.y, &B.x, &B.y );67 for( int i = 0; i < n; i++ ){68 int dis1 = ( p[i] - A ).length();69 int dis2 = ( p[i] - B ).length();70 p[i] = point( dis1, dis2 );71 }72 sort( p, p + n );73 for( int i = 0; i < m; i++ ){74 scanf( "%d %d", &query[i].r1, &query[i].r2 );75 query[i].id = i;76 }77 sort( query, query + m );78 int j = 0;79 for( int i = 0; i < m; i++ ){80 while( j < n && p[j].x <= query[i].r1 ){81 add( p[j].y, 1 );82 j++;83 }84 ans[query[i].id] = sum( query[i].r2 );85 }86 for( int i = 0; i < m; i++ ){87 printf( "%d\n", ans[i] );88 }89 }90 return 0;91 }
View Code

  hdu 4417 Super Mario

题意:给定一段区间每个点有个高度。在m次询问中每次给出左右端点和可以到达的高度,统计有多少个是小于到达高度

做法:离线排序+树状数组。。把输入的每个点的按高度排序,再把询问保存起来,按照高度排序,然后一边插入树状数组一边统计。。

其实还可以在线做,用主席树做

View Code

 

转载于:https://www.cnblogs.com/LJ-blog/p/3906117.html

你可能感兴趣的文章
webapp返回上一页 处理
查看>>
新安装的WAMP中phpmyadmin的密码问题
查看>>
20172303 2017-2018-2 《程序设计与数据结构》第5周学习总结
查看>>
(转)HTML的代码(从朋友那转的,看着觉得会有用就转了)
查看>>
eclipse中将一个项目作为library导入另一个项目中
查看>>
Go语言学习(五)----- 数组
查看>>
Android源码学习之观察者模式应用
查看>>
Content Provider的权限
查看>>
416. Partition Equal Subset Sum
查看>>
centos7.0 64位系统安装 nginx
查看>>
数据库运维平台~自动化上线审核需求
查看>>
注解开发
查看>>
如何用 Robotframework 来编写优秀的测试用例
查看>>
Django之FBV与CBV
查看>>
Vue之项目搭建
查看>>
app内部H5测试点总结
查看>>
Docker - 创建支持SSH服务的容器镜像
查看>>
[TC13761]Mutalisk
查看>>
三级菜单
查看>>
Data Wrangling文摘:Non-tidy-data
查看>>