Cycling Roads

几何

When Vova was in Shenzhen, he rented a bike and spent most of the time cycling around the city. Vova was approaching one of the city parks when he noticed the park plan hanging opposite the central entrance. The plan had several marble statues marked on it. One of such statues stood right there, by the park entrance. Vova wanted to ride in the park on the bike and take photos of all statues. The park territory has multiple bidirectional cycling roads. Each cycling road starts and ends at a marble statue and can be represented as a segment on the plane. If two cycling roads share a common point, then Vova can turn on this point from one road to the other. If the statue stands right on the road, it doesn’t interfere with the traffic in any way and can be photoed from the road.
Can Vova get to all statues in the park riding his bike along cycling roads only?
Input
The first line contains integers n and m that are the number of statues and cycling roads in the park (1 ≤ m < n ≤ 200) . Then n lines follow, each of them contains the coordinates of one statue on the park plan. The coordinates are integers, their absolute values don’t exceed 30 000. Any two statues have distinct coordinates. Each of the following m lines contains two distinct integers from 1 to n that are the numbers of the statues that have a cycling road between them.
Output
Print “YES” if Vova can get from the park entrance to all the park statues, moving along cycling roads only, and “NO” otherwise.
Example
input output

4 2
0 0
1 0
1 1
0 1
1 3
4 2



YES

4 3
0 0
1 0
1 1
0 1
1 2
2 1
3 4



NO

3 2
0 0
1 0
1 1
1 3
3 2

题目大意:给出n个点,m条线段,问所有的点是否可以相互到达。
给出的点有两个变量,x,y。给出的线段,有两个变量,每一条线段代表第一个点和第二个点之间有一条线段。

可以使用并查集+线段, 首先,给出线段之后,把在线段上的点都合并,然后遍历看看这条线段是否与其他线段相交,如果相交,则合并其他点。如果最后只有一个祖先,则是YES,否则,NO。

#include <bits/stdc++.h>
using namespace std;
int pre[322];
int ans;
const double pi = acos(-1.0);
const double eps = 1e-8;
int Find(int a)
{
    if(a!=pre[a])
        return pre[a] = Find(pre[a]);
    return a;
}
void Merge(int a, int b)
{
    int aa = Find(a);
    int bb = Find(b);
    if(aa!=bb)
    {
        pre[aa] = bb;
        ans--;
    }
}
int cmp(double x)
{
    if(fabs(x)<eps)
        return 0;
    if(x>0)
        return 1;
    return -1;
}
struct point
{
    double x, y;
    int id;
    point(){}
    point(double a, double b)
    {
        x = a;
        y = b;
    }
    friend point operator + (const point &a, const point &b)
    {
        return point (a.x + b.x, a.y + b.y);
    }
    friend point operator - (const point &a, const point &b)
    {
        return point (a.x - b.x, a.y - b.y);
    }
}Point[345];
double dot(const point &a, const point &b)//点积
{
    return a.x*b.x+a.y*b.y;
}
double det(const point &a, const point &b)//叉积
{
    return a.x*b.y - a.y*b.x;
}
struct line
{
    point a, b;
    line(){};
    line(point x, point y):a(x), b(y){}
}Line[322];
line point_make_line(const point a, const point b)
{
    return line(a, b);
}
//bool PointOnSegment (point p, point s, point t)
//{
//    return cmp(det(p-s, t-s))==0&&cmp(dot(p-s, p-t))<=0;
//}
bool PointOnSegment (point p, line A)
{
    return cmp(det(A.a - p, A.b-p))==0&&cmp(dot(A.a-p, A.b-p))<=0;
}
//bool parallel(line a, line b)
//{
//    return !cmp(det(a.a-a.b, b.a-b.b));
//}
//bool line_make_point(line a, line b)
//{
//    if(parallel(a, b))
//        return false;
//    return true;
//}
bool line_make_point(line l1, line l2)
{
    if (PointOnSegment(l1.a, l2) || PointOnSegment(l1.b, l2) || PointOnSegment(l2.a, l1) || PointOnSegment(l2.b, l1))
    {
        return true;
    }
    double c1 = det(l1.a - l2.a, l1.a - l1.b);
    double c2 = det(l1.a - l2.b, l1.a - l1.b);
    double c3 = det(l2.a - l1.a, l2.a - l2.b);
    double c4 = det(l2.a - l1.b, l2.a - l2.b);
    return cmp(c1) * cmp(c2) < 0 && cmp(c3) * cmp(c4) < 0;
}
int main()
{
    int n, m;
    cin>>n>>m;
    ans = n;
    for(int i=1;i<=n;i++)
    {
        cin>>Point[i].x>>Point[i].y;
        Point[i].id = i;
    }
    for(int i=1;i<=n;i++)
    {
        pre[i] = i;
    }
    for(int i=1;i<=m;i++)
    {
        int a, b;
        cin>>a>>b;
        Line[i] = point_make_line(Point[a], Point[b]);
        for(int j=1;j<=n;j++)
        {
//            if(PointOnSegment(Point[j], Point[a], Point[b]))
//                {
//                    Merge(Point[j].id, Point[a].id);
//                    Merge(Point[j].id, Point[b].id);
//                }
                if(PointOnSegment(Point[j], Line[i]))
                {
                    Merge(Point[j].id, Line[i].a.id);
                    Merge(Point[j].id, Line[i].b.id);
                }
        }
        for(int j=1;j<i;j++)
        {
            if(line_make_point(Line[i], Line[j]))
            {
                Merge(Line[i].a.id, Line[j].a.id);
                Merge(Line[i].a.id, Line[j].b.id);
                Merge(Line[i].b.id, Line[j].a.id);
                Merge(Line[i].b.id, Line[j].b.id);
            }
        }
    }
    if(ans==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}
代码转载自:https://pan.quark.cn/s/a4b39357ea24 本文重点阐述了利用 LabVIEW 软件构建的锁相放大器的设计方案及其具体实施流程,并探讨了该设备在声波相位差定位系统中的实际运用情况。 锁相放大器作为一项基础测量技术,其核心功能在于能够精确锁定微弱信号的频率参数并完成相关测量工作。 在采用 LabVIEW 软件开发的锁相放大器系统中,通过计算测量信号与两条参考信号之间的互相关函数,实现对微弱信号的频率锁定,同时输出被测信号的幅值信息。 虚拟仪器技术是一种基于计算机硬件平台的仪器系统,其显著特征在于用户可以根据实际需求自主设计仪器功能,配备虚拟化操作界面,并将测试功能完全由专用软件程序实现。 虚拟仪器系统的基本架构主要由计算机主机、专用软件程序以及硬件接口模块等核心部件构成。 虚拟仪器最突出的优势在于其功能完全取决于软件编程,用户可以根据具体应用场景灵活调整系统功能参数。 在基于 LabVIEW 软件开发的锁相放大器系统中,主要运用 LabVIEW 软件平台完成锁相放大器功能的整体设计。 LabVIEW 作为一个图形化编程环境,能够高效地完成虚拟仪器的开发工作。 借助 LabVIEW 软件,可以快速构建锁相放大器的用户操作界面,并且可以根据实际需求进行灵活调整和功能扩展。 锁相放大器系统的关键构成要素包括测量信号输入通道、参考信号输入通道、频率锁定处理单元以及信号幅值输出单元。 测量信号是系统需要检测的对象,参考信号则用于引导系统完成对测量信号的频率锁定。 频率锁定处理单元负责实现测量信号的锁定功能,信号幅值输出单元则负责输出被测信号的幅值大小。 在锁相放大器的实际实现过程中,系统采用了双路参考信号输入方案来锁定测量信号。 通过分析两路参考信号之间的相...
边缘计算环境中基于启发式算法的深度神经网络卸载策略(Matlab代码实现)内容概要:本文介绍了在边缘计算环境中,利用启发式算法实现深度神经网络任务卸载的策略,并提供了相应的Matlab代码实现。文章重点探讨了如何通过合理的任务划分与调度,将深度神经网络的计算任务高效地卸载到边缘服务器,从而降低终端设备的计算负担、减少延迟并提高整体系统效率。文中涵盖了问题建模、启发式算法设计(如贪心策略、遗传算法、粒子群优化等可能的候选方法)、性能评估指标(如能耗、延迟、资源利用率)以及仿真实验结果分析等内容,旨在为边缘智能计算中的模型推理优化提供可行的技术路径。; 适合人群:具备一定编程基础,熟悉Matlab工具,从事边缘计算、人工智能、物联网或智能系统优化方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究深度神经网络在资源受限设备上的部署与优化;②探索边缘计算环境下的任务卸载机制与算法设计;③通过Matlab仿真验证不同启发式算法在实际场景中的性能表现,优化系统延迟与能耗。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注算法实现细节与仿真参数设置,同时可尝试复现并对比不同启发式算法的效果,以深入理解边缘计算中DNN卸载的核心挑战与解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值