再探 3126 Nova //二分逼近+多重匹配
来源:互联网 发布:mysql 创建唯一索引 编辑:程序博客网 时间:2024/06/02 07:18
Nova
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 566 Accepted Submission(s): 135
The first line of each case consists of three integers N, M, K, indicating the number of lich, the number of wisps and the number of trees. The next N lines, each line consists of four integers x, y, r, t indicating the coordinate of that a lich, the radius of the attack range that lich’s Frost Nova can reach and the value of cool down time. The next M lines, each line consists of two integers x, y indicating the coordinate of each wisp. The last K lines, each line consists of three integers x, y, r, indicating the coordinate and radius of a tree. A lich cannot attack a wisp if the segment between them has a common point with the tree. The lich, wisp and trees will not overlap with each other.
Constrains
0 < T <= 20
0 <= N, M, K <= 200
-10000 <= x, y <= 10000
0 <= r, t <= 10002
12 3 1-100 0 100 3100 0 100 5-100 -10100 10110 115 5 10
5
#include<stdio.h>
#include<string.h>
#include<math.h>
const int maxint=1<<30-1;
const double eps=1e-8;
int sign(double x)
{
return (x>eps)-(x<-eps);
}
struct point
{
double x,y;
point() {}
point(double xx,double yy):x(xx),y(yy) {}
point operator+ (const point& a) const { return point(x+a.x,y+a.y); }
point operator- (const point& a) const { return point(x-a.x,y-a.y); }
double operator* (const point& a) const { return x*a.y-y*a.x;}
double dot(const point& a) const { return x*a.x+y*a.y;}
double dist() const { return x*x+y*y;}
double length() const { return sqrt(dist()); }
void input() { scanf("%lf%lf",&x,&y); }
void output() const { printf("%lf %lf/n",x,y);}
}lich[201],wisp[201],tree[201];
int link[201][201];
int n,m,k,tmax;
bool flag,used[201];
int r[201],t[201],tr[201],tnow[201];
bool g[201][201];
bool can(int t)
{
for(int i=0;i<n;i++)
{
if(used[i]==0&&g[i][t])
{
used[i]=1;
if(link[i][0]<tnow[i])
{
link[i][++link[i][0]]=t;
return true;
}
else
{
for(int j=1; j<=link[i][0]; j++)
if(can(link[i][j]))
{
link[i][j]=t;
return true;
}
}
}
}
return false;
}
bool MaxMatch(int x)
{
for(int i=0;i<n;i++) tnow[i]=x/t[i]+1;
for(int i=0;i<n;i++) link[i][0]=0;
for(int i=0;i<m;i++)
{
memset(used,false,sizeof(used));
if(!can(i)) return false;
}
return true;
}
void solve()
{
int fir=0,sec=tmax*m;
int ans=0;
while(fir<sec)
{
int mid=(fir+sec)>>1;
if(MaxMatch(mid))
{
flag=true;
ans=mid;
sec=mid;
}
else
fir=mid+1;
}
if(flag) printf("%d/n",ans);
else printf("-1/n");
}
bool nova(point& a,point& b,int r)
{
if(sign((a-b).dist()-r*r)>0) return false;
for(int i=0;i<k;i++)
{
if(sign(fabs((tree[i]-a)*(b-a))/(a-b).length()-tr[i])>0) continue;
if(sign((tree[i]-a).dot(b-a))<0 || sign((tree[i]-b).dot(a-b)<0)) continue;
return false;
}
return true;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
tmax=0;
flag=false;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<n;i++)
{
lich[i].input();
scanf("%d%d",&r[i],&t[i]);
if(t[i]>tmax) tmax=t[i];
}
for(int i=0;i<m;i++) wisp[i].input();
for(int i=0;i<k;i++)
{
tree[i].input();
scanf("%d",&tr[i]);
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
g[i][j]=nova(lich[i],wisp[j],r[i]);
solve();
}
return 0;
}
- 再探 3126 Nova //二分逼近+多重匹配
- 二分多重匹配模板
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- poj2289多重二分匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- hdu1669 二分多重匹配+二分
- 二分图多重匹配问题
- 二分图的多重匹配
- 二分图多重匹配--poj2289
- 二分图多重匹配--poj2584
- poj 2112(二分+多重匹配)
- HDU 1669 二分+多重匹配
- 二分图的多重匹配
- 使用 datetimepicker 控件是不规范的设计吗?
- 使用 datetimepicker 控件是不规范的设计吗?
- 使用 datetimepicker 控件是不规范的设计吗?
- 心情
- link
- 再探 3126 Nova //二分逼近+多重匹配
- 网站测试工具汇总
- Server Error in Application. IIS问题
- javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver
- windows live writer中配置csdn帐户
- java.lang.NoSuchMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext错误解决
- redo与undo
- 学习淘宝API
- Qt 4.6.3 移植到mini2440的详细记录 (基于CentOS - 5.4)