#HDU3315#My Brute(Km+余数巧用)

6 篇文章 0 订阅

My Brute

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1425    Accepted Submission(s): 557


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!

题目大意:

有两队人在打架,分别一共进行N场比赛,给出每场比赛的分值V[i](赢了就加,输了就减)

给出H[i],P[i]分别表示每个人的血量,A[i],B[i]分别表示每个人的攻击力

打架的方式是H先打P,P减掉A的血,然后P再打H,H减掉B的血,最后谁先没血了(<=0)谁就输了

P中人的顺序不变,改变H中人的顺序,使得H队最后得分尽量高,大于0输出得分,否则"Oh, I lose my dear seaco!"

当有多组解时,要求改变位置尽可能少。


此题解法很巧妙,因为得分都是小于等于1000的,并且只有90个人,所以我们建图时将得分全部*100,当i与j位置相同时再+1,

这样,在不影响答案的情况下,会尽量选择i==j的那条边,最后Ans/100,Ans%100所得到的数全是因为选择了i==j的边造成的

然后一次完备匹配即可。


BFS实现:

Status Accepted
Time 78ms
Memory 1636kB
Length 1875
Lang G++
Submitted
Shared

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int Max=100;
const int inf=0x3f3f3f3f;

int N;
bool viy[Max];
int pre[Max],slack[Max],match[Max],wx[Max],wy[Max];
int V[Max],H[Max],P[Max],A[Max],B[Max];
int map[Max][Max];

void getint(int&num){
    char c;int flag=1;num=0;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}
    num*=flag;
}
void pre_work(){
	for(int i=1; i<=N; ++i)
		for(int j=1; j<=N; ++j){
			int a=H[i]/B[j]+(H[i]%B[j]?1:0);
			int b=P[j]/A[i]+(P[j]%A[i]?1:0);
			if(a>=b)	map[i][j]=V[i]*100;
			else map[i][j]=-V[i]*100;
			if(i==j)	map[i][j]++;
		}
}

void Bfs(int k){
	int px,py=0,yy=0,delta;
	for(int i=1; i<=N; ++i)
		pre[i]=0,slack[i]=inf;
	match[py]=k;
	do{
		delta=inf;
		px=match[py];
		viy[py]=1;
		for(int i=1; i<=N; ++i)if(!viy[i]){
			if(wx[px]+wy[i]-map[px][i]<slack[i])
				slack[i]=wx[px]+wy[i]-map[px][i],pre[i]=py;
			if(slack[i]<delta)
				delta=slack[i],yy=i;
		}
		for(int i=0; i<=N; ++i)
			if(viy[i])	wx[match[i]]-=delta,wy[i]+=delta;
			else slack[i]-=delta;
		py=yy;
	}while(match[py]);
	while(py){
		match[py]=match[pre[py]];
		py=pre[py];
	}
}

void Km(){
	for(int i=1; i<=N; ++i){
		wx[i]=-inf,wy[i]=0,match[i]=0;
		for(int j=1; j<=N; ++j)
			wx[i]=max(wx[i],map[i][j]);
	}
	for(int i=1; i<=N; ++i)
		memset(viy,0,sizeof(viy)),Bfs(i);
}

int main(){
	while(~scanf("%d",&N)&&N){
		for(int i=1; i<=N; ++i)
			getint(V[i]);
		for(int i=1; i<=N; ++i)
			getint(H[i]);
		for(int i=1; i<=N; ++i)
			getint(P[i]);
		for(int i=1; i<=N; ++i)
			getint(A[i]);
		for(int i=1; i<=N; ++i)
			getint(B[i]);
		pre_work();
		Km();
		int cnt,Ans=0;
		for(int i=1; i<=N; ++i)
			Ans+=map[match[i]][i];
		cnt=Ans%100;
		if(Ans>0)
			printf("%d %.3lf%%\n",Ans/100,100.0*cnt/N);
		else puts("Oh, I lose my dear seaco!");
	}
	return 0;
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值