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.pswp.cn/news/250702.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/250702.shtml
英文地址,請注明出處:http://en.pswp.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;其實感覺這種算不上跨域請…