题解:AT_arc173_b [ARC173B] Make Many Triangles
背景
前几天打了比赛,崩麻了,所以来水一篇题解。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的更多相关文章
- 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 ...
- [USACO20FEB]Equilateral Triangles P 题解
优雅的暴力. 设三个点为 \((i,j,k)\),则有 \(6\) 个未知数即 \(x_i,x_j,x_k,y_i,y_j,y_k\).又因为有 \(2\) 条关于这 \(6\) 个未知数的方程 \( ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
- 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 ...
- 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 ...
- 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 ...
- CodeForces 682E Alyona and Triangles (计算几何)
Alyona and Triangles 题目连接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/J Description You ar ...
- Little Zu Chongzhi's Triangles
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- POJ1569 Myacm Triangles
Description There has been considerable archeological work on the ancient Myacm culture. Many artifa ...
- hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...
随机推荐
- 开源项目分享:ChatGPT 控制台聊天应用
开源项目分享:ChatGPT 控制台聊天应用 分享一个我最近完成的一个小应用,一个ChatGPT 的控制台聊天应用,大家都在搞AI,我也来玩一玩,顺便分享到社区,有兴趣的小伙伴可以去我的github主 ...
- GIT文件上传演示
Be Written By Handat.憨大头 注:以下内容默认你已经做好了git工具的用户账户配置. (1)创建Gitee线上代码仓库,HTTPS协议地址就是仓库地址,如例https://gite ...
- 安装vmware17和下载红帽镜像
安装vmware17 一.下载 1.访问vmware官网 (也可以使用这个链接https://www.vmware.com/products/workstation-pro/workstation-p ...
- C语言常用数学函数
目录 C语言常用数学函数(头文件#include "math.h") abs()函数 labs()函数 fabs()函数 floor()函数 floorf() floorl() c ...
- java中实现创建目录、创建文件的操作
一.创建目录 mkdir()--仅创建一层目录,返回true或false. mkdirs()--创建一层或多层目录,返回true或false. 也就是,在通常情况下,使用mkdirs()即可满足创 ...
- LeetCode 207. Course Schedule 课程表 (C++/Java)
题目: There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have pr ...
- 利用夜莺开源版对H3C无线设备监控
编者荐语:真正搞监控的人肯定知道 SNMP 水有多深,有时我甚至腹黑猜测,这些厂商是故意的吧,,,指标不标准,格式各异,只能靠一款灵活的采集器了,本文是夜莺社区用户写的文章,转给大家参考. autho ...
- Wireshark基础教程
Wireshark是非常流行的网络封包分析软件,可以截取各种网络数据包,并显示数据包详细信息.常用于开发测试过程各种问题定位.本文主要内容包括: 1.Wireshark软件下载和安装以及Wiresha ...
- Vue3:项目创建
Vue 3 相对于 Vue 2 带来了许多改进和优点,这些改进主要是为了提高性能.开发体验和可维护性.但是对于创建项目,Vue3也可以采用跟Vue2相同的方式. 使用CLI创建 1. 安装Vue CL ...
- Vue学习:8.v标签综合-强化版
通过前几节的认识和学习,我们掌握了常用v标签的用法,这一节再来巩固提高一下吧. 实例:成绩面板 实现功能: 主体由两大部分组成:表格+表单.这个表格可以显示多科成绩,并具有表头.删除以及底部统计功能. ...