F - Rain on your Parade HDU2389 (二分图 Hopcroft-Carp算法)

You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It’s a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It could be the perfect end of a beautiful day.
But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, “I know that breeze! It means its going to rain heavily in just a few minutes!” Your guests all wear their best dresses and really would not like to get wet, hence they stand terrified when hearing the bad news.
You have prepared a few umbrellas which can protect a few of your guests. The umbrellas are small, and since your guests are all slightly snobbish, no guest will share an umbrella with other guests. The umbrellas are spread across your (gigantic) garden, just like your guests. To complicate matters even more, some of your guests can’t run as fast as the others.
Can you help your guests so that as many as possible find an umbrella before it starts to pour?

Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, find out how many of your guests can at most reach an umbrella. Two guests do not want to share an umbrella, however.
Input
The input starts with a line containing a single integer, the number of test cases.
Each test case starts with a line containing the time t in minutes until it will start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= 3000), followed by m lines containing x- and y-coordinates as well as the speed si in units per minute (1 <= s i <= 3000) of the guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <= 3000), the number of umbrellas, followed by n lines containing the integer coordinates of each umbrella, separated by a space.
The absolute value of all coordinates is less than 10000.
Output
For each test case, write a line containing “Scenario #i:”, where i is the number of the test case starting at 1. Then, write a single line that contains the number of guests that can at most reach an umbrella before it starts to rain. Terminate every test case with a blank line.
Sample Input
2
1
2
1 0 3
3 0 3
2
4 0
6 0
1
2
1 1 2
3 3 2
2
2 2
4 4
Sample Output
Scenario #1:
2

Scenario #2:
2

题意:

   先给出距离下雨的时间,再给出n个人和m把雨伞的坐标位置,以及每个人的奔跑速
   度。每把雨伞只能供一人使用。求在下雨前最多有多少人可以拿到雨伞。

Hopcroft-Carp算法 并不是太理解 找了个板子

#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<queue>
typedef long long ll;
using namespace std;
const int N=3010;
const int INF=0x3f3f3f3f3f;
int bmap[N][N];
int cx[N],cy[N];
int dis,n,m,t;
int dx[N],dy[N],used[N];
struct node
{
    int x,y,s;
}st[N],en[N];
bool answer(node A,node B)
{
    double ans=sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
    if(A.s*t>=ans)
    {
        return true;
    }
    else{
    return false;
    }
}
bool searchpath()
{
    queue<int>Q;
    dis=INF;
    memset(dx,-1,sizeof(dx));
    memset(dy,-1,sizeof(dy));
    for(int i=1;i<=m;i++)
    {
        if(cx[i]==-1)
        {
            Q.push(i);
            dx[i]=0;
        }
    }
    while(!Q.empty())
    {
        int u=Q.front();
        Q.pop();
        if(dx[u]>dis)
            break;
        for(int v=1;v<=n;v++)
        {
            if(bmap[u][v]&&dy[v]==-1)
            {
                dy[v]=dx[u]+1;
                if(cy[v]==-1)
                    dis=dy[v];
                else
                {
                    dx[cy[v]]=dy[v]+1;
                    Q.push(cy[v]);
                }
            }
        }
    }
    return dis!=INF;
}
bool DFS(int u)
{
    for(int v=1;v<=n;v++)
    {
        if(!used[v]&&bmap[u][v]&&dy[v]==dx[u]+1)
        {
            used[v]=1;
            if(cy[v]!=-1&&dy[v]==dis)
                continue;
            if(cy[v]==-1||DFS(cy[v]))
            {
                cy[v]=u;
                cx[u]=v;
                return true;
            }
        }
    }
    return false;
}
int maxmatch()
{
    int sum=0;
    memset(cx,-1,sizeof(cx));
    memset(cy,-1,sizeof(cy));
    while(searchpath())
    {
        memset(used,0,sizeof(used));
        for(int i=1;i<=m;i++)
        {
            if(cx[i]==-1&&DFS(i))
                sum++;
        }
    }
    return sum;
}
int main()
{
    int T;
    scanf("%d",&T);
    int Case=1;
    while(T--)
    {
        memset(bmap,0,sizeof(bmap));
        scanf("%d",&t);
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&st[i].x,&st[i].y,&st[i].s);
        }
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&en[i].x,&en[i].y);
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(answer(st[i],en[j]))
                {
                    bmap[i][j]=1;
                }
            }
        }
        printf("Scenario #%d:\n",Case++);
        printf("%d\n\n",maxmatch());
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Type-C Cable是一种符合Universal Serial Bus Type-C Cable and Connector Specification R2.0标准的USB-C数据线。\[1\]根据引用\[2\]的描述,由于非公开协议的限制,Intel TBT Gen3开始已经可以应用在USB-C Port上,所以对于TBT的相关Cable应该也会有兼容。而根据引用\[3\]的描述,谱瑞(Parade)收购了睿思科技(Fresco Logic),这可能意味着他们在USB这块有一定的技术积累。因此,Type-C Cable可能具备兼容TBT和USB 3.0的功能。 #### 引用[.reference_title] - *1* [【硬件】【USB】【Type-C】](https://blog.csdn.net/syjie19900426/article/details/109054926)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Usb Type-C 1.2 Usb Type-C Cable](https://blog.csdn.net/Strider_kong/article/details/126056566)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [PS188——谱瑞(Parade)推动的 Type-C扩展坞红海战略](https://blog.csdn.net/Type_C_Ken/article/details/124349798)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值