题目链接 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的更多相关文章

  1. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. 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)然后,当 ...

  3. HDU 5517 【二维树状数组///三维偏序问题】

    题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...

  4. hdu 3908 Triple(组合计数、容斥原理)

    Triple Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  5. K-D树

    一般用来解决各种二维平面的点对统计,也许一般非正解? 没时间慢慢写了,打完这个赛季后补细节 建树板子: #include <cstdio> #include <locale> ...

  6. HDU 5902 GCD is Funny 数学

    GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...

  7. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. hdu 1370 Biorhythms

    中国剩余定理……. 链接http://acm.hdu.edu.cn/showproblem.php?pid=1370 /**************************************** ...

  9. 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms

    题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...

随机推荐

  1. Convolutional Neural Networks(2):Sparse Interactions, Receptive Field and Parameter Sharing

    Sparse Interactions, Receptive Field and Parameter Sharing是整个CNN深度网络的核心部分,我们用本文来具体分析其原理. 首先我们考虑Feedf ...

  2. spring-第九篇之高级依赖关系配置

    1.关于配置文件一些使用 组件与组件之间的耦合,采用依赖注入管理:基本类型的成员变量值,应该直接在代码中设置. 2.获取其他bean的属性值 PorpertyPathFactoryBean用来获取目标 ...

  3. JS跨域:jsonp、跨域资源共享、iframe+window.name

    JS跨域:jsonp.跨域资源共享.iframe+window.name :https://www.cnblogs.com/doudoublog/p/8652213.html JS中的跨域 请求跨域有 ...

  4. JAVA模拟Spring实现IoC过程(附源码)

    前言:本人大四学生,第一次写博客,如果有写得不好的地方,请大家多多指正 一.IoC(Inversion of Control)反转控制 传统开发都是需要对象就new,但这样做有几个问题: 效率低下,创 ...

  5. Linux mysql 乱码

    http://www.pc6.com/infoview/Article_63586.html http://itindex.net/detail/41748-linux-mysql-5.5 http: ...

  6. 关于JSON.stringify()与JSON.parse()

    一.JSON.stringify()与JSON.parse()的区别 JSON.stringify()的作用是将js值转换成JSON字符串,而JSON.parse()是将JSON字符串转换成一个对象. ...

  7. springcloud费话之Eureka集群

    目录: springcloud费话之Eureka基础 springcloud费话之Eureka集群 springcloud费话之Eureka服务访问(restTemplate) springcloud ...

  8. jq中的ajax传参

        一.   jq中的Ajax传参有两种           1.通过url地址来传参    2.通过data来传递参数 1. url来传递参数 function GetQuery(id) { | ...

  9. java随机数Math.random()

    double random=Math.random();//返回[0,1)随机数 (int)(Math.random()*6)//返回0-5:随机数 (int)(Math.random()*6+1)/ ...

  10. 2019-9-2-git镜像仓库

    title author date CreateTime categories git镜像仓库 lindexi 2019-09-02 12:57:37 +0800 2018-2-13 17:23:3 ...