HDU 3315 My Brute 费用流+求错位率(好题)

点击打开链接

 

 

My Brute

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


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!
 


 

Author
starvae
 


 

Source
 


 

Recommend
wxl

 

题意:有两组人就行PK,编号都是1到N。并且每个人都有HP和ATK.。并且对应第i个人,如果赢了就的v[i]分,输了就丢失v[i]分。开始0分。可以改变参赛队员的顺序。让你求能够获得的最大分数和改变参赛队员顺序占一开始顺序的比例。

求最大分数的话,就用二分匹配来算。此题好就好在要求一个错位的概率。如何求呢,就是给边标记一下。先将边扩大一定的比例,这个比例也不是随便多少倍都行,而要大于N的值,只有这样最后求得的最大分数除以倍数才是实际分数。如果标记过小的话,就会造成混淆。求错位概率就用求得的最大分数模上扩大的倍数,在除以总共的个数N即可。

#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#define inf  0x3f3f3f3f
#define MAX 1010
using namespace std;
int g[107][107];
int lx[107],ly[107],slack[107],match[107];
bool visx[107],visy[107];
int v[107],h[107],p[107],a[107],b[107];
int n;

bool dfs(int cur)
{
    visx[cur]=true;
    for(int y=1;y<=n;y++)
    {
        if(visy[y])
            continue;
        int t=lx[cur]+ly[y]-g[cur][y];
        if(t==0)
        {
            visy[y]=true;
            if(match[y]==-1||dfs(match[y]))
            {
                match[y]=cur;
                return true;
            }
        }
        else if(slack[y]>t)
            slack[y]=t;
    }
    return false;
}

int KM()
{
    memset(match,-1,sizeof(match));
    memset(ly,0,sizeof(ly));
    for(int i=1; i<=n; i++)
    {
        lx[i]=-inf;
        for(int j=1; j<=n; j++)
        {
            if(g[i][j]>lx[i])
                lx[i]=g[i][j];
        }
    }
    for(int x=1;x<=n;x++)
    {
        for(int i=1;i<=n;i++)
            slack[i]=inf;
        while(true)
        {
            memset(visx,false,sizeof(visx));
            memset(visy,false,sizeof(visy));
            if(dfs(x))
                break;
            int d=inf;
            for(int i=1;i<=n;i++)
                if(!visy[i]&&d>slack[i])
                    d=slack[i];
            for(int i=1;i<=n;i++)
                if(visx[i])
                    lx[i]-=d;
            for(int i=1;i<=n;i++)
                if(visy[i])
                    ly[i]+=d;
                else
                    slack[i]-=d;
        }
    }
    int result=0,flag=0;
    for(int i=1;i<=n;i++)
    {
        if(match[i]==-1||g[match[i]][i]==-inf)
            continue;
        result+=g[match[i]][i];

    }
    return result;
}

bool win(int i,int j)
{
    int x,y;
    if(p[j]%a[i]==0)
        x=p[j]/a[i];
    else
        x=p[j]/a[i]+1;
    if(h[i]%b[j]==0)
        y=h[i]/b[j];
    else
        y=h[i]/b[j]+1;
    if(x<=y)
        return true;
    else
        return false;
}

int main()
{
    while(scanf("%d",&n),n)
    {
        memset(g,0,sizeof(g));
        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]=-inf;
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                if(win(i,j))
                {
                    if(i==j)
                        g[i][j]=v[i]*100+1;
                    else
                        g[i][j]=v[i]*100;
                }
                else
                {
                    if(i==j)
                        g[i][j]=-v[i]*100+1;
                    else
                        g[i][j]=-v[i]*100;
                }
        int ans=KM();
        int anss=ans/100;
        if(ans<=0)
            printf("Oh, I lose my dear seaco!\n");
        else
            printf("%d %.3lf%%\n",anss,100*(double)(ans%100)/n);
    }
    return 0;
}


 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值