Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题
2015-06-19 11:22
501 查看
D. Vanya and Triangles
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/552/problem/DDescription
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.[b]Input[/b]
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.
[b]Output[/b]
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
[b]Sample Input[/b]
4
0 0
1 1
2 0
2 2
[b]Sample Output[/b]
3
HINT
[b]题意[/b]平面上给你n个点,然后问你能构成多少个三角形
[b]题解:[/b]
n^3暴力跑一法就过了……
是数据太水,还是我太屌?
[b]代码:[/b]
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 2000001 #define mod 10007 #define eps 1e-5 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** #include<cstdio> #include<cmath> using namespace std; struct point { int x,y; friend int operator *(point A,point B){return A.x*B.y-A.y*B.x;} friend point operator -(point A,point B){point C;C.x=A.x-B.x;C.y=A.y-B.y;return C;} }p[3100]; int ans,n; int main() { 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-2;i++) for(int j=i+1;j<n;j++) for(int k=j+1;k<=n;k++) if((p[i]-p[j])*(p[j]-p[k]))ans++; printf("%d",ans); return 0; }
相关文章推荐
- eclipse 操作笔记
- SAFe 从概念到实践 开发人员的“敏捷”之我见
- 解决编译Gh0st时error C2065: 'IDC_HAND' : undeclared identifier
- 算法导论--贪心算法与动态规划(活动选择问题)
- 第三阶段绩效考核
- SVN 目录结构
- java知识点二-TCP和UDP的联系和用途
- linux 配置放火墙端口
- 剖析开源监控Nagios故障
- ssh框架分工与职责
- String format specifier
- leetcode: basic caculator
- 恢复oracle中误删除drop掉的表
- Android--Volley(四)--源码解析
- 超时重发
- MongoDB 常用命令
- Gstreamer/tools: gst-launch gst-inspect 用法示例
- Count Primes
- windows7剪切文件夹到另一个文件夹出现未响应怎么办?
- android app notification的用法