题目描述

You are playing a coin puzzle. The rule of this puzzle is as follows:

There are N coins on a table. The i-th coin is a circle with ri radius, and its center is initially placed at (sxi,syi). Each coin also has a target position: you should move the i-th coin so that its center is at (txi,tyi). You can move coins one by one and can move each coin at most once. When you move a coin, it must move from its initial position to its target position along the straight line. In addition, coins cannot collide with each other, including in the middle of moves.

The score of the puzzle is the number of the coins you move from their initial position to their target position. Your task is to write a program that determines the maximum score for a given puzzle instance.

输入

The input consists of a single test case formatted as follows.

N
r1 sx1 sy1 tx1 ty1
:
rN sxN syN tx1 tyN
The first line contains an integer N (1≤N≤16), which is the number of coins used in the puzzle. The i-th line of the following N lines consists of five integers: ri,sxi,syi,txi, and tyi (1≤ri≤1,000,−1,000≤sxi,syi,txi,tyi≤1,000,(sxi,syi)≠(txi,tyi)). They describe the information of the i-th coin: ri is the radius of the i-th coin, (sxi,syi) is the initial position of the i-th coin, and (txi,tyi) is the target position of the i-th coin.

You can assume that the coins do not contact or are not overlapped with each other at the initial positions. You can also assume that the maximum score does not change even if the radius of each coin changes by 10−5.

输出

Print the maximum score of the given puzzle instance in a line.

样例输入

3
2 0 0 1 0
2 0 5 1 5
4 1 -10 -5 10

样例输出

2
题意:
给你n(n<=)个圆的圆心坐标和半径,以及他们目的地的圆心坐标
问最多有多少个圆可以不和其他圆相交到达目的地
圆只能走直线且只能移动到目的地 思路:
直接bfs,^16的int记录当前局面,看哪个圆可以移动到目的地而不和其他圆相交就可以扩展到下一个状态
主要问题就是判断一个圆去目的地的路上会不会和其他圆相交
将其他圆的半径加上当前圆的半径,问题就转化成了求圆心线(线段)和其他圆会不会相交的问题
如果线段端点有一个在圆内则一定相交
如果圆心到线段所在直线的距离大于半径一定不相交
否则圆心到两端点的角度都为锐角,则一定相交 (早知道就用double了,炸int调了我两晚上
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=;
int n,ans;
struct Point{
ll x,y;
Point() {}
Point(ll _x,ll _y)
{
x=_x; y=_y;
}
Point operator -(const Point &b) const
{
return Point(x-b.x,y-b.y);
}
ll operator *(const Point &b) const
{
return x*b.x+y*b.y;
}
}p1[N],p2[N];
struct orz{
int s,d;};
ll r[N];
queue<orz>q;
bool vis[<<];
ll dis(Point a,Point b)
{
return (a-b)*(a-b);
}
bool Inter(int i,int j,int op)
{
Point O;
if (op==) O=p2[j]; else O=p1[j];
Point O1=p1[i],O2=p2[i];
int R=r[j]+r[i];
if (dis(O1,O)<R*R || dis(O2,O)<R*R) return ; ll a,b,c,dis1,dis2,ang1,ang2;
if (O1.x==O2.x) a=,b=,c=-O1.x;
else if (O1.y==O2.y) a=,b=,c=-O1.y;
else a=O1.y-O2.y,b=O2.x-O1.x,c=O1.x*O2.y-O1.y*O2.x; dis1=a*O.x+b*O.y+c;
dis1*=dis1;
dis2=(a*a+b*b)*(R*R);
if (dis1>=dis2) return ; ang1=(O.x-O1.x)*(O2.x-O1.x)+(O.y-O1.y)*(O2.y-O1.y);
ang2=(O.x-O2.x)*(O1.x-O2.x)+(O.y-O2.y)*(O1.y-O2.y);
if (ang1> && ang2>)return ;
return ;
}
bool check(int x,int s)
{ bool flag=;
for (int i=;i<n;i++)
{
if (i==x) continue;
if (s&(<<i)) flag&=Inter(x,i,);
else flag&=Inter(x,i,);
if (!flag) break;
}
return flag;
}
void bfs()
{
ans=;
q.push({,});
vis[]=;
while (!q.empty())
{
orz now=q.front(); q.pop();
//for (int i=0;i<n;i++) cout<<((now.s>>i)&1); cout<<endl;
ans=max(ans,now.d);
for (int i=;i<n;i++)
{
if ((now.s&(<<i))== && !vis[now.s|(<<i)] && check(i,now.s) )
{
q.push({now.s|(<<i),now.d+});
vis[now.s|(<<i)]=;
}
}
}
}
int main()
{
scanf("%d",&n);
for (int i=;i<n;i++) scanf("%lld%lld%lld%lld%lld",&r[i],&p1[i].x,&p1[i].y,&p2[i].x,&p2[i].y);
bfs();
printf("%d\n",ans);
return ;
}
 

最新文章

  1. 【jQuery】--图片轮播
  2. 电脑只有网页打不开,QQ和其他软件都能用
  3. solrCloud+tomcat+zookeeper集群配置
  4. [Node.js] 对称加密、公钥加密和RSA
  5. WebStorm设置手机测试服务器-局域网内其他设备访问
  6. Ubuntu下VIM的安装及其配置——Linux篇
  7. Portal for ArcGIS上传shp文件中文乱码可能情况
  8. 经常遇到Please ensure that adb is correctly located at &#39;D:\java\sdk\platform-tools\adb.exe&#39; and can be e
  9. python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案
  10. HDU 4890 One to Four(2014 Multi-University Training Contest 3)
  11. mysqldump --master-data
  12. 【JAVAWEB学习笔记】网上商城实战5:后台的功能模块
  13. 如何用ABP框架快速完成项目(4) - 如何正确使用ABP?
  14. 5个php实例,细致说明传值与传引用的区别
  15. sohu_news搜狐新闻类型分类
  16. 22 初始模块 random time collections functools
  17. 489. Robot Room Cleaner扫地机器人
  18. win7下把电脑设置成wlan热
  19. java发生邮件(转)
  20. AWS探索及创建一个aws EC2实例

热门文章

  1. 拓展练习部分---打包压缩 及 RPM工具
  2. 虚拟机(JVM)如何加载类
  3. c# 7.0新语法特性
  4. Python--反射(重点)、面向对象内置方法:如__str__、面向对象的软件开发
  5. ZOJ 1610 Count the Colors (线段树区间更新与统计)
  6. 【Flutter学习】可滚动组件之SingleChildScrollView
  7. mysql学习-join的使用
  8. 阿里云Redis 配置
  9. python数据结构:进制转化探索
  10. tidb入门