题解: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 ...
随机推荐
- Django----模型----数据库的基本操作
1.添加记录 方式一:save() 方式二(推荐):create() 2.查询记录 (1)all() 查询所有记录,返回queryset对象. stu_list = Student.objects.a ...
- tkinter的Text组件设置禁止编辑
完整代码: from tkinter import * import requests window = Tk() window.geometry('1000x500+300+100') window ...
- 【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
在使用App Service服务部署业务应用,因为有些第三方的接口需要调用者携带TLS/SSL证书(X509 Certificate),在官方文档中介绍了两种方式在代码中使用证书: 1) 直接使用证书 ...
- linux扩展分区
linux扩展分区 1.准备工作 系统版本:ubuntu20.04 工具:一个安装了ubuntu系统的系统U盘或者ubuntu系统制作的启动盘 2.缩小分区 要扩展某一个分区,再没有空闲空间时需要从其 ...
- uniapp 拨打电话功能
phoneNumber进行动态调用时候一定要添加引号,否则会报错 1 call() { 2 uni.makePhoneCall({ 3 phoneNumber: 'this.leads.tel' // ...
- SQL练习之打卡记录数据统计类问题
最近老婆的公司,关闭了OA系统中,各类打卡时间数据统计的功能,为了不麻烦老婆手算,就做了一个简单的打卡系统,方便自动统计老婆想要知道的各类数据. 做的过程中就遇到了几个还挺有意思的SQL,这里写成一篇 ...
- #define 用法解法
宏的优点是能整理代码 缺点是宏替换来的代码需要人工解除宏后才能暴漏源代码 改底层时候是需要解一解的 它可以做到main函数中只有一个宏字母 这个宏定义时候,定义成了几个函数的源代码 所以main里面就 ...
- 编程语言界的丐帮 C#.NET 国密数字信封 民生银行
民生银行的库DLL只有C版本和JAVA版本.按着JAVA版本做的C# 实现. 重点内容. 1.数字信封就是 CmsEnvelopedData Der编码后转BASE64 2.重点类:ContentIn ...
- element el-input 去掉边框
element样式还是蛮好的,只是有时候我们需要做一些调整,比如,el-input 的边框,官网是这样子的 我们需要去掉这个边框 试了常用的:border: none: 以及:outline:non ...
- Maven配置阿里云镜像和本地仓库路径
配置阿里云镜像仓库 在settings > mirrors标签下添加以下内容 <!-- Aliyun Mirror --> <mirror> <id>alim ...