跳到主要內容

uva 10080











From Evernote:



uva 10080



這題我沒有用簡潔的的寫法,中規中矩地用最大流

[sourcecode language="cpp"]
//============================================================================
// Name : Gopher II.cpp
// Date : 2013 2013/2/5 下午10:24:07
// Author : GCA
//============================================================================
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define Set(a,s) memset(a,s,sizeof(a))
#define Write(w) freopen(w,"w",stdout)
#define Read(r) freopen(r,"r",stdin)
#define Pln() printf("\n")
#define I_de(x,n)for(int i=0;i<n;i++)printf("%d ",x[i]);Pln()
#define De(x)printf(#x"%d\n",x)
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define Pmz(dp,nx,ny)for(int hty=0;hty<ny;hty++){for(int htx=0;htx<nx;htx++){\
printf("%d ",dp[htx][hty]);}Pln();}
#define M 250
#define PII pair<int,int>
#define PB push_back
#define oo INT_MAX
#define Set_oo 0x3f
#define Is_debug true
#define debug(...) if(Is_debug)printf("DEBUG: "),printf(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define eps 1e-6
bool xdy(double x,double y){return x>y+eps;}
bool xddy(double x,double y){return x>y-eps;}
bool xcy(double x,double y){return x<y-eps;}
bool xcdy(double x,double y){return x<y+eps;}
int min3(int x,int y,int z){
int tmp=min(x,y);
return min(tmp,z);
}
int max3(int x,int y,int z){
int tmp=max(x,y);
return max(tmp,z);
}
struct edge{
int to,cap;
}etmp;
vector<edge> mz[M];
double mx[M],my[M];
int n,m,s,v;
void addpath(int x,int y){
etmp.cap=1;
etmp.to=y;
mz[x].PB(etmp);
etmp.cap=0;
etmp.to=x;
mz[y].PB(etmp);
}
double getdis(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int flow[M][M];
int father[M];
int q[90000000];
int front,rear;
void ed(){
int pflow[M];
Set(flow,0);
int maxflow=0;
while(1){
front=rear=0;
Set(pflow,0);
pflow[n+m]=oo;
q[front++]=n+m;
while(front>rear){
int u=q[rear++];
FOR(it,mz[u]){
int cap=(*it).cap,v=(*it).to;
if(!pflow[v]&&cap>flow[u][v]){
father[v]=u;
pflow[v]=min(pflow[u],cap-flow[u][v]);
q[front++]=v;
// debug("%d %d %d\n",u,v,pflow[v]);
}
}
}
if(!pflow[n+m+1])break;
// for(int i=n+m+1;i!=n+m;i=father[i]){
// debug("%d\n",i);
// }
// Pln();
maxflow+=pflow[n+m+1];
for(int i=n+m+1;i!=n+m;i=father[i]){
flow[father[i]][i]+=pflow[n+m+1];
flow[i][father[i]]-=pflow[n+m+1];
}

}
printf("%d\n",n-maxflow);

}
int main() {
ios_base::sync_with_stdio(0);
while(~scanf("%d%d%d%d",&n,&m,&s,&v)){
for(int i=0;i<n;i++){
scanf("%lf%lf",&mx[i],&my[i]);
addpath(n+m,i);
}
double hx,hy;
for(int i=0;i<m;i++){
scanf("%lf%lf",&hx,&hy);
addpath(i+n,m+n+1);
for(int j=0;j<n;j++){
if(xcdy(getdis(mx[j],my[j],hx,hy)/(v*1.0),s)){
addpath(j,i+n);
}
}
}
ed();
for(int i=0;i<=m+n+1;i++)mz[i].clear();

}
}

[/sourcecode]

留言