Vanya and Triangles 暴力枚举
枚举法:
枚举法是利用计算机速度快, 精度高的特点, 对要解决的问题所有可能情况进行霸道的, 一个不漏检验, 从中找出符合要求的答案。
特点:
1. 得到的结果一定正确。
2. 可能做了很多无用功,效率低下。
3. 一般会涉及到极值。
4. 数据量大的话可能造成时间崩溃。
结构:
循环结构。
基本思路:
1. 确定枚举对象, 枚举范围, 判定条件。
2. 枚举可能的解, 验证是否是问题的解。
Vanya and Triangles :
M - Vanya and Triangles
Crawling in process... Crawling failed Time Limit:4000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Sample Input
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
#include<stdio.h>struct point{int x, y;
}p[3100];int main()
{int n, ans = 0;scanf("%d", &n);for(int i = 1; i <= n; i++)scanf("%d%d", &p[i].x, &p[i].y);for(int i = 1; i < n - 1; i++)for(int j = i + 1; j < n; j++)for(int k = j + 1; k <=n; k++)if((p[i].y - p[j].y)*(p[k].x - p[i].x) != (p[k].y - p[i].y)*(p[i].x - p[j].x))ans++;printf("%d\n", ans);return 0;
}
转载于:https://www.cnblogs.com/xzrmdx/p/4954180.html
Vanya and Triangles 暴力枚举相关推荐
- POJ 3174 暴力枚举
思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...
- codeforces数学1600day6[CodeForces - 1029C多区间交+枚举,CodeForces 992C[数学公式推导],CodeForces 992B[质因数分解+暴力枚举]]
A - Maximal Intersection CodeForces - 1029C 题目大意:就是给你n个区间,这n个区间有公共的区间长度为x,现在叫你从这n个区间中删掉一个使得x最大化. 解题思 ...
- 最大字段和 冲出暴力枚举
这篇解题报告是对我最近一些题的总结,里面的代码都是我解题,优化,再优化的过程的记录,记录了自己对算法的完善与优化思路,还有对编程哲学的理解:do it,do it well. 很感谢孙老师您,让自己可 ...
- hdu 4587 TWO NODES 暴力枚举+tarjan
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意是拿掉两个点 求最多可以把整个图分成几个联通块 注意到有一个模板是可以通过找割点来快速求出 ...
- 一道暴力枚举题Win32版本示例
来看一个问题:该问题的解法是 暴力枚举:这大概是ACM方面的:名称叫火柴棒等式: 给你n根火柴棍,你可以拼出多少个形如"A+B=C"的等式?等式中的A.B.C是用火柴棍拼出的整数( ...
- C. Divisibility by Eight【暴力枚举】
暴力枚举即可.枚举1位这种情况,枚举2位这种情况,枚举3位这种情况. 3位满足足以,其他的4位,5位...都包含1000必定满足. #include<bits/stdc++.h> usin ...
- YBTOJ:灯光控制(贪心)(公倍数)(暴力枚举)
文章目录 题目描述 解析 代码 题目描述 解析 没有想出来 首先可以确定开关要么开一次,要么不动,其他都和这俩是等价的 一开始最先想到的就是贪心的方法,每个开关遍历,如果按下会使答案变好就按下. 但是 ...
- array专题2---理解暴力枚举与动态规划
746 Min Cost Climbing Stairs 一直以后对暴力枚举(又称:深度优先搜索)和动态规划不太理解,不能明白个中区别,更别说贪心.今天做这道题目的时候有点心得. 思路一:看到题目,直 ...
- 【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)
题干: The game "The Pilots Brothers: following the stripy elephant" has a quest where a play ...
- Uva 201 Squares (暴力 + 枚举)
[题意] 给出 n*n 的 点 H 横向 V 纵向 (注意) V 想 I,j 相反 问 边 为1 ,2 , 3 .... n 的 正方向有几个 [思路] n 很小 直接暴力 枚举 枚举 ...
最新文章
- rtcp 实时传输控制协议 简介
- mxnet cannot import name 'nd'
- 比赛的一道题:SCSHOP1.5代码审计
- 推荐算法工程师成长2:排序模块
- spdk/dpdk 编译相关问题汇总
- linux es数据库 head,elasticsearch安装es-sql插件
- reboot mysql fail_mysql 5.7.18,在系统重启后,为什么无法启动?
- 初学者学习C++的50条忠告
- 再谈js对象数据结构底层实现原理-object array map set
- Windows下Node.js安装Canvas插件
- Maven图文闪电入门
- Latex初学入门记载
- 无人机航拍全景图这些事情一定要知道
- 2023-2028年中国压铸机行业发展前景与投资趋势分析报告
- vue实现店铺装修h5用户端实现
- 程序员不得不知道的英语词汇
- 十进制如何转化为二进制和六进制
- Word2019修改背景色失效的解决方法
- kafka topic消息分配partition规则
- 软件测试 查看网页打开时间,网页响应时间101(三)