【题目分析】

刚开始想的是KD-Tree去暴力求解。

写了半天还没有暴力得的分数多(说好的nlogn呢)

直接按照四个维度排序。

然后扫一遍,用bitset去维护,然后对于四个维度小于一个询问的结果取一个交就可以了。

Bitset大法好。

【代码】

垃圾KD-Tree

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath> #include <set>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue> using namespace std; #define maxn 500005
#define mlog 16
#define F(i,j,k) for (int i=j;i<=k;++i)
#define inf (1e18) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} struct node{double d[4],mn[4],mx[4];int siz,l,r;}t[maxn],now;
int n,q,D,rt,tot=0,m;
bool operator < (node x,node y){return x.d[D]<y.d[D];} void update(int k)
{
F(i,0,3)
{
t[k].mx[i]=max(max(t[k].d[i],t[t[k].l].mx[i]),t[t[k].r].mx[i]);
t[k].mn[i]=min(min(t[k].d[i],t[t[k].l].mn[i]),t[t[k].r].mn[i]);
}
t[k].siz=t[t[k].l].siz+t[t[k].r].siz+1;
} int build(int l,int r,int dir)
{
int mid=(l+r)/2;
D=dir;
nth_element(t+l,t+mid,t+r+1);
t[mid].siz=1;
F(i,0,3) t[mid].mx[i]=t[mid].mn[i]=t[mid].d[i];
t[mid].l=mid>l?build(l,mid-1,(dir+1)%4):0;
t[mid].r=mid<r?build(mid+1,r,(dir+1)%4):0;
update(mid);
return mid;
} bool in(int o)
{
int flag=1;
F(i,0,3)
{
{
if (t[o].mx[i]>=0&&t[o].mx[i]<=now.d[i]);
else flag=0;
}
{
if (t[o].mn[i]>=0&&t[o].mn[i]<=now.d[i]);
else flag=0;
}
}
return flag;
} void print(int o){
if (!o) return;
printf("%d t[o].mn[0]=%f t[o].mn[1]=%f t[o].mx[0]=%f t[o].mx[1]=%f l :%d r: %d\n",o,t[o].mn[0],t[o].mn[1],t[o].mx[0],t[o].mx[1],t[o].l,t[o].r);
print(t[o].l);
print(t[o].r);
} bool din(int o)
{
int flag=1;
F(i,0,3)
{
if (t[o].d[i]>=0&&t[o].d[i]<=now.d[i]);
else flag=0;
}
return flag;
} bool out(int o)
{
int flag=1;
F(i,0,3)
{
if ((t[o].mx[i]>now.d[i]&&t[o].mn[i]>now.d[i])||(t[o].mx[i]<0&&t[o].mn[i]<0));
else flag=0;
}
return flag;
} int query(int o)
{
if (!o) return 0;
if (in(o)){return t[o].siz;}
else
{
int ret=0;
if (din(o)) ret+=1;
if (t[o].l)
{
if (out(t[o].l)); else ret+=query(t[o].l);
}
if (t[o].r)
{
if (out(t[o].r)); else ret+=query(t[o].r);
}
return ret;
}
} int main()
{
Finout();
F(i,0,3) t[0].mx[i]=inf,t[0].mn[i]=-inf;
scanf("%d",&m);n=1;
F(i,1,m)
{
int flag=1;
F(j,0,3)
{
scanf("%lf",&t[n].d[j]);
if (t[n].d[j]<0) flag=0;
}
if (flag) n++;
}
n--;
rt=build(1,n,1);
scanf("%d",&q);
F(i,1,q)
{
int flag=1;
F(j,0,3)
{
scanf("%lf",&now.d[j]);
if (now.d[j]<0) flag=0;
}
if (flag) printf("%d\n",query(rt));
else printf("0\n");
}
}

有趣的Bitset

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
#define maxn 30010
#define F(i,j,k) for (int i=j;i<=k;++i)
int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
bitset<maxn> b[maxn],now;
struct node{double d[4];int id;}a[maxn],q[maxn];
int n,m,D;
bool cmp(node x,node y){return x.d[D]<y.d[D];}
int main()
{
scanf("%d",&n);
F(i,1,n)
{
scanf("%lf%lf%lf%lf",&a[i].d[0],&a[i].d[1],&a[i].d[2],&a[i].d[3]);
a[i].id=i;
}
scanf("%d",&m);
F(i,1,m)
{
scanf("%lf%lf%lf%lf",&q[i].d[0],&q[i].d[1],&q[i].d[2],&q[i].d[3]);
q[i].id=i;
b[i].set();
}
F(i,0,3)
{
D=i;
sort(a+1,a+n+1,cmp);
sort(q+1,q+m+1,cmp);
now.reset();
int p=1;
F(j,1,m)
{
while (p<=n&&a[p].d[i]<=q[j].d[i]) now[a[p].id]=1,p++;
b[q[j].id]&=now;
}
}
F(i,1,m) printf("%d\n",b[i].count());
}

  

Tsinsen 1485 Catch The Penguins 抓企鹅 ——Bitset的更多相关文章

  1. 清澄 A1485. Catch The Penguins 抓企鹅

    试题来源 2013中国国家集训队论文答辩 问题描述 Xyz带着他的教徒们乘着科考船一路破冰来到了南极大陆,发现这里有许许多多的企鹅.邪恶的Xyz想要抓很多企鹅回去开动物园,当宠物玩.但动物保护协会很快 ...

  2. B - Catch That Cow (抓牛)

    B - Catch That Cow Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. 用正则表达式抓取网页中的ul 和 li标签中最终的值!

                获取你要抓取的页面 const string URL = "http://www.hn3ddf.gov.cn/price/GetList.html?pageno=1& ...

  4. C# 中异常抛出捕获机制--throw / try,catch,finally

    try { messagebox.show("true"); } catch { messagebox.show("false"); } finally { m ...

  5. java之try catch finally

    try{ }catch(Exception e){ }finally{ } java异常处理在编程中很常见,将可能抛出异常的语句放在try{}中,若有异常抛出,则try{}中抛出异常语句之后的语句不再 ...

  6. UE4 Android打包 问题 记录笔记

    问题一:error: expression result unused [-Werror,-Wunused-value] 虽然看了输出日志知道了这行沉余代码删掉就行,但是不是很懂这个地方报错意义. 问 ...

  7. 原来还有这样的记词方法_Java版记不规则动词_博主推荐

    昨天在看一本英语书的不规则动词的时候,突然产生的灵感:就是想把这样记单词简单方式,用程序代码实现,然后,使用户可以与之进行交互 这样,在用户背不规则动词的时候就会轻松把它给记住.基于这一点,于是我就思 ...

  8. Jdbc 事务

    package com.j1; import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.Prep ...

  9. Javaweb 第15天 web练习和分页技术

    第15天 web练习和分页技术 复习day14内容: 学习新技术的思路? 分析功能的思路? 使用queryRunner操作数据库的步骤? ResultSetHandler接口常用实现类(三个重点)? ...

随机推荐

  1. css布局两边固定中间自适应的四种方法

    第一种:左右侧采用浮动 中间采用margin-left 和 margin-right 方法. 代码如下: <div style="width:100%; margin:0 auto;& ...

  2. Codeforces Round #318 (Div. 2) C Bear and Poker (数学)

    简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...

  3. 转载:收费版APP三年总结(个人经验+数据图分享)

    各位朋友好,apop感觉这里的朋友有许多是以广告收入为主,所以apop来分享另外一块(收费版APP)的个人三年来的总结分享,希望对各位有帮助.首 先,其实在AppStore(或GooglePlay)上 ...

  4. 阿里云apt-get安装包时Err:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main amd64 git amd64 1:2.7.4-0ubuntu1.2 404 Not Found

    新部署的云服务器出现如下错误: root@iZj6cbjalvhsw0fhndmm5xZ:~# apt-get install git Reading package lists... Done Bu ...

  5. flex常用属性

    <1>align-items: 垂直方向的对齐方式 align-items: stretch(拉伸,布满父容器) | center(垂直居中) | flex-start(上对齐) | fl ...

  6. python打开.pkl的文件并显示里面的内容

    pkl文件是pyhthon里面保存文件的一种格式,如果直接打开会显示一堆序列化的东西.正确的打开方式如下: import cPickle as pickle f = open('path') info ...

  7. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  8. w3 parse a url

     最新链接:https://www.w3.org/TR/html53/ 2.6 URLs — HTML5 li, dd li { margin: 1em 0; } dt, dfn { font-wei ...

  9. shell脚本,实现奇数行等于偶数行。

    请把如下字符串stu494e222fstu495bedf3stu49692236stu49749b91转为如下形式:stu494=e222fstu495=bedf3stu496=92236stu497 ...

  10. webpack执行命令的不同方式

    如使用webpack3及之前的版本只需安装webpack3即可,因为之前的webpack里面集成了webpack-cli 1. 使用局部安装webpack和webpack-cli,使用package. ...