题目描述

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. Goldengate 部署oracle10g在 rac asm环境,完整教程

    前言 Goldengate再rac 环境部署,和单机部署区别还是有点大,主要存在环境上. 环境 oracle10g ,sid=rac 准备工作 1.在rac节点,配置监听动态注册,确保goldenga ...

  2. 59th python下graphviz安装 砖

    原文 摘录  感谢分享:   https://www.cnblogs.com/liusx0303/p/9155305.html 参考链接:https://blog.csdn.net/u01325041 ...

  3. oracle exp不生成dumpfile,预估出实际导出文件的大小。

    目的:在不创建dumpfile前预估出需要的导出文件大小.  适用于export     实验步骤如下:OS:  Linux test20 2.6.18-238.el5 #1 SMP Sun Dec ...

  4. pc上用C语言模拟51多任务的案例程序

    #include <stdio.h> #include <stdlib.h> //任务槽个数.在本例中并未考虑任务换入换出,所以实际运行的任务有多少个, //就定义多少个任务槽 ...

  5. InnoDB的LRU淘汰策略

    Reference: https://time.geekbang.org/column/article/121710 InnoDB存储引擎是基于集合索引实现的数据存储,也就是除了索引列以及主键是存储在 ...

  6. Anaconda 安装 pytorch报错解决方法

    一.安装Pytorch: # -c 指定用pytorch镜像源下载软件conda install pytorch torchvision cpuonly -c pytorch 报错: 二.配置: ch ...

  7. linux编译php

    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/loc ...

  8. UVa 699 The Falling Leaves (树水题)

    Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...

  9. paper 143:人脸验证

    持续更新ing,敬请期待! 参考:http://blog.csdn.net/stdcoutzyx/article/details/42091205  1. DeepID人脸识别算法 香港中文大学的团队 ...

  10. 处理post上传的文件;并返回路径

    /** * 处理post上传的文件:并返回路径 * @param string $path 字符串 保存文件路径示例: /Upload/image/ * @param string $format 文 ...