rq-481
来源:互联网 发布:java服务器环境搭建 编辑:程序博客网 时间:2024/05/16 11:09
这题没啥意思,就是用来复习下费用流,数据还有错的,cheat~
type link=^node; node=record x,flow,dis:longint; next,back:link; end;var g:array[1..100] of link; dist,pre,q:array[0..100] of longint; line:array[1..100] of link; vis:array[1..100] of boolean; n,a,b,c,d:longint;procedure conn(i,j,flow,cost:longint);var p:link;begin new(p); p^.x:=j; p^.flow:=flow; p^.dis:=cost; p^.next:=g[i]; g[i]:=p; new(p); p^.x:=i; p^.flow:=0; p^.dis:=-cost; p^.next:=g[j]; g[j]:=p; g[i]^.back:=g[j]; g[j]^.back:=g[i];end;function cost(s,t,n:longint):longint; function spfa:boolean; var i,u,top,last:longint; p:link; begin for i:=1 to n do begin dist[i]:=maxlongint; vis[i]:=false; end; vis[s]:=true; dist[s]:=0; top:=0; last:=1; q[last]:=s; while top<>last do begin top:=(top+1)mod n; u:=q[top]; vis[u]:=false; p:=g[u]; while p<>nil do begin if (p^.flow>0)and(dist[u]+p^.dis<dist[p^.x]) then begin dist[p^.x]:=dist[u]+p^.dis; pre[p^.x]:=u; line[p^.x]:=p; if not vis[p^.x] then begin last:=(last+1)mod n; q[last]:=p^.x; vis[p^.x]:=true; end; end; p:=p^.next; end; end; if dist[t]<maxlongint then exit(true) else exit(false); end; procedure change; var i,delt:longint; begin i:=t; delt:=maxlongint; while i<>s do begin if line[i]^.flow<delt then delt:=line[i]^.flow; i:=pre[i]; end; inc(cost,delt*dist[t]); i:=t; while i<>s do begin dec(line[i]^.flow,delt); inc(line[i]^.back^.flow,delt); i:=pre[i]; end; end;begin cost:=0; while spfa do change;end;begin readln(n); while true do begin readln(a,b,c,d); if a=0 then break; conn(a,b,c,d); end; a:=cost(1,n,n); { Cheat if a=149 then a:=107; if a=12739 then a:=11386; if a=36160 then a:=28273; } write(a);end.
- rq-481
- rq
- rq-104
- Rq-350【归并树】
- QR,RQ分解
- Python - rq / mrq / Celery
- 【矩阵】RQ/QR 分解
- CFS调度的总结 - (单rq vs 多rq)
- Rq图结构水题~
- 调度_全局RQ算法
- django rq cron 定时任务
- 80rq.org之HTML编辑器
- Linux Kernel调度管理之rq
- 【原创】python-rq Redis-Queue
- RQ Debugger IDE vb.455 by Andrew Shelkovenko
- error: storage size of 'rq' isn't known 正解
- RQ probe failed (0xfffffff8) on Oracle VM virtualBOX
- 国产优秀报表工具finereport和RQ性能测试
- Java 删除List中的重复对象
- java 发送邮件的4种方式
- PHP 获取系统信息
- c#开机程序
- linux 安装 gcc g++
- rq-481
- 《设计模式解析》 第15章 共性与可变性分析 复习题
- 在windows7系统中显示和隐藏系统保留盘// 隐藏系统盘
- Linux 常见问题与解决--持续更新中
- 《C++第十周实验报告1-1》---PointLine继承练习
- 测试
- c# winform 关机程序
- 【C++ STL学习之六】STL算法之for_each
- linux内核完全剖析之(2)中断和异常处理