首页 > 其他分享 >2022CCPC Weihai Site C. Grass

2022CCPC Weihai Site C. Grass

时间:2023-05-03 16:45:24浏览次数:48  
标签:return 个点 Point int Weihai Site 共线 Grass define

C. Grass

题意:

选出5个点,并以A点为中心不存在与其他4个点的向量同向且共线

分析:

预选出4个点,枚举第5个点

  • 如果遍历一遍后没有找到能与选定的4个点不都同向共线,此时一定满足所有的点都共线(所有点都不满足)

当选出满足条件的点后再去判断以那个点为中心去连接其他点不会有共线的情况:

  • 这里判断共线使用叉积 \(\frac{x_1}{y_1} = \frac{x_2}{y_2}\) 判断是否共线,
  • 判断是否同向用叉乘,不同向则叉乘为负

实现:

#include <bits/stdc++.h>
using namespace std;
#define mst(x, y) memset(x, y, sizeof x)
#define endl '\n'
#define INF LONG_LONG_MAX
#define int long long
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 2000010, MOD = 1e9 + 7;
const double EPS = 1e-6;
typedef pair<int, int> PII;
int T;
int n;
struct Point
{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y){};
} p[N], res[6], tmp[6];
Point operator-(Point A, Point B)
{
    return {A.x - B.x, A.y - B.y};
}
bool operator*(Point A, Point B)
{
    if (B.x * A.y != B.y * A.x)
        return 0;
    if (B.x * A.x < 0 || B.y * A.y < 0)
        return 0;
    return 1; // 两向量同向且共线
}
bool check()
{
    for (int i = 1; i <= 5; i++)
    {
        int idx = 0;
        for (int j = 1; j <= 5; j++)
        {
            if (i != j)
                tmp[++idx] = res[i] - res[j];
        }

        bool f = true;
        for (int j = 1; j <= 4 && f; j++)
        {
            for (int k = 1; k <= 4 && f; k++)
            {
                if (j != k && (tmp[j] * tmp[k]))
                    f = false;
            }
        }
        if (!f)
            continue;

        cout << "YES" << endl;
        cout << res[i].x << " " << res[i].y << endl;
        for (int j = 1; j <= 5; j++)
        {
            if (i != j)
                cout << res[j].x << " " << res[j].y << endl;
        }
        return 1;
    }
    return 0;
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i].x >> p[i].y;

    if (n < 5)
    {
        cout << "NO" << endl;
        return;
    }
    else
    {
        for (int i = 1; i <= 4; i++)
            res[i] = p[i];

        for (int i = 5; i <= n; i++)
        {
            res[5] = p[i];
            if (check())
                return;
        }
        cout << "NO" << endl;
    }
}
signed main()
{
    FAST;
    T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

标签:return,个点,Point,int,Weihai,Site,共线,Grass,define
From: https://www.cnblogs.com/Aidan347/p/17369251.html

相关文章

  • Sololearn website big changes All In One
    SololearnwebsitebigchangesAllInOneLearnPythonoldversionJumptoourbestPythoncourse!Thisoldversionisabouttogoonpermanentvacation.这个旧版本即将永久休假https://www.sololearn.com/learning/1158newversionhttps://www.sololearn.com/l......
  • 【ABAQUS&Composite】composite layerup Manager从txt导入铺层信息
    ABAQUS在复合材料建模方面自由度是比较高的。官方提供了两个工具:ABAQUS/CAE中的CompositeLayupManagerABAQUS/CAE的plugin:CompositesModeler(需要ABAQUS2019以上)abaqus的compositelayupmanager做单个铺层方案的时候很方便。但是如果做多个铺层方案,就比较麻烦。比如我......
  • Sitecore XP 10.3(latest) Docker一键部署
    本文演示通过PowerShell+DockerDesktopforWindows一键部署Sitecore10.3(即Sitecore最新版)Docker开发/测试/演示环境。官方参考 SitecoreXP10.3.0DeveloperWorkstationDeploymentWithDocker演示配置为XPSingle(XP0) 环境准备1,windows10+/WindowsServer2019(Windows......
  • 本地图文直接复制到SiteFactory编辑器中
    ​ 百度ueditor新增的将word内容导入到富文本编辑框的功能怎么没有啊,...ueditor实现word文档的导入和下载功能的方法:1、UEditor没有提供word的导入功能,只能说是粘贴复制。2、方案:用poi来提供word导入,思路是将word转换为html输出,再用UEditor提供的setContent()方法将html的内容......
  • Sitecore10 Demo演示环境Azure一键部署(Step By Step Guide to installing Sitecore10
    本文演示SitecoreXPSingle(XP0)在Azure上的一键部署,即“30分钟生成Sitecore演示环境”的一环。关于XP(即SitecoreExperiencePlatform)roles的相关介绍移步XPSingle配置主要用来开发和测试:FourSitecoreroles:ContentDelivery,ContentManagement,Processing,andRepo......
  • GrassRouter多链路聚合通信系统保障公路网络稳定全面覆盖解决方案
    近年来国内经济不断发展,城市道路交通能力迅速提高,各省市道路交通体系不断完善,促使高速公路运能得到极大提高,公路运输的通达性、舒适性得到明显提高。随着现代化高速公路的建设,新一代无线网络监控系统,已日益成为高速公路监控管理的主要手段。目前高速公路普遍存在各路段监控“信息孤......
  • SiteFactory 实现ctrl+v粘贴图片并上传、word粘贴带图片
    ​ 自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了。一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器)中时,编辑器都无法自动上传图片。需要用户手动一张张上传Word图片。如果只有一张图片还能够接......
  • VMware Site Recovery Manager 8.7 (for vSphere 8 U1) - 数据中心灾难恢复 (DR)
    请访问原文链接:https://sysin.org/blog/vmware-srm-8/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgSiteRecoveryManager8.7|18APR2023|Build21590800什么是SiteRecoveryManager(SRM)?SiteRecoveryManager是业界领先的灾难恢复(DR)软件,可自动编......
  • Minimum Number of Visited Cells in a Grid
    MinimumNumberofVisitedCellsinaGridYouaregivena0-indexed mxn integermatrix grid .Yourinitialpositionisatthetop-left cell (0,0).Startingfromthecell (i,j),youcanmovetooneofthefollowingcells:Cells (i,k) with j<k......
  • Disqus Site Reactions All In One
    DisqusSiteReactionsAllInOneemoji......