HDU2389Rain on your Parade 二分匹配Hopcroft-Karp

5 篇文章 0 订阅
1 篇文章 0 订阅
Rain on your Parade
Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 3963    Accepted Submission(s): 1320


Problem Description
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 <= si <= 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



Source
HDU 2008-10 Public Contest 

裸二分匹配
但是数据量很大,用匈牙利O(VE)的复杂度,肯定会超时
Hopcroft-Karp复杂度为O(sqrt(V)*E),妥妥的


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
#include<queue>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>

const int NX = 3005;
const int NY = NX;

struct Edge{
    int to,next;
}edge[NX*NY];
int head[NX];
inline void addEdge(int k,int u,int v){
    edge[k].to=v;
    edge[k].next=head[u];
    head[u]=k;
}

int nx,ny;//左右集合顶点数
int cx[NX],cy[NY];//x/y配对到的点的标号 标号:x:1-nx y:1-ny
int disX[NX],disY[NY];//顶点距离标号
int dis;//可匹配点距离
bool bmask[NY];//寻找增广路时的标志数组

bool searchPath(){//是否存在增广路
    queue<int>que;
    dis=INF;
    fill(disX,disX+nx+1,-1);
    fill(disY,disY+ny+1,-1);
    for(int i=1;i<=nx;++i){
        if(cx[i]==-1){
            que.push(i);
            disX[i]=0;
        }
    }
    while(!que.empty()){
        int u=que.front();
        que.pop();
        if(disX[u]>dis){
            break;
        }
        for(int i=head[u];i!=-1;i=edge[i].next){
            int v=edge[i].to;
            if(disY[v]==-1){
                disY[v]=disX[u]+1;
                if(cy[v]==-1){
                    dis=disY[v];
                }
                else{
                    disX[cy[v]]=disY[v]+1;
                    que.push(cy[v]);
                }
            }
        }
    }
    return INF!=dis;
}

int findPath(int u){
    for(int i=head[u];i!=-1;i=edge[i].next){
        int v=edge[i].to;
        if(!bmask[v]&&disY[v]==disX[u]+1){
            bmask[v]=1;
            if(cy[v]!=-1&&disY[v]==dis){//disY[v]==dis 但是v已经被匹配了
                continue;
            }
            if(cy[v]==-1||findPath(cy[v])){//v未被匹配 或者 v被匹配 但是匹配v的点 又找到新的匹配点
                cy[v]=u;
                cx[u]=v;
                return 1;
            }
        }
    }
    return 0;
}

int maxMatch(){
    int res=0;
    fill(cx,cx+nx+1,-1);
    fill(cy,cy+ny+1,-1);
    while(searchPath()){
        fill(bmask,bmask+ny+1,false);
        for(int i=1;i<=nx;++i){
            if(cx[i]==-1){
                res+=findPath(i);
            }
        }
    }
    return res;
}

int x[NX],y[NX],s[NX];
int x_[NY],y_[NY];

int distance(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int slove(){
    int t;
    scanf("%d",&t);
    scanf("%d",&nx);
    fill(head,head+nx+1,-1);
    for(int i=1;i<=nx;++i){
        scanf("%d%d%d",x+i,y+i,s+i);
    }
    scanf("%d",&ny);
    int numE=0;
    for(int i=1;i<=ny;++i){
        scanf("%d%d",x_+i,y_+i);
        for(int j=1;j<=nx;++j){
            int dis=distance(x_[i],y_[i],x[j],y[j]);
            if(t*t*s[j]*s[j]>=dis){
                addEdge(numE++,j,i);
            }
        }
    }
    return maxMatch();
}

int main()
{
    //freopen("/home/lu/Documents/r.txt","r",stdin);
    //freopen("/home/lu/Documents/w.txt","w",stdout);
    int T;
    scanf("%d",&T);
    for(int t=1;t<=T;++t){
        int ans=slove();
        printf("Scenario #%d:\n%d\n\n",t,ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值