背景

前几天打了比赛,崩麻了,所以来水一篇题解。LC真睿智

题意

给你 \(n\) 个点,问最多能组成几个三角形。

分析

听说可以随机化。这道题就是一个简单贪心。

我们考虑,如果没有共线的点,那么答案显然就是 \(\frac{n}{3}\) 了。

如果有共线,我们容易想到一个贪心思路:既然同一直线上的点不能组成三角形,那么应该尽可能让多的不在这条直线上的点消耗这条直线上的点,即设直线上点的集合为 \(C\),那么对于任意 \(\{x,y\}\notin C\),让它和 \(C\) 中的两个元素组成三角形即可。这种情况下答案显然是 \(n-card(C)\),限制条件是直线上的点能够消耗完其余点,即 $\frac{card(C)}{2}> n-card(C) $。

由于 $1\leq n \leq 300 $ 的奇妙范围,直线的寻找可以直接暴力三重循环。对于是否共线的判断,可以用相似来证,具体在代码里面。

然后就可以上代码了。

Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int w=1,s=0;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch)){s=s*10+(ch-'0');ch=getchar();}
return w*s;
}
const int maxn=1e6+10;
int n;
struct no
{
int x,y;
}a[500];
int ans=-maxn;//记录最长直线
bool ch(no x,no y)//判断是否共线
{
return x.x*y.y==x.y*y.x;
}
no operator -(no x,no y)
{
return (no){x.x-y.x,x.y-y.y};
}
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int x=read(),y=read();
a[i]={x,y};
}
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
int sum=2;
for(int k=1;k<=n;k++)
{
if(k==i||k==j)continue;
if(ch(a[k]-a[i],a[k]-a[j]))sum++;
}
ans=max(ans,sum);//更新最大值
}
}
if(ans/2>n-ans)cout<<n-ans;//直线可以消耗所有点
else cout<<n/3;//不能
return 0;
}

题解:AT_arc173_b [ARC173B] Make Many Triangles的更多相关文章

  1. codechef Chef and The Right Triangles 题解

    Chef and The Right Triangles The Chef is given a list of N triangles. Each triangle is identfied by ...

  2. [USACO20FEB]Equilateral Triangles P 题解

    优雅的暴力. 设三个点为 \((i,j,k)\),则有 \(6\) 个未知数即 \(x_i,x_j,x_k,y_i,y_j,y_k\).又因为有 \(2\) 条关于这 \(6\) 个未知数的方程 \( ...

  3. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  4. Codeforces Round #309 (Div. 1) C. Love Triangles dfs

    C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...

  5. Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题

    D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  6. Project Euler 91:Right triangles with integer coordinates 格点直角三角形

    Right triangles with integer coordinates The points P (x1, y1) and Q (x2, y2) are plotted at integer ...

  7. CodeForces 682E Alyona and Triangles (计算几何)

    Alyona and Triangles 题目连接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/J Description You ar ...

  8. Little Zu Chongzhi's Triangles

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  9. POJ1569 Myacm Triangles

    Description There has been considerable archeological work on the ancient Myacm culture. Many artifa ...

  10. hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形

    How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...

随机推荐

  1. 记一次DRF问题排障

    1 最近在搞django,在写一个接口的时候用到了APIview,之后再调用接口的时候一直显示405,不允许使用post方法 视图

  2. C# winfrom 局域网版多人成语接龙(二)

    功能基本上是完成了,要两个人完才好玩,目前 倒计时,每组游戏玩家数量这些控制变量,都是写死再代码里的,等以后想改的时候再改,这个项目核心的功能算是实现了,但还可以扩展,比如记录一下用户的游戏数据,答对 ...

  3. FFmpeg下载编译、代码结构以及编译系统

    从这里开始,就要踏上学习FFmpeg的旅程了,使用的FFmpeg版本5.0.1 1.ubuntu下,如何下载并编译FFmpeg源码 打开FFmpeg官网 Download FFmpeg,我们可以通过g ...

  4. WPF 不透明蒙板概述

    本文内容 先决条件 使用不透明蒙板创建视觉效果 创建不透明蒙板 将渐变用作不透明蒙板 显示另外 4 个 不透明蒙板能够使部分元素或视觉对象透明或部分透明. 要创建不透明蒙版,请将 Brush 应用于元 ...

  5. Linux下docker安装部署

    Linux下docker安装部署 环境说明 该文档安装环境为CentOS Linux release 7.9.2009,内核版本为3.10.0-1160.81.1.el7.x86_64 安装说明 安装 ...

  6. 春松客服入驻Rainbond开源应用商店

    "做好开源客服系统" 春松客服是拥有坐席管理.渠道管理.机器人客服.数据分析.CRM 等功能于一身的新一代客服系统.将智能机器人与人工客服完美融合,同时整合了多种渠道,结合 CRM ...

  7. containerd 源码分析:创建 container(一)

    0. 前言 Kubernetes:kubelet 源码分析之 pod 创建流程 介绍了 kubelet 创建 pod 的流程,containerd 源码分析:kubelet 和 containerd ...

  8. 第一个java的应用程序

    编写java第一个程序 class HelloWorld { public static void main(String[] args){ System.out.print("Hello ...

  9. REACT列表过度

    <TransitionGroup> <CSSTransition> <li>aaaa</li> </CSSTransition> </ ...

  10. CF1815

    CF1815 Div. 1 确实难,Virtual Contest 上只完成了两道题,想出来了三道题. A. Ian and Array Sorting 秒切题--考虑将前 \(n - 1\) 个数变 ...