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 ...
随机推荐
- POJ - 3176 Cow Bowling 动态规划
动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...
- Hexo-博客yilia主题创建分类(categories)和标签(tags)首页
转载自:http://orzcss.com/posts/5a207d64/ 概述 默认安装的 hexo 本身是没有分类和标签首页的,例如:http://orzcss.com/categories/页面 ...
- CSS基础--属性选择器、伪类选择器
属性选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 《JAVA设计模式》之命令模式(Command)
在阎宏博士的<JAVA与模式>一书中开头是这样描述命令(Command)模式的: 命令模式属于对象的行为模式.命令模式又称为行动(Action)模式或交易(Transaction)模式. ...
- meta标签viewport的深入理解(转)
移动前端开发之viewport的深入理解 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport了,只有明白了viewport的概念以及弄清楚了跟viewport有关的met ...
- CentnOS7安装Nginx“No package available”
Nginx相对Apache有轻量级,简洁的优点,算得上Apache的优秀替代品了,但是由于Nginx不在yum的官方源中,因此安装时总会出现失败的现象,只需: yum install epel-rel ...
- 20180209-shutil模块
下面讲解shutil模块的相关操作: 1.shutil.copyfileobj(fsrc, fdst, length=16*1024) 将fsrc文件内容拷贝到fdst文件中,length是指一次拷贝 ...
- PHP算法[转]
这里是用PHP写的几个基础算法,算法的重要性貌似对于PHP程序员不怎么重要,其实是非常重 要的,经典名句:算法+数据结构=程序.作为一名真正的高级PHP程序员,我认为应该熟悉C,如果你想成为真正的程序 ...
- go语言从例子开始之Example32.打点器
定时器 是当你想要在未来某一刻执行一次时使用的 - 打点器 则是当你想要在固定的时间间隔重复执行准备的.这里是一个打点器的例子,它将定时的执行,直到我们将它停止. Example: package m ...
- ltp-ddt wdt_test
# @name Watchdog Timer getsupport,settimeout,getstatus,keepalive ioctl and write test# @desc Watchdo ...