JZOJ 4622 亚瑟王之宫【NOIP2016A组模拟7.13】
来源:互联网 发布:知乎乌克兰汽车之家 编辑:程序博客网 时间:2024/05/07 15:26
亚瑟王之宫
题目描述
输入格式
输出格式
样例输入
4 4 4
1 1
4 1
1 4
4 4
样例输出
4
数据范围
题解
首先,求出每两个位置的最短路径,可以用
然后,我们枚举骑士们聚集的两个位置,我们设第
先假设所有的骑士都向第一个位置聚集,则
接下来,我们每个
于是,我们按照
最后统计一下最优解即可。
Code(Pascal)
var w:array[1..8,1..2] of longint= ((1,-2),(-1,2),(-1,-2),(1,2),(2,1),(2,-1),(-2,1),(-2,-1)); qs:array[0..200,1..2] of longint; dl:array[0..400] of longint; f:array[0..20,0..20,0..20,0..20] of int64; n,m,j,k,l,i,o,p,r,c,ans,kkk:longint;function ok(x,y:longint):boolean; begin exit((x>0) and (x<=r) and (y>0) and (y<=c)); end;function max(a,b:int64):int64; begin if a>b then exit(a) else exit(b); end;function min(a,b:int64):int64; begin exit(A+b-max(a,b)); end;procedure qsort(l,r:longint); var i,j,m:longint; begin i:=l; j:=r; m:=dl[(l+r) div 2]; repeat while dl[i]<m do inc(i); while dl[j]>m do dec(j); if i<=j then begin dl[0]:=dl[i]; dl[i]:=dl[j]; dl[j]:=dl[0]; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end;begin readln(n,r,c); for i:=1 to n do readln(qs[i,1],qs[i,2]); for i:=1 to r do for l:=1 to c do begin for j:=1 to r do for k:=1 to c do f[i,l,j,k]:=maxlongint; f[i,l,i,l]:=0; end; for i:=1 to r do for l:=1 to c do for j:=1 to 8 do if ok(i+w[j,1],l+w[j,2]) then f[i,l,i+w[j,1],l+w[j,2]]:=1; for o:=1 to r do for p:=1 to c do for i:=1 to r do for l:=1 to c do for j:=1 to r do for k:=1 to c do f[i,l,j,k]:=min(f[i,l,j,k],f[i,l,o,p]+f[o,p,j,k]); m:=n div 2; ans:=maxlongint; for i:=1 to r do for l:=1 to c do for j:=1 to r do for k:=1 to c do begin kkk:=0; for o:=1 to n do begin kkk:=f[i,l,qs[o,1],qs[o,2]]+kkk; dl[o]:=f[j,k,qs[o,1],qs[o,2]]-f[i,l,qs[o,1],qs[o,2]]; end; qsort(1,n); for o:=1 to m do kkk:=kkk+dl[o]; ans:=min(ans,kkk); end; writeln(ans);end.
4 0
- JZOJ 4622 亚瑟王之宫【NOIP2016A组模拟7.13】
- 【NOIP2016A组模拟7.13】亚瑟王之宫
- 【NOIP2016A组模拟7.13】亚瑟王之宫 题解+代码
- 【NOIP2016A组模拟7.13】亚瑟王之宫
- 【JZOJ 4622】亚瑟王之宫
- 【JZOJ 4622】 亚瑟王之宫
- [JZSC2016]【NOIP2016A组模拟7.13】总结
- 【NOIP2016A组模拟7.13】搬运干草捆
- NOIP2016A组模拟7.13】字符串匹配
- 【NOIP2016A组模拟7.13】字符串匹配 题解+代码
- 【jzoj4622】【亚瑟王之宫】
- [JZOJ4622] 亚瑟王之宫
- 【JZOJ4622】亚瑟王之宫
- 【APIO2016】亚瑟王之宫
- 亚瑟王
- JZOJ 100045. 【NOIP2017提高A组模拟7.13】好数
- shell 亚瑟王环
- bzoj4008[HNOI2015]亚瑟王
- SpringMVC 的几种传参的方式
- C#精髓 第四讲 GridView 72般绝技
- PHP文件上传操作
- POJ 1001 Exponentiation
- ImageLoader的简单分析(二)
- JZOJ 4622 亚瑟王之宫【NOIP2016A组模拟7.13】
- C++内存布局:深入立即C++内存布局下
- ubuntu安装protobuf
- 【COCI2008】二叉树
- event.target
- try...catch...finally分析总结
- 使用update-alternatives切换ubuntu下默认java命令
- HashMap的实现原理
- jzoj 1388 【2012.02.25普及组】探索的奶牛 结题报告