题目描述

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. layui修改表格行高

    .layui-table-cell { height: auto !important; white-space: normal; }

  2. shell位置参数处理举例

  3. smb.conf - Samba组件的配置文件

    总览 SYNOPSIS smb.conf是Samba组件的配置文件,包含Samba程序运行时的配置信息.smb.conf被设计成可由swat (8)程序来配置和管理.本文件包含了关于smb.conf的 ...

  4. noip2018火柴棒等式

    以下题目摘自洛谷p1149 给你n根火柴棍,你可以拼出多少个形如“A+B=CA+B=C”的等式?等式中的AA.BB.CC是用火柴棍拼出的整数(若该数非零,则最高位不能是00).用火柴棍拼数字0-90− ...

  5. word--->pdf资料转载..

    https://blog.csdn.net/dsn727455218/article/details/80667927

  6. Vue项目中使用Vux

    最近想用vue+vux写一个项目,于是到vux的官网看了文档开始着手搭建项目,但是遇到一些坑.下面简单说下安装vux 的过程.默认已安装vue环境1.安装vux npm install vux --s ...

  7. 带你认识SATA、mSATA 、PCIe和M.2四种接口

    http://mst.zol.com.cn/615/6150989.html 犹记得当年Windows7系统体验指数中,那5.9分磁盘分数,在其余四项的7.9分面前,似乎已经告诉我们机械硬盘注定被时代 ...

  8. 分布式存储Ceph之PG状态详解

    https://www.jianshu.com/p/36c2d5682d87 1. PG介绍 继上次分享的<Ceph介绍及原理架构分享>,这次主要来分享Ceph中的PG各种状态详解,PG是 ...

  9. idea 配置idk

    [Toc] #一.idea配置全局jdk ##1.1 File-->Project Structure ##1.2 选择SDKs ##1.3 选择jdk路径即可,可以添加多个jdk #二.配置项 ...

  10. Kubernetes 技能图谱skill-map

    # Kubernetes 技能图谱 ## Container basics (容器技术基础)* Kernel* Cgroups* Userspace runtime* Image* Registry ...