Coin Slider
题目描述
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.
输入
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.
输出
样例输入
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的更多相关文章
- 19个非常有用的 jQuery 图片滑动插件和教程
jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入精美的效果.今天 ...
- 40款非常棒的 jQuery 插件和制作教程(系列一)
jQuery 在现在的 Web 开发项目中扮演着重要角色,jQuery 让网站有更好的可用性和用户体验,让访问者对网站留下非常好的印象.jQuery以其插件众多.独特.轻量以及支持大规模的网站开发闻名 ...
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- 跟着《beginning jquery》学写slider插件并借助自定义事件改进它
<beginning jquery>是一本很不错的学习jquery的书,作者的讲解深入浅出,很适合初学者,在最后一章里面,作者把前面所有的点结合起来完成了一个轮播图的jquery插件.实现 ...
- 推荐:图片轮播插件Nivo Slider
因为项目需要一款切换样式多一些的轮播插件,不经意找到了NivoSlider,非常好用,比bootstrap要好用,而且样式丰富.值得注意的是,这款插件是在MIT协议下免费的. ...
- 自制 移动端 纯原生 Slider滑动插件
在Google搜关键字“slider”或“swiper”能找到一大堆相关插件,自己造轮子是为了能更好的理解其中的原理. 给这个插件取名为“veSlider”是指“very easy slider”非常 ...
- 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing
[源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...
- 洛谷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 ...
- [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 ...
随机推荐
- Provider
import React from 'react';import PropTypes from 'prop-types'; class Provider extends React.Component ...
- Java多线程的理解和实例
编写具有多线程程序经常会用到的方法:run(), start(), wait(), notify(), notifyAll(), sleep(), yield(), join() 还有一个关键字:sy ...
- css3--css3模块
CSS3被拆分为"模块".旧规范已拆分成小块,还增加了新的. 一些最重要CSS3模块如下: 1.选择器(.基本选择器,层次选择器,伪类选择器,伪元素,属性选择器,通配符) 2.盒模 ...
- c++后台开发面试常见知识点总结(六)算法手写
链表倒转 leetcode-206 连续子数组最大和问题(和最大的连续子序列的和) leetcode-53 输出字符串中最长的回文子串长度? leetcode-5 一个字符串,求最长无重复子串 ...
- 【leetcode】1005. Maximize Sum Of Array After K Negations
题目如下: Given an array A of integers, we must modify the array in the following way: we choose an i an ...
- Security Spring 配置
<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://w ...
- c# 7.0新语法特性
public class NewAtturibute { public void TestFunc() { // 01 Out变量 不用初始化 "; if (int.TryParse(inp ...
- linux su su-的区别
su只是切换用户. su - 切换用户并切换shell环境. su another pwd后为/home/current su - another pwd后为/home/another
- redis-持久化、主从复制、集群
持久化 RDB.AOF(redis.conf) 主从复制 redis.conf 集群 redis-trib.rb.ruby相见如下链接http://www.cnblogs.com/wuxl360/p/ ...
- SCP-Py-001
项目编号:Py-001 项目等级:Euclid 特殊收容措施: Py-001必须被存储于基金会主站的网络硬盘中,并切断一切与互联网的连接. Py-001突破收容在网络上传播后,一旦在一台计算机上被下载 ...