HDU 1350
http://acm.hdu.edu.cn/showproblem.php?pid=1350
给m个顾客的乘车信息,表示几点前上车,要从一个坐标点到达另一个坐标点,花费的时间是两点的曼哈顿距离,两次换乘至少间隔1分钟(具体看样例),求最少的司机数目
把每位顾客看成一个点,如果该司机可以在接完a顾客后接到b顾客,则视为a到b连一条有向边。这个图肯定是无环的(已经接完的顾客不需要再去接),并且要用尽可能少的路径(司机)覆盖所有点,所以转化为DAG图最小路径覆盖的问题,二分图最大匹配经典模型
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath> using namespace std; struct node{
int s,t,nxt ;
}e[] ;
int k,m,n,head[],cnt,match[],vis[] ;
int find(int s)
{
for(int i=head[s] ;i!=- ;i=e[i].nxt)
{
int tt=e[i].t ;
if(!vis[tt])
{
vis[tt]= ;
if(match[tt]==- || find(match[tt]))
{
match[tt]=s ;
return ;
}
}
}
return ;
}
int max_match()
{
int ans= ;
memset(match,-,sizeof(match)) ;
for(int i= ;i<=n ;i++)
{
memset(vis,,sizeof(vis)) ;
ans+=find(i);
}
return ans;
}
void add(int s,int t) {e[cnt].s=s ;e[cnt].t=t ;e[cnt].nxt=head[s] ;head[s]=cnt++ ;} struct point{
int x,y;
}; struct node1{
point s,t;
int st,ed;
}kk[]; int ABS(int x){
return x>?x:-x;
} void read_graph()
{
memset(head,-,sizeof(head)) ;
cnt= ;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j)continue;
if(kk[i].ed+ABS(kk[i].t.x-kk[j].s.x)+ABS(kk[i].t.y-kk[j].s.y)<kk[j].st)
add(i,j);
}
}
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<=n;i++){
int hh,mm;
scanf("%d:%d%d%d%d%d",&hh,&mm,&kk[i].s.x,&kk[i].s.y,&kk[i].t.x,&kk[i].t.y);
kk[i].st=hh*+mm;
kk[i].ed=kk[i].st+ABS(kk[i].s.x-kk[i].t.x)+ABS(kk[i].s.y-kk[i].t.y);
}
read_graph();
printf("%d\n",n-max_match());
}
return ;
}
HDU 1350的更多相关文章
- HDU 1350 Taxi Cab Scheme
Taxi Cab Scheme Time Limit: 10000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...
- HDU 1337 && POJ 1218&& zju 1350 方法总结
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1337 杭电 http://poj.org/problem?id=1218清华 http://acm.zj ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU 4585 Shaolin(Treap找前驱和后继)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Su ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
随机推荐
- MATLAB画图
画图代码 clear % http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries % load RankData % ...
- PHP——字符串统一转码为GBK,自动判断是否UTF8并转码
public static function strToGBK($strText) { $encode = mb_detect_encoding($strText, array('UTF-8','GB ...
- B+树索引和哈希索引的区别——我在想全文搜索引擎为啥不用hash索引而非得使用B+呢?
哈希文件也称为散列文件,是利用哈希存储方式组织的文件,亦称为直接存取文件.它类似于哈希表,即根据文件中关键字的特点,设计一个哈希函数和处理冲突的方法,将记录哈希到存储设备上. 在哈希文件中,是使用一个 ...
- Octopus系列之开发过程各个技术点
自定义了页面周期 使用唯一的一个VelocityEngine全局的静态实例,优化了小泥鳅blog中每次请求都要创建VelocityEngine实例对象,减少了对象的开销 通过UA判断请求来自的设备,从 ...
- sql2008 附加数据库出错解决方法
当遇到 无法为此请求检索数据,(Microsoft.SqlServer.SmoEnum)其他信息执行Transact-Sql语句或批处理时发生了异常, Microsoft.SqlServer.Conn ...
- javascript密码强度验证!
//CharMode函数 //测试某个字符是属于哪一类 function CharMode(iN) { if (iN>=48 && iN <=57) //数字 return ...
- eclipse快捷键失效的解决办法
今天敲html代码,突然发现ctrl+D不能用了,shift+enter/shift+ctrl+enter也不能用了,上网上搜了下,原来我是在文本模式下打开的.切换为html editor打开就o了. ...
- plsql记住登录密码
登录plsql:tools(工具)->preference(首选项)->Login history(登录历史):选择"Store with password"(带口令存 ...
- [Js]基础知识
一.JavaScript组成 1.ECMAScript 解释器.翻译(提供功能有限,如加减乘除,定义变量.函数等) 几乎没有兼容性问题 2.DOM 有一些兼容性问题 3.BOM(用的少,交互 ...
- 十大谷歌Google搜索技巧分享
前言:多数人在使用Google搜索的过程是非常低效和无谓的,如果你只是输入几个关键词,然后按搜索按钮,你将是那些无法得到Google全部信息的用户,在这篇文章中,Google搜索专家迈克尔.米勒将向您 ...