题目描述

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 ;
}
 

Coin Slider的更多相关文章

  1. 19个非常有用的 jQuery 图片滑动插件和教程

    jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入精美的效果.今天 ...

  2. 40款非常棒的 jQuery 插件和制作教程(系列一)

    jQuery 在现在的 Web 开发项目中扮演着重要角色,jQuery 让网站有更好的可用性和用户体验,让访问者对网站留下非常好的印象.jQuery以其插件众多.独特.轻量以及支持大规模的网站开发闻名 ...

  3. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  4. 跟着《beginning jquery》学写slider插件并借助自定义事件改进它

    <beginning jquery>是一本很不错的学习jquery的书,作者的讲解深入浅出,很适合初学者,在最后一章里面,作者把前面所有的点结合起来完成了一个轮播图的jquery插件.实现 ...

  5. 推荐:图片轮播插件Nivo Slider

          因为项目需要一款切换样式多一些的轮播插件,不经意找到了NivoSlider,非常好用,比bootstrap要好用,而且样式丰富.值得注意的是,这款插件是在MIT协议下免费的.        ...

  6. 自制 移动端 纯原生 Slider滑动插件

    在Google搜关键字“slider”或“swiper”能找到一大堆相关插件,自己造轮子是为了能更好的理解其中的原理. 给这个插件取名为“veSlider”是指“very easy slider”非常 ...

  7. 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing

    [源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...

  8. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  9. [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

随机推荐

  1. elasticsearch 嵌套对象使用Multi Match Query、query_string全文检索设置

    参考: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-nested-type.html https://sta ...

  2. 2019-9-2-win10-uwp-隐私声明

    title author date CreateTime categories win10 uwp 隐私声明 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 1 ...

  3. 2018-2-13-win10-UWP-九幽登录

    title author date CreateTime categories win10 UWP 九幽登录 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  4. 表结构转excel

    SELECTCOLUMN_NAME 列名,COLUMN_TYPE 数据类型,DATA_TYPE 字段类型,CHARACTER_MAXIMUM_LENGTH 长度,IS_NULLABLE 是否为空,CO ...

  5. JavaSE---Runtime类

    1.概述 1.1 Runtime类  代表 java程序运行时环境: 1.2 Runtime类  提供的类方法: getRuntime():获取Runtime实例: gc():通知垃圾回收器回收资源: ...

  6. Delphi DBGrid 实现复选框

    1 在数据库对应的表中加入  bit 列验证是否被选中 然后dbgrid第一列的filedname是bit列 在DBgrid的onDrawColumnCell事件中写: procedure DBGri ...

  7. shell快速入门

    $? 表示上一个命令退出的状态,0表示执行正常,不等于0表示执行不正常. $$ 表示当前进程编号 $ 表示当前脚本名称 $# 表示参数的个数,常用于循环 $*和$@ 都表示参数列表 $n 表示n位置的 ...

  8. vue 前后端数据交互问题解决

    先在vue项目中配置好路由组件路由 然后写相应组件 2 后端 写接口赔路由 第三  解决跨域问题 处理数据交互 这样前端就拿到了数据

  9. NetHogs——Linux下按进程实时统计网络带宽利用率

    Debian/Ubuntu下安装很简单,执行:apt-get install nethogs 就可以安装. CentOS/RHEL下建议先安装上EPEL,再执行:yum install libpcap ...

  10. 存储-docker数据共享(13)

    容器与 host 共享数据 我们有两种类型的 data volume,它们均可实现在容器与 host 之间共享数据,但方式有所区别. 对于 bind mount 是非常明确的:直接将要共享的目录 mo ...