题目描述

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<=16)个圆的圆心坐标和半径,以及他们目的地的圆心坐标
问最多有多少个圆可以不和其他圆相交到达目的地
圆只能走直线且只能移动到目的地思路:
直接bfs,2^16的int记录当前局面,看哪个圆可以移动到目的地而不和其他圆相交就可以扩展到下一个状态
主要问题就是判断一个圆去目的地的路上会不会和其他圆相交
将其他圆的半径加上当前圆的半径,问题就转化成了求圆心线(线段)和其他圆会不会相交的问题
如果线段端点有一个在圆内则一定相交
如果圆心到线段所在直线的距离大于半径一定不相交
否则圆心到两端点的角度都为锐角,则一定相交(早知道就用double了,炸int调了我两晚上

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200;
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[1<<20];
ll dis(Point a,Point b)
{return (a-b)*(a-b);
}
bool Inter(int i,int j,int op)
{Point O;if (op==1) 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 0;ll a,b,c,dis1,dis2,ang1,ang2;if (O1.x==O2.x) a=1,b=0,c=-O1.x;else if (O1.y==O2.y) a=0,b=1,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 1;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>0 && ang2>0)return 0;return 1;
}
bool check(int x,int s)
{bool flag=1;for (int i=0;i<n;i++){if (i==x) continue;if  (s&(1<<i)) flag&=Inter(x,i,1);else flag&=Inter(x,i,2);if (!flag)  break;}return flag;
}
void bfs()
{ans=0;q.push({0,0});vis[0]=1;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=0;i<n;i++){if ((now.s&(1<<i))==0 && !vis[now.s|(1<<i)] && check(i,now.s) ){q.push({now.s|(1<<i),now.d+1});vis[now.s|(1<<i)]=1;}}}
}
int main()
{scanf("%d",&n);for (int i=0;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 0;
}

View Code

 

转载于:https://www.cnblogs.com/tetew/p/11391843.html

Coin Slider相关推荐

  1. 39个超实用jQuery实例应用特效

    2019独角兽企业重金招聘Python工程师标准>>> 1.Contextual Slideout:上下文滑动特效 2.Revealing Photo Slider:图片幻灯片特效 ...

  2. 33个优秀的 jQuery 图片展示插件分享

    您你可能还喜欢 60款很酷的 jQuery 幻灯片演示和下载 提升你网站水平的 jQuery 插件推荐 30个最佳 jQuery Lightbox 效果插件 Web开发者必备的20款超赞jQuery插 ...

  3. 设计师和开发人员更快完成工作需求的35个惊人的jquery插件教程(下)

    jQuery是一个快速,简洁的工具,它可以遍历HTML文档,处理事件,执行动画,并添加AJAX.jQuery赋予web开发更多的选择机会,使网站产生令人难以置信的元素效果不像之前需要写下几十行代码实现 ...

  4. 50个精心收集的惊人的jquery绚丽插件--功能全覆盖

    原文地址:http://www.cnblogs.com/58top/archive/2012/08/03/2622060.html TN3 Gallery – jQuery Slider and Im ...

  5. 30个很棒的jQuery幻灯片放映插件

    1. Awesome Diapo Slide Show with Jquery 查看详细 . 2. Full Screen Slide Show Plugin 查看详细 . 3. Crafty Sli ...

  6. wordpress滑动验证_WordPress图像滑块:滑动还是不滑动?

    wordpress滑动验证 Image sliders (also known as image carousels or slideshows) can be a convenient way to ...

  7. 第二百二十节,jQuery EasyUI,Slider(滑动条)组件

    jQuery EasyUI,Slider(滑动条)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Slider(滑动条)组件的使用方法,这个 ...

  8. slider(滑动条)控件模版,样式--用图片定义控件模版

    初接触wpf,想自己用图片做一个个性slider滑块控件,网上找了很久无果.后来一些机缘巧合看别人源码的时候找到了类似的,然后自己再查了一下msdn,大概弄懂了. 我们先来看看slider控件组成元素 ...

  9. iOS 自定义双向滑块Slider

    ZPSlider 一个双向滑块的Slider 前提 这个是在一次和朋友吃饭的时候,我们唠嗑的时候他说的一个需求.因为系统的Slider是只有一个滑块的,而且没有分段滑动的效果. 这不最近都在研究这么个 ...

最新文章

  1. RPM包安装LAMP及httpd虚拟机SSL实现
  2. 企业架构:现代数据架构的特征
  3. html怎么建边框,如何使用CSS创建多色边框?
  4. fanuc roboguide_ROBOGUIDE码垛简单工作站的创建
  5. CheckstyleException: cannot initialize module TreeWalker - TreeWalker is not allowed as a
  6. river歌曲表达的意思_华晨宇新歌《斗牛》究竟表达了什么?
  7. 1进程 ppid_Python每日3题什么是僵尸进程和孤儿进程?
  8. layui日期输入框
  9. vscode解决方案 关闭源代码管理
  10. 【笔记】运筹(中)——Rita_Aloha
  11. Little Gyro and Sort(第二届中国计量大学ACM程序设计竞赛个人赛)
  12. 外贸单证管理可高效简化外贸进出口制单流程
  13. [免费专栏] 车联网基础理论之车联网安全常见术语科普
  14. django 模型choice基本讲解
  15. js中yyyy-MM-dd格式的日期转换
  16. 踩坑三丰云、踩坑主机屋云服务
  17. Centos 安装FTP配置目录权限,iptables设置ftp服务
  18. 传统算法与神经网络算法,常见的神经网络算法有
  19. 瑞星杀毒软件的安装与设置
  20. Google Earth Engine(GEE)——利用Landsat 5 每一期影像制作动画时序并附带时间属性

热门文章

  1. NameNode中几个关键的数据结构
  2. 手机休眠监测wifi
  3. 12个球问题--微软面试题
  4. git pull问题“error: Your local changes to the following files would be overwritten by merge”解决方案
  5. Golang 数组传参
  6. OVS DPDK vs OVS Deep Dive(十六)
  7. javascript写坦克大战
  8. python模块手册_python模块说明
  9. mysql 启动参数_MySQL启动相关参数 MySQL DBA学习
  10. log4cxx体系结构