枚举法:

枚举法是利用计算机速度快, 精度高的特点, 对要解决的问题所有可能情况进行霸道的, 一个不漏检验, 从中找出符合要求的答案。

特点:

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;
}

  

  

 

Vanya and Triangles 暴力枚举的更多相关文章

  1. 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 ...

  2. Codeforces 552E Vanya and Brackets(枚举 + 表达式计算)

    题目链接 Vanya and Brackets 题目大意是给出一个只由1-9的数.乘号和加号组成的表达式,若要在这个表达式中加上一对括号,求加上括号的表达式的最大值. 我们发现,左括号的位置肯定是最左 ...

  3. hdu 4082 Hou Yi's secret(暴力枚举)

    Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  5. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  6. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  7. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  8. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  9. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

随机推荐

  1. adb 获取手机值

     获取手机RAM值    adb shell cat /proc/meminfo   获取手机内存值     adb shell df /data

  2. [Javascript] Advanced Reduce: Additional Reducer Arguments

    Sometimes we need to turn arrays into new values in ways that can't be done purely by passing an acc ...

  3. JavaScript高级编程II

         原文地址: http://www.onlamp.com/pub/a/onlamp/2007/08/23/advanced-javascript-ii.html?page=1 在前面的文章中, ...

  4. 关于DOS下启动MySQL时提示服务名无效

    主要原因:启动时:net start mysql 而打开服务后发现,本地服务中mysql这个服务实际名字为mysql55,故启动语句应为:net  start mysql55: 以下摘自课程提问: 你 ...

  5. Android UI WebView的使用:

    Android UI WebView的使用: /** * @author smiling * @date 2016/10 */ 布局: <?xml version="1.0" ...

  6. yii criteria select column as 与 时间段查询

    需要查询某时间段的记录,但是数据库里只有一个时间记录,如果写sql的话,很快的,放到yii里一时竟然没办法... 不过,最后还是解决了,使用了一个第三方的插件 参考http://www.yiifram ...

  7. linux定时任务2-at命令

    定时执行命令: [root@rheltest1 ~]# at now + 1 minute //一分钟后执行下面的任务 at> date >> /tmp/test_date.log ...

  8. spring03autowire属性

    1.创建需要的实体类 public class Student { //学生实体类 private String name; //姓名 private Integer age; //年龄 privat ...

  9. codevs 2995 楼房

    /*暴力30分*/ #include<iostream> #include<cstring> #include<cstdio> #include<map> ...

  10. ASP.NET-FineUI开发实践-9(四)

    现在是这么个问题,在开发中表格是动态出来的,就是标准板是全部字段列出,客户要根据情况列出自己想要的,在增加操作页面的同时要是能用前台自带的功能直接保存到后台就好了,现在的列显示和隐藏是不回发的. 1. ...