1070: [SCOI2007]修车

/*
一开始以为是个贪心 发现自己太naive了将每个技术工人拆成n个点,一共拆n
*m个,第i个表示倒数第i次修车。 让每辆车向拆出来的点连边,费用为tmp[i][j]*k,i是技工,j是车,k是拆出来的第几个点, 这样设置费用的原因是j是i倒数第k个修的,那么i修的后k个车都要等倒数第k个车。 然后跑最小费用最大流就可以了 */#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std;inline int read() {char c=getchar();int num=0;for(;!isdigit(c);c=getchar());for(;isdigit(c);c=getchar())num=num*10+c-'0';return num; }const int N=65; const int M=2e5+5;int m,n,S,T; int tim[N][N]; long long ans;int head[M],num_edge; struct Edge {int v,nxt,flow,cost; }edge[M];inline void add_edge(int u,int v,int flow,int cost) {edge[++num_edge].v=v;edge[num_edge].flow=flow;edge[num_edge].cost=cost;edge[num_edge].nxt=head[u];head[u]=num_edge;edge[++num_edge].v=u;edge[num_edge].flow=0;edge[num_edge].cost=-cost;edge[num_edge].nxt=head[v];head[v]=num_edge; }int dis[M]; queue<int> que; bool inque[M]; bool spfa() {memset(dis,0x3f,sizeof(dis));que.push(S),dis[S]=0;int now;while(!que.empty()){now=que.front(),que.pop();for(int i=head[now],v;i;i=edge[i].nxt){if(edge[i].flow==0)continue;v=edge[i].v;if(dis[v]>dis[now]+edge[i].cost){dis[v]=dis[now]+edge[i].cost;if(!inque[v]){que.push(v);inque[v]=1;}}}inque[now]=0;}return dis[T]!=0x3f3f3f3f; }int vis[M],visf; int dfs(int u,int flow) {if(u==T||!flow)return flow;int outflow=0;vis[u]=visf;for(int i=head[u],v,tmp;i;i=edge[i].nxt){if(!edge[i].flow)continue;v=edge[i].v;if(vis[v]!=visf&&dis[v]==dis[u]+edge[i].cost){tmp=dfs(v,min(flow,edge[i].flow));if(!tmp)continue;ans+=1ll*tmp*edge[i].cost;edge[i].flow-=tmp;edge[i^1].flow+=tmp;flow-=tmp;outflow+=tmp;if(!flow){vis[u]=0;return outflow;}}}vis[u]=0;dis[u]=0x7fffffff;return outflow; }int main() {num_edge=1;m=read(),n=read();T=n+n*m+1;for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)tim[j][i]=read();for(int i=1;i<=n;++i)add_edge(S,i,1,0);for(int i=1,p;i<=m;++i){for(int j=1;j<=n;++j){p=i*n+j;add_edge(p,T,1,0);for(int c=1;c<=n;++c)add_edge(c,p,1,tim[i][c]*j);}}while(spfa()){++visf;dfs(S,0x7fffffff);}printf("%.2lf",1.0*ans/n);return 0; }

 

转载于:https://www.cnblogs.com/lovewhy/p/9633745.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/250702.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PHP 实现冒泡排序

PHP 实现冒泡排序 直接上代码 //冒泡排序 function bubble_sort($array){$count count($array);if ($count<0) {return false;}for ($i0; $i <$count ; $i) { for ($j0; $j <$count-$i-1 ; $j) { if ($array[$j]>$array[$j1]) {$tmp $array[$j1];$array[$j1]$a…

node --- 后端使用bcrypt对密码进行加密处理

密码的处理 加密处理在线调试: http://www.atool9.com/hash.phpbcrypt: 加密工具安装 && 使用 npm install --save bcryptconst bcrypt require(bcrypt); const SALT_WORK_FACTOR 10;const UserSchema new Schema({UserId: {type: ObjectId},password: String })U…

统一建模语言UML

目录 1. UML定义2. UML结构2.1 视图&#xff08;View&#xff09;2.2 图&#xff08;Diagram&#xff09;2.3 模型元素&#xff08;Model element&#xff09;2.4 通用机制&#xff08;General mechanism&#xff09;3. 类图3.1 类与类图3.2 类之间的关系3.2.1 关联关系3.2.2 聚…

SpringCloud系列七:使用Ribbon实现客户端侧负载均衡

1. 回顾 在前面&#xff0c;已经实现了微服务的注册与发现。启动各个微服务时&#xff0c;Eureka Client会把自己的网络信息注册到Eureka Server上。 但是&#xff0c;在生成环境中&#xff0c;各个微服务都会部署多个实例&#xff0c;因此还行继续进行优化。 2. Ribbon简介 Ri…

node --- 使用koa-router,让后端模块化

使用Koa-router进行路由管理 npm install --save koa-router const Router require(koa-router); let router new Router(); router.get(/, async (ctx)>{ctx.body 用户操作首页 })路由模块化 在appApi下面创建需要模块化的文件如:home.js、user.js const Router re…

PHP 实现桶排序

PHP 实现桶排序 <?phpfunction Bucket_sort($array){//初始化桶大小$min min($array);$max max($array);$book array_fill($min, $max-$min1, 0);//将要进行的数据进行计数foreach ($array as $key) {$book[$key];// echo $book[$key];}//返回数据$resArr array();for…

springboot ajax返回html

因为拦截器 或者是 shiro 拦截登陆接口 转载于:https://www.cnblogs.com/xdcr/p/9638569.html

【小试牛刀】短信验证码(随机数)的生成实现

短信验证码&#xff0c;相信在生活中大家是几乎天天能够遇到。但你知道它是怎样生成的吗&#xff1f;其实它就是若干位数的随机数组合而成。下面附上一小段程序&#xff0c;供大家一起学习交流。package com.fhcq.util;import org.apache.commons.lang3.RandomStringUtils;publ…

node --- 后端使用body-parse解析Post请求,前端使用axios发送Post请求

使用body-parser解析post请求 安装service/index.js npm install --save koa-bodyparser导入 const Koa require(koa); const app new Koa(); const bodyParser require(koa-bodyparser); app.use(bodyParser)准备请求的url全局配置src/serviceAPI.config.js const LOCA…

PHP 实现二分查找

PHP 实现二分查找 原理&#xff1a; 首先&#xff0c;假设数组中元素是按升序排列&#xff0c;将表中间位置记录的关键字与查找关键字比较&#xff0c;如果两者相等&#xff0c;则查找成功&#xff1b;否则利用中间位置记录将数组分成前、后两个子数组&#xff0c;如果中间位…

python基础:条件循环字符串

while True:a int(input(摄氏度转换为华氏温度请按1\n华氏温度转化为摄氏温度请按2\n))if a 1:celsius float(input(输入摄氏温度&#xff1a;))fahreaheit (celsius 1.8) 32 # f c9/532print({:.2f}摄氏温度转为华氏温度为{:.2f}.format(celsius, fahreaheit))elif a …

项目难点总结

一 滑动窗口 &#xff11;&#xff09;滑动窗口设置 &#xff12;&#xff09;窗口对齐 &#xff13;&#xff09;窗口的调优&#xff0c;能否正常触发 数据丢失问题    &#xff52;&#xff45;&#xff54;&#xff52;&#xff59; 事件延时&#xff08;late arrival …

7-n!末尾有几个0

如何确定一个N&#xff01;末尾有多少个零 转载 2015年08月30日 15:02:49622题目&#xff1a;1*2*3*……*100 求结果末尾有多少个零 分析&#xff1a;一般类似的题目都会蕴含某种规律或简便方法的,阶乘末尾一个零表示一个进位&#xff0c;则相当于乘以10而10 是由2*5所得&#…

PHP中header的用法

PHP中header的用法 摘要&#xff1a; header()的作用&#xff1a;给客户端发送头信息 头信息的作用 跳转 Header("Refresh:2; URLhttp://localhost//session.php");//2秒后跳转 //若等待时间为0&#xff0c;则与header("location:")效果一致 Header(&q…

node --- koa、Mongoose、vue联系知识梳理

前端、后端联系知识梳理 以打开浏览器,访问login为栗打开浏览器,访问localhost:8080/#/loginsrc/router/index.js 会根据 /login 找到对应的Login(src/components/pages/Login.vue)组件, 然后渲染到浏览器当输入用户名和密码,点击登录按钮后根据Login组件中配置的axios请求向后…

倒计时

//1获取24小时$fixation_time strtotime("1 day")-time();//2.获取已经过去的时间$different time()-strtotime($question->created_at);//3.获取时间差$time $fixation_time - $different;//4.获取时$hour floor($time/3600);if($hour<10){$hour 0.$hour;…

Git命令一览

Git命令一览 分支名称 master 稳定分支 develop 不稳定分支&#xff08;开发分支&#xff09; issue 或 fixbug BUG 分支 feature 新功能分支 release 预发布分支 本地操作 git init 初始化 git add 增加到暂存区 git commit -m 提交到分支 git status 查看状态 gi…

从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十二║Vue实战:个人博客第一版(axios+router)...

前言 今天正式开始写代码了&#xff0c;之前铺垫了很多了&#xff0c;包括 6 篇基础文章&#xff0c;一篇正式环境搭建&#xff0c;就是为了今天做准备&#xff0c;想温习的小伙伴可以再看看《Vue 基础入门详细的环境搭建》&#xff0c;内容很多&#xff0c;这里就暂时不复习了…

node --- 使用mongoose连接mongoDB,并初始化所有的Schema

写了一个init.js函数 使用了glob来对协助完成(https://github.com/isaacs/node-glob)连接的数据库的名称(smile-vue)连接数据库操作:connect 断线重开连接失败连接成功 初始化所有的Schemas暴露给其他页面使用的接口 const mongoose require(mongoose); const db mongodb:/…

ajax跨域问题(php)

ajax出现请求跨域错误问题,主要原因就是因为浏览器的“同源策略”。 解决方法(我只用过下面这3种)&#xff1a; 1. 架设服务器代理&#xff1a;即浏览器请求同源服务器&#xff0c;再由后者请求外部服务&#xff08;之前博主一直用这种方法&#xff0c;其实感觉这种算不上跨域请…