hdu 5517 Triple
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5517
-------------------------------------------------------------------------------------------------------
前置知识以及思维难度上不算很高 不过实现对于我这种弱渣来说还是太复杂了(很多处理比较绕)
我们稍作分析(xiangyun)后可以发现 有可能最优且本质不同的三元组C只有不超过M个
对于二元组A b相同时只用保留a最大的 并且把相同的A合并掉
处理完之后再将B与之合体 得到不超过M个C
此时先按一个元素排序 再根据另两个元素值 用二维树状数组统计下就好了
-------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + , lim = ;
int t, n, m, len, lenm;
struct sa
{
int x,y,c;
}a[N],ua[N];
struct sc
{
int x,y,z,c;
}c[N];
bool f[lim][lim];
bool cmp1(const sa &aa,const sa &bb)
{
return aa.y < bb.y || (aa.y == bb.y && aa.x > bb.x);
}
bool cmp2(const sc &aa,const sc &bb)
{
return aa.x > bb.x || (aa.x == bb.x && aa.y < bb.y)
|| (aa.x == bb.x && aa.y == bb.y && aa.z < bb.z);
}
int main()
{
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca)
{
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a + , a + + n, cmp1);
len = lenm = ;
memset(ua, , sizeof ua);
for(int i = ; i <=n;)
{
++len;
ua[len].x = a[i].x;
ua[len].y = a[i].y;
int j = i;
while(a[j + ].x == a[i].x)
++j;
ua[len].c = j - i + ;
while(a[j]. y == a[i].y)
++j;
i = j;
}
int tx,ty,tz;
for(int i = ; i <= m; ++i)
{
scanf("%d%d%d", &tx, &ty, &tz);
int L = , R = len, mid;
while(L < R)
{
mid = (L + R) >> ;
if(ua[mid].y >= tz)
R = mid;
else
L = mid + ;
}
if(ua[R].y == tz)
{
++lenm;
c[lenm].x = ua[R].x;
c[lenm].y = lim - tx;
c[lenm].z = lim - ty;
c[lenm].c = ua[R].c;
}
}
n = lenm;
sort(c + ,c + + n,cmp2);
memset(f, , sizeof f);
long long ans = ;
for(int i = ; i <= n; ++i)
{
if(c[i].x == c[i + ].x && c[i].y == c[i + ].y &&
c[i].z == c[i + ].z)
{
c[i + ].c += c[i].c;
continue;
}
bool tmp = ;
for(int p = c[i].y; p ; p -= p & -p)
for(int q = c[i].z; q; q -= q & -q)
tmp |= f[p][q];
if(!tmp)
ans += c[i].c;
for(int p = c[i].y; p < lim; p += p & -p)
for(int q = c[i].z; q < lim; q += q & -q)
f[p][q] = ;
}
printf("Case #%d: %lld\n", ca, ans);
}
return ;
}
hdu 5517 Triple的更多相关文章
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- ACM-ICPC 2015 沈阳赛区现场赛 I. Triple && HDU 5517(二维BIT)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5517 题意:有二元组(a,b),三元组(c,d,e).当b == e时它们能构成(a,c,d)然后,当 ...
- HDU 5517 【二维树状数组///三维偏序问题】
题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...
- hdu 3908 Triple(组合计数、容斥原理)
Triple Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- K-D树
一般用来解决各种二维平面的点对统计,也许一般非正解? 没时间慢慢写了,打完这个赛季后补细节 建树板子: #include <cstdio> #include <locale> ...
- HDU 5902 GCD is Funny 数学
GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1370 Biorhythms
中国剩余定理……. 链接http://acm.hdu.edu.cn/showproblem.php?pid=1370 /**************************************** ...
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...
随机推荐
- E-puck简单入门
E-puck是瑞士的一款小型的机器人,可以用于教学和实验,其外形小巧,并且整个结构也比较简单,如果出现损坏也比较容易维护. 其外形如下: 因为国内的资料很少,资料主要还是通过官方文档了解,而官方的文档 ...
- Spring Cloud Stream 进行服务之间的通讯
Spring Cloud Stream Srping cloud Bus的底层实现就是Spring Cloud Stream,Spring Cloud Stream的目的是用于构建基于消息驱动(或事件 ...
- 01 spring循环依赖
作者:Mythsman原文:https://blog.mythsman.com/post/5d838c7c2db8a452e9b7082c/转载自:猿天地原文来自:https://mp.weixin. ...
- [fw]linux测试工程介绍(Linux Test Project)
http://ltp.sourceforge.net/ Linux Test Project, 后台很硬,由SGI™ 发起, IBM维护,所以质量有保障. 里面介绍了很多工具,对于一般的基准测试应该是 ...
- linux上执行jmeter脚本
1.linux上安装jmeter 将windows上的zip包直接放到linux上 进入bin目录,chmod 777 jmeter 修改环境变量: 1 2 3 4 # vim /etc/profil ...
- linux网络子系统调优
- shell条件判断命令test
- ssh-agent - 认证代理
总览 (SYNOPSIS) ssh-agent [-a bind_address ] [-c | -s ] [-t life ] [-d ] [command [args ... ] ] ssh-ag ...
- Git--03 git分支
目录 Git分支 1.新建testing分支 2.合并分支 3.合并冲突 4.删除分支 Git标签使用 1.查看标签 02.删除标签 Git分支 分支即是平行空间,假设你在为某个手机系统研发拍照功 ...
- P.W.N. CTF - MISC - Canadian FOI
题目 链接:https://ctftime.org/task/6935 题解 只有两个页面的网站,index.html和about.html index.html页面有一个pdf链接,指向http:/ ...