zoukankan      html  css  js  c++  java
  • hdu 2389 Rain on your Parade

    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.
    // 这题是很裸的二分匹配了 主要是HK二分匹配算法的模板
    // 表示不清楚为什么会比直接dfs快蛮多、不会证明 呵呵
    #include <iostream> #include <math.h> #include <vector> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N=3010; struct cor { int x,y; }X[N],Y[N]; int speed[N]; bool visit[N]; int cx[N],cy[N]; int dx[N],dy[N]; vector <int> G[N]; double dis(int i,int j) { return sqrt(double( (X[i].x-Y[j].x)*(X[i].x-Y[j].x) + (X[i].y-Y[j].y)*(X[i].y-Y[j].y) ) ); } int m,n; bool search() { memset(dx,0,sizeof(dx)); memset(dy,0,sizeof(dy)); queue <int > Q; int i,u,v; bool flag=0; for(i=1;i<=m;i++) if(!cx[i]) Q.push(i); while(!Q.empty()) { u=Q.front();Q.pop(); for(i=0;i<G[u].size();i++) { v=G[u][i]; if(!dy[v]) { dy[v]=dx[u]+1; if(!cy[v]) flag=true; else { dx[cy[v]]=dy[v]+1; Q.push(cy[v]); } } } } return flag; } bool dfs(int u) { int i,v; for(i=0;i<G[u].size();i++) { v=G[u][i]; if(!visit[v]&&dy[v]==dx[u]+1) { visit[v]=true; if(!cy[v]||dfs(cy[v])) { cy[v]=u; cx[u]=v; return true; } } } return false; } int Maxmatch() { memset(cx,0,sizeof(cx)); memset(cy,0,sizeof(cy)); int ans=0; while(search()) { memset(visit,0,sizeof(visit)); for(int i=1;i<=m;i++) if(!cx[i]&&dfs(i)) ans++; } return ans; } int main() { int t,cnt=1; scanf("%d",&t); while(t--) { int tm; int i,j; scanf("%d",&tm); scanf("%d",&m); for(i=1;i<=m;i++) scanf("%d %d %d",&X[i].x,&X[i].y,&speed[i]); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d %d",&Y[i].x,&Y[i].y); for(i=1;i<=m;i++) { G[i].clear(); for(j=1;j<=n;j++) if(speed[i]*tm>=dis(i,j)) G[i].push_back(j); } printf("Scenario #%d:\n",cnt++); printf("%d\n\n",Maxmatch()); } return 0; }
  • 相关阅读:
    19.08.12 知识点的记录
    19.08.09 知识点的记录
    keil编译生成bin文件的方法
    python 虚拟环境virtualenv
    RT_Thread GD32F303 片上flash使用fal组件
    esp8266 deepsleep唤醒不工作打印
    5V 电源 适配器 空载耗电量 自身电量 消耗功率
    keil 更换jlink脚本版本
    ESP8266 NONOS SmartConfig配网(安信可公众号配网)
    windows安装esp开发环境
  • 原文地址:https://www.cnblogs.com/372465774y/p/3043820.html
Copyright © 2011-2022 走看看