HDU 3316 My Brute(二维费用流)经典
My Brute
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 941 Accepted Submission(s): 372
to choose from the two excellent boys. So there will be a competition between starvae and xingxing. The competition is like the game “My Brute”.

Now starvae have n brutes named from S1 to Sn and xingxing’s brutes are named from X1 to Xn. A competition consists of n games. At the beginning, starvae's brute Si must versus xingxing’s brute Xi. But it’s hard for starvae to win the competition, so starvae
can change his brutes’ order to win more games. For the starvae’s brute Si, if it wins the game, starvae can get Vi scores, but if it loses the game, starvae will lose Vi scores. Before the competition, starvae’s score is 0. Each brute can only play one game.
After n games, if starvae’s score is larger than 0, we say starvae win the competition, otherwise starvae lose it.
It’s your time to help starvae change the brutes’ order to make starvae’s final score be the largest. If there are multiple orders, you should choose the one whose order changes the least from the original one. The original order is S1, S2, S3 … Sn-1, Sn, while
the final order is up to you.
For starvae’s brute Si (maybe this brute is not the original brute Si, it is the ith brute after you ordered them) and xingxing’s brute Xi, at first Si has Hi HP and Xi has Pi HP, Si’s damage is Ai and Xi’s is Bi, in other words, if Si attacks, Xi will lose
Ai HP and if Xi attacks, Si will lose Bi HP, Si attacks first, then it’s Xi’s turn, then Si… until one of them’s HP is less than 0 or equal to 0, that, it lose the game, and the other win the game.
Come on, starvae’s happiness is in your hand!
a line with n numbers mean A1 to An.(1<=Ai<=50) Then follows a line with n numbers mean B1 to Bn. (1<=Bi<=50) A zero signals the end of input and this test case is not to be processed.
digits after the decimal point. If starvae can’t win the competition after changing the order, please just print “Oh, I lose my dear seaco!” Maybe the sample can help you get it.
3
4 5 6
6 8 10
12 14 16
7 7 6
7 3 5
3
4 5 6
6 8 10
12 14 16
5 5 5
5 5 5
0
7 33.333%
Oh, I lose my dear seaco!
输出最大得分和比例。
假设分数<=0则输出Oh, I lose my dear
seaco!
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN = 1010;
const int MAXM = 100100;
const int INF = 1<<29;
struct EDG{
int to,next,cap;
int cost,flag;
}edg[MAXM];
int head[MAXN],eid;
int pre[MAXN], cost[MAXN] ; //点0~(n-1) void init(){
eid=0;
memset(head,-1,sizeof(head));
}
void addEdg(int u,int v,int cap,int cst,int flag){
edg[eid].to=v; edg[eid].next=head[u]; edg[eid].cost = cst;
edg[eid].cap=cap; edg[eid].flag=flag; head[u]=eid++; edg[eid].to=u; edg[eid].next=head[v]; edg[eid].cost = -cst;
edg[eid].cap=0; edg[eid].flag=-flag; head[v]=eid++;
} bool inq[MAXN];
int q[MAXN],flg[MAXN];
bool spfa(int sNode,int eNode,int n){
int l=0 , r=0; for(int i=0; i<n; i++){
inq[i]=false; cost[i]= -INF; flg[i]=-INF;
}
cost[sNode]=0; flg[sNode]=0; inq[sNode]=1; pre[sNode]=-1;
q[r++]=sNode;
while(l!=r){
int u=q[l++];
if(l==MAXN)l=0;
inq[u]=0;
for(int i=head[u]; i!=-1; i=edg[i].next){
int v=edg[i].to;
if(edg[i].cap<=0)continue; if( cost[v]<cost[u]+edg[i].cost || cost[v]==cost[u]+edg[i].cost&&flg[v]<flg[u]+edg[i].flag){ //在满足可增流的情况下,最小花费
cost[v] = cost[u]+edg[i].cost;
flg[v] = flg[u]+edg[i].flag;
pre[v]=i; //记录路径上的边
if(!inq[v]){
if(r==MAXN)r=0;
q[r++]=v;
inq[v]=1;
}
}
}
}
return cost[eNode]!=-INF; //推断有没有增广路
}
//反回的是最大流,最小花费为minCost
int minCost_maxFlow(int sNode,int eNode ,int& minCost,int n){
int ans=0;
while(spfa(sNode,eNode,n)){
ans+=flg[eNode];
minCost+= cost[eNode]; for(int i=pre[eNode]; i!=-1; i=pre[edg[i^1].to]){
edg[i].cap-=1; edg[i^1].cap+=1;
}
}
return ans;
}
int main(){
//输入,初始化init()
int n,valu[MAXN],H[MAXN],P[MAXN],A[MAXN],B[MAXN];
while(scanf("%d",&n)>0&&n){
for(int i=1; i<=n; i++)
scanf("%d",&valu[i]);
for(int i=1; i<=n; i++)
scanf("%d",&H[i]);
for(int i=1; i<=n; i++)
scanf("%d",&P[i]);
for(int i=1; i<=n; i++)
scanf("%d",&A[i]);
for(int i=1; i<=n; i++)
scanf("%d",&B[i]); init();
int s=0 , t= 2*n+1;
for(int i=1; i<=n; i++)
{
addEdg(s , i , 1 , 0 , 0);
addEdg(i+n, t , 1 , 0 , 0);
}
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(P[j]/A[i]+(P[j]%A[i]!=0? 1:0)<=H[i]/B[j]+(H[i]%B[j]!=0? 1:0)){
if(i==j)
addEdg(i,j+n,1,valu[i],1);
else
addEdg(i,j+n,1,valu[i],0);
}
else{
if(i==j)
addEdg(i,j+n,1,-valu[i],1);
else
addEdg(i,j+n,1,-valu[i],0);
}
int maxcost=0;
int ans=minCost_maxFlow(s , t , maxcost, t+1);
if(maxcost<=0)
printf("Oh, I lose my dear seaco!\n");
else
printf("%d %.3f%%\n",maxcost,100.0*ans/n);
}
}
HDU 3316 My Brute(二维费用流)经典的更多相关文章
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- hdu - 2660 Accepted Necklace (二维费用的背包问题)
http://acm.hdu.edu.cn/showproblem.php?pid=2660 f[v][u]=max(f[v][u],f[v-1][u-w[i]]+v[i]; 注意中间一层必须逆序循环 ...
- HDU 2159 二维费用背包问题
一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...
- HDU 3496 (二维费用的01背包) Watch The Movie
多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...
- hdu_2159(二维费用背包)
HDU_2159 二维费用背包问题 http://acm.hdu.edu.cn/showproblem.php?pid=2159 #include<cstdio> #include< ...
- HDU 3127 WHUgirls【二维完全背包】
题意:给出一个长为a,宽为b的布,再给出n个围巾的规格(长x,宽y,价值c),问怎样裁剪能够得到最大的价值. ----第一次做的时候不会---然后放到今天做--发现还是不会---于是又--看题解了-- ...
- hdu2159二维费用背包
题目连接 背包九讲----二维费用背包 问题 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有一个可付出的最大值(背包容量).问怎样选择物 ...
- 2159 ACM 杭电 杀怪 二维费用的背包+完全背包问题
题意:已知经验值,保留的忍耐度,怪的种数和最多的杀怪数.求进入下一级的最优方案. 思路:用二维费用的背包+完全背包问题 (顺序循环)方法求解 什么是二维费用的背包问题? 问题: 二维费用的背包问题是指 ...
- 洛谷 P1507 NASA的食物计划 【二维费用背包】 || 【DFS】
题目链接:https://www.luogu.org/problemnew/show/P1507 题目背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安全技术问题一直大伤脑筋,因此在各方压力 ...
随机推荐
- Ext.Toolbar.Fill()
tbar : ['-',new Ext.form.Label({ text : '产品代码:' }),new Ext.form.TextField({ id : 'cpdm', name : 'cpd ...
- Hadoop 组成
这里介绍一下hadoop的组成, hadoop主要由两部分组成,,一个是hdfs,还有一个是mapreduce 这两个部分在hadoop 2.2.0中分别用start-dfs.sh和start-yar ...
- 算法:非平衡二叉搜索树(UnBalanced Binary Search Tree)
背景 很多场景下都需要将元素存储到已排序的集合中.用数组来存储,搜索效率非常高: O(log n),但是插入效率比较低:O(n).用链表来存储,插入效率和搜索效率都比较低:O(n).如何能提供插入和搜 ...
- 通过http请求传递xml流和接收xml流的代码示例
通过http请求传递xml流和接收xml流的代码示例 //1.在servlet中post一个xml流:import java.io.OutputStreamWriter;import org.jdom ...
- Android之计算两个时间的相差
参数: sdate = 2013-07-16 16:14:47 /** * 以友好的方式显示时间 * @param sdate * @return */ public static String ...
- 数据结构及算法篇bsearch crypt lfind lsearch qsort rand srand
crypt(将密码或数据编码) 相关函数 getpass 表头文件 #define _XOPEN_SOURCE #include<unistd.h> 定义函数 char * crypt ( ...
- MyBatis使用Collection查询多对多或一对多结果集bug
情况描述:当使用JOIN查询,如果SQL查询出来的记录不是按id列排序的,则生成的List结果会有问题 案例: 1) 数据库模型 简而言之一个Goods包含多个Goods_Img 2) Java Be ...
- 学习笔记:状态压缩DP
我们知道,用DP解决一个问题的时候很重要的一环就是状态的表示,一般来说,一个数组即可保存状态.但是有这样的一些题 目,它们具有DP问题的特性,但是状态中所包含的信息过多,如果要用数组来保存状态的话需要 ...
- 第七章 Xmemcached客户端介绍
提示:有关于XMemcached在实际开发中的具体使用,查看"Java企业项目开发实践"系列博客的<第八章 企业项目开发--分布式缓存memcached> 注意:本文主 ...
- 第八章 ArrayBlockingQueue源码解析
注意:在阅读本文之前或在阅读的过程中,需要用到ReentrantLock,内容见<第五章 ReentrantLock源码解析1--获得非公平锁与公平锁lock()><第六章 Reen ...