Problem Description

Seaco is a beautiful girl and likes play a game called “My Brute”. Before Valentine’s Day, starvae and xingxing ask seaco if she wants to spend the Valentine’s Day with them, but seaco only can spend it with one of them. It’s hard 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!

Input

First line is a number n. (1<=n<=90) Then follows a line with n numbers mean V1 to Vn. (0<Vi<1000) Then follows a line with n numbers mean H1 to Hn. (1<=Hi<=100)Then follows a line with n numbers mean P1 to Pn. (1<=Pi<=100) Then follows 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.

Output

For each test case, if starvae can win the competition, print the largest score starvae can get, and then follow a real percentage means the similarity between the original order and the final order you had changed, round it to three 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.

Sample Input

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

Sample Output

7 33.333%
Oh, I lose my dear seaco!

题意:有 S1-Sn 的 n 个勇士要与 X1-Xn 的 n 个勇士比赛,开始时,Si 的比赛对象是 Xi,若 Si 赢了 Xi,将获得 Vi 分,否则获得 -Vi 分,开始对决时,Si 有初始生命 Hi,初始攻击 Ai,Xi 有初始生命 Pi,初始攻击 Bi,Si 先出手,然后 Xi 失去 Ai 生命,若 Xi 未死,则 Xi 出手,Si 失去 Bi 生命,重复过程,直到有一方生命值小于等于 0 时,决斗结束

现在要重新安排 S、X 双方的决斗顺序,使可获取的分最多,输出可获得的最大值与原匹配与新匹配之间的相似性

思路:题目一开始给出的对决方式实质是一个匹配,现在要构造一个最优匹配,且要优先使用原边,套用模版进行计算即可,思路与  Assignment(HDU-2853)很像,不同的是,边权值需要自己进行计算,对于左 i 到右 j 的权值,要用一个循环来判断哪边的生命值先为 0

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define MOD 16007
#define INF 0x3f3f3f3f
#define N 1001
#define LL long long
using namespace std;
int n;
int G[N][N];
int Lx[N],Ly[N];
bool visX[N],visY[N];
int linkX[N],linkY[N];
bool dfs(int x){visX[x]=true;for(int y=1;y<=n;y++){if(!visY[y]){int temp=Lx[x]+Ly[y]-G[x][y];if(temp==0){visY[y]=true;if(linkY[y]==-1 || dfs(linkY[y])){linkX[x]=y;linkY[y]=x;return true;}}}}return false;
}
void update(){int minn=INF;for(int i=1;i<=n;i++)if(visX[i])for(int j=1;j<=n;j++)if(!visY[j])minn=min(minn,Lx[i]+Ly[j]-G[i][j]);for(int i=1;i<=n;i++)if(visX[i])Lx[i]-=minn;for(int i=1;i<=n;i++)if(visY[i])Ly[i]+=minn;
}
int KM(){memset(linkX,-1,sizeof(linkX));memset(linkY,-1,sizeof(linkY));for(int i=1;i<=n;i++){Lx[i]=Ly[i]=0;for(int j=1;j<=n;j++)Lx[i]=max(Lx[i],G[i][j]);}for(int i=1;i<=n;i++){while(true){memset(visX,false,sizeof(visX));memset(visY,false,sizeof(visY));if(dfs(i))break;elseupdate();}}int ans=0;for(int i=1;i<=n;i++)if(linkY[i]!=-1)ans+=G[linkY[i]][i];return ans;
}
int v[N],h[N],p[N],a[N],b[N];
int attack(int x,int y){int hpX=h[x],hpY=p[y];int vX=a[x],vY=b[y];while(hpX&&hpY){hpY-=vX;if(hpY<=0)return v[x];hpX-=vY;if(hpX<=0)return -v[x];}
}
int main(){while(scanf("%d",&n)!=EOF&&(n)){for(int i=1;i<=n;i++)scanf("%d",&v[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]);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)G[i][j]=attack(i,j);for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){G[i][j]=G[i][j]*(n+1);if(i==j)G[i][j]++;}}int ans=KM();int temp1=ans/(n+1);int temp2=ans%(n+1);if(temp1<=0)printf("Oh, I lose my dear seaco!\n");elseprintf("%d %.3lf%%\n",temp1,100*temp2*1.0/n);}return 0;
}

My Brute(HDU-3315)相关推荐

  1. 有源汇有上下界最大流/最小流 配题(HDU 3157)

    因为是有源汇所以设源点为 s,汇点为 t. 有源汇有上下界最大流: 连接一条 t 指向 s 的边,容量为 INF. 通过上述步骤,现在图变成了无源汇网络. 引入超级源点 S,超级汇点 T. 连接一条 ...

  2. 最大表示法--环形字符串最大字典序(HDU 5442)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 问题概述:n个字符围成一个环,请从这个环中找出字典序最大的长度为n的字符串,输出它的起始点和方向(0顺1 ...

  3. HDU2019多校第二场 1009(HDU 6599) I Love Palindrome String(回文树(自动机)+manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 解题思路: 回文自动机求每个本质不同的子串出现的次数,同时记录每个节点i代表的回文串第一次出现的 ...

  4. S-Nim (HDU 1536)组合博弈SG多组游戏

    S-Nim 题目链接 Problem Description Arthur and his sister Caroll have been playing a game called Nim for ...

  5. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

  6. (HDU - 1847)Good Luck in CET-4 Everybody!(博弈)

    题目链接:Good Luck in CET-4 Everybody! - HDU 1847 - Virtual Judge (ppsucxtt.cn) 题目是中文的,我在这就不翻译题意了. 先说一种打 ...

  7. 美素数(HDU 4548)(打表,简化时间复杂度)

    相信大家都喜欢美的东西,让我们一起来看看美素数吧. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为"美素数",如29,本身是素数,而且2+9 = 11 ...

  8. 单词数(HDU 2072)

    lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题. Input 有多组数据,每组一行,每组就 ...

  9. Ant Trip(HDU 3018)---多笔画问题

    题目链接 题目描述 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together w ...

  10. 机器人的舞蹈(hdu 2232)

    机器人的舞蹈 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

最新文章

  1. 解决Moodle日历乱码的最佳方案
  2. Salesforce - soql 多字段多值过滤查询思路
  3. Angular 2 DI系统中 函数forwardRef 的作用?
  4. thinkingback no5
  5. 计算机网络基础:网络标准相关知识介绍
  6. AspNetCore结合Redis实践消息队列
  7. android代码旋转屏幕,Android Activity源码分析--windowmanager屏幕旋转研究
  8. a标签实现点击复制文本
  9. 用IDEA进行git版本控制
  10. 串口波特率自适应算法(仿真通过)
  11. 高通平台msm8916修改开机logo 高通平台修改LK(bootloader)开机logo
  12. BZOJ1006神奇的国度
  13. 魅族手机安装Google Play
  14. 单片机只会调库和复制别人的代码是什么水平?
  15. Java书签 #MyBatis之setMapperLocations配置多个mapper路径的两种方法详解
  16. 计算机应用基础0039答案,计算机应用基础-0039(贵州电大-课程号:5205004)参考资料...
  17. 行人重识别(1)——行人检测综述
  18. java程序员 待遇_现在的java程序员薪资待遇怎么样?
  19. CTO语录:真正技术高手是如何炼成的?
  20. “Tplink端口映射设置”教程---快解析

热门文章

  1. 了解VS2005为你的MFC程序做的一些事
  2. 5G时代,为什么主流大厂纷纷布局这项技术?
  3. STM32之ADC单通道单次例程
  4. 重构 - 美股行情系统APP推送改造
  5. XFire WebService开发快速起步
  6. 数据源管理 | OLAP查询引擎,ClickHouse集群化管理
  7. imagej链接资源
  8. 记录kylin成功启动,访问页面404问题
  9. 操作系统已经向SQL Server 返回了错误21
  10. 微信小程序周报(第八期)