清华学堂 LightHouse
灯塔(LightHouse)
Description
As shown in the following figure, If another lighthouse is in gray area, they can beacon each other.

For example, in following figure, (B, R) is a pair of lighthouse which can beacon each other, while (B, G), (R, G) are NOT.

Input
1st line: N
2nd ~ (N + 1)th line: each line is X Y, means a lighthouse is on the point (X, Y).
Output
How many pairs of lighthourses can beacon each other
( For every lighthouses, X coordinates won't be the same , Y coordinates won't be the same )
Example
Input
3
2 2
4 3
5 1
Output
1
Restrictions
For 90% test cases: 1 <= n <= 3 * 105
For 95% test cases: 1 <= n <= 106
For all test cases: 1 <= n <= 4 * 106
For every lighthouses, X coordinates won't be the same , Y coordinates won't be the same.
1 <= x, y <= 10^8
Time: 2 sec
Memory: 256 MB
Hints
The range of int is usually [-231, 231 - 1], it may be too small.
视频里有讲解我尽然没看到,醉了。
就是求一下逆序对就行。
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
const int max_size = * 1e6;
LL y_val[max_size];
LL tmp_arry[max_size];
///加速代码,why 百度
const int SZ = <<;
struct fastio{
char inbuf[SZ];
char outbuf[SZ];
fastio(){
setvbuf(stdin,inbuf,_IOFBF,SZ);
setvbuf(stdout,outbuf,_IOFBF,SZ);
}
}io;
struct Point
{
LL x, y;
} p[max_size]; int cmp(const void *a, const void *b)
{
struct Point *c = (Point *)a;
struct Point *d = (Point *)b;
if(c->x != d->x)
return c->x - d->x;
else
return d->y - c->y;
} LL Merge(LL *arr, LL beg, LL mid, LL end, LL *tmp_arr)
{
memcpy(tmp_arr+beg, arr+beg, sizeof(LL)*(end - beg + ));
LL i = beg;
LL j = mid+;
LL k = beg;
LL inversion = ;
while(i <= mid && j <= end)
{
if(tmp_arr[i] <= tmp_arr[j])
arr[k++] = tmp_arr[i++];
else
{
arr[k++] = tmp_arr[j++];
inversion += mid - i + ;
}
} while(i <= mid)
arr[k++] = tmp_arr[i++];
while(j <= end)
arr[k++] = tmp_arr[j++];
return inversion;
} LL MergeInversion(LL *arr, LL beg, LL end, LL *tmp_arr)
{
LL inversions = ;
if(beg < end)
{
LL mid = (beg + end) >> ;
inversions += MergeInversion(arr, beg, mid, tmp_arr);
inversions += MergeInversion(arr, mid+, end, tmp_arr);
inversions += Merge(arr, beg, mid, end, tmp_arr);
}
return inversions;
} int main()
{
LL n;
cin >> n;
for(int i = ; i < n; i++)
{
cin >> p[i].x >> p[i].y;
} qsort(p, n, sizeof(p[]), cmp);
for(int i = ; i < n; i++)
{
y_val[i] = p[i].y;
} memcpy(tmp_arry, y_val, sizeof(LL)*n);
cout << n*(n-) / - MergeInversion(y_val, , n-, tmp_arry) << endl;
return ;
}
然后再对代码进行优化吧,我的这段过不了最后一个点。因为多做了排序操作,没必要。
清华学堂 LightHouse的更多相关文章
- 清华学堂 列车调度(Train)
列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...
- 清华学堂 Range
Descriptioin Let S be a set of n integral points on the x-axis. For each given interval [a, b], you ...
- 记2014“蓝桥杯全国软件大赛"决赛北京之行
5月29,30日 最终到了这一天.晚上有数据结构课,10点多的火车,我们就没有去上课,下午在宿舍里收拾东西,晚上8点左右从南校出发,9点半多到达火车站和老师学长学姐们会和. 第一次去北京,第一次买的卧 ...
- WEB入门三 CSS样式表基础
学习内容 Ø CSS的基本语法 Ø CSS选择器 Ø 常见的CSS样式 Ø 网页中3种使用CSS的方式 能力目标 Ø 理解CSS的 ...
- 【推荐】适合本科生的网络公开课(MOOC为主),不断更新……
题记:身在海大(湛江),是幸运还是不幸,每一个人有自己的定义.人生不能再来一次,唯有把握当下.提高自己,才可能在不能拼爹的年代靠自身实力前行.或许,我们做不了富二代.但我们每一个人.都有机会成为富二代 ...
- 教育O2O在学校落地,学堂在线瞄准混合式教学
(大讲台—国内首个it在线教育混合式自适应学习平台.) 进入2015年,互联网教育圈最火的词非“教育O2O”莫属.不断刷新的融资金额和速度,不断曝光的正面和负面新闻,都让教育O2O公司赚足了眼球.然并 ...
- 新上市Lighthouse专用芯片TS3633规格介绍
背景介绍 Valve 有远大的愿景.它决心要把 SteamVR 追踪系统推向世界,从虚拟现实里的空间定位,到机器人领域,Valve 想为各种环境下的跟踪应用提供支持. 上个月,Valve 方面宣布会把 ...
- HTML5学堂,感谢您一年的陪伴(上)
在HTML学堂将满一周岁之际,感谢再过去的一年里支持和关注它的每一个小伙伴.有了你们的支持,HTML5学堂才能更好的走下去.我们将会把这一年的积累重新体现在HTML5学堂的官网上.HTML5学堂将会全 ...
- 【Java】深深跪了,OJ题目Java与C运行效率对比(附带清华北大OJ内存计算的对比)
看了园友的评论之后,我也好奇清橙OJ是怎么计算内存占用的.重新测试的情况附在原文后边. -------------------------------------- 这是切割线 ----------- ...
随机推荐
- 一个ERP项目实施工程师的若干体会
本人在多年的工作中,参与了ERP的研发和实施,对ERP有较深的认识.在这里,根据自已的实施过程中的一些经历,把自已在实践中的一些体会贡献出来和大家共享,由于时间和精力所限,内容难免有不当之处,挂一漏万 ...
- 处理 input 上传图片,浏览器读取图片大小过程中遇到到的坑(兼容IE8\9)
为了 解决这个坑~ 已经 累傻了.. 周末再 写吧..
- @Controller和@RestController的区别?
@Controller和@RestController的区别?官方文档:@RestController is a stereotype annotation that combines @Respon ...
- 2015.4.21 实现一般免登陆,微博QQ分享,字体自适应等
1.实现一般的登录验证和免登陆: 解决方法:node方法代码,nodeJS实现的session模块,不完整,但能用,仅供参考. 语言无所谓,session的机制都是一样的,实现不一样而已,: 2. ...
- 关于 Word Splitting 和 IFS 的三个细节
在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...
- solr-web界面增加登录认证
目录 配置tomcat-user.xml 配置web.xml 界面展示 回到顶部 配置tomcat-user.xml 找到 tomcat 下 conf 文件下增加 tomcat-user.xml &l ...
- 第2月第5天 arc invocation getReturnValue
http://blog.csdn.net/zengconggen/article/details/38024625
- 02OC的类和对象
这章重点介绍OC的类以及对象,由于C语言是面向过程语言,而OC只是对于C语言多了一些面向对象的特性,所以OC相对于其他面向对象语言,例如C#.Java等没有那么多的语法特性,所以差别还是比较大的. 一 ...
- mrjob 使用 mongoldb 数据源【转】
最近做的事情是用mrjob写mapreduce程序,从mongo读取数据.我的做法很容易也很好懂,因为mrjob可以支持sys.stdin的读取,所以我考虑用一个python程序读mongo中的数据, ...
- PROJ4初探(转并整理格式)
PROJ4初探(转并整理格式) Proj4是一个免费的GIS工具,软件还称不上. 它专注于地图投影的表达,以及转换.采用一种非常简单明了的投影表达--PROJ4,比其它的投影定义简单,但很明显.很容易 ...