#308 (div.2) D. Vanya and Triangles
来源:互联网 发布:电子显示屏软件下载 编辑:程序博客网 时间:2024/05/16 17:00
1.题目描述:点击打开链接
2.解题思路:本题是一道简单的计算几何题,统计一个图中有多少个三角形,由于给的时间很宽,完全可以用O(N^3)的算法来解决,判断是否构成三角形只需要用向量来判断三点是否共线即可。
3.代码:
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<algorithm>#include<string>#include<sstream>#include<set>#include<vector>#include<stack>#include<map>#include<queue>#include<deque>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<functional>using namespace std;typedef long long ll;typedef unsigned long long ull;#define me(s) memset(s,0,sizeof(s))#define For(i,n) for(int i=0;i<(n);i++)#define pb push_back#define sz size#define clr clear#define F(a,b) for(int i=a;b;i++)struct Point{ int x,y; Point(int x=0,int y=0):x(x),y(y){} Point operator +(const Point&p)const { return Point(x+p.x,y+p.y); } Point operator -(const Point&p)const { return Point(x-p.x,y-p.y); } void read() { scanf("%d%d",&x,&y); }}a[2005];bool ok(int i,int j,int k){ Point e1=a[i]-a[j]; Point e2=a[i]-a[k]; if(e1.x*e2.y-e1.y*e2.x==0)return false; return true;}int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) a[i].read(); ll cnt=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) for(int k=j+1;k<n;k++) if(ok(i,j,k)) cnt++; printf("%I64d\n",cnt); } return 0;}
0 0
- #308 (div.2) D. Vanya and Triangles
- D. Vanya and Triangles(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles
- Codeforces Round #308 (Div. 2) D Vanya and Triangles
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles (判断三角形数量)
- cf #308 D. Vanya and Triangles (几何)
- codeforces #308 D.Vanya and Triangles(枚举+斜率分块)
- cf#308-D - Vanya and Triangles-求平面点集中三角形个数-枚举-n^2logn
- Codeforces 552D Vanya and Triangles
- CodeForces 552D Vanya and Triangles
- 【25.33%】【codeforces 552D】Vanya and Triangles
- CodeForces 552D — Vanya and Triangles 暴力枚举
- Codeforce 552D Vanya and Triangles(暴力枚举)
- Codeforces 552D. Vanya and Triangles【向量判三点共线】
- Codeforces 552D Vanya and Triangles【暴力枚举+思维】
- Codeforces #280 (Div. 2)D Vanya and Computer Game
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure
- webx--借用petstore快速入门
- JavaScript权威指南_113_第15章_脚本化文档_15.2-选取文档元素-通过ID选取元素
- Android开发中解决动画只执行一次的方法
- 自定义cell适配-返回的cell高度
- 设计模式--浅谈策略模式
- #308 (div.2) D. Vanya and Triangles
- Newtonsoft.Json高级用法
- lib库
- 设计模式--浅谈桥接模式
- ios中webview的高级用法(二)
- 刷新和加载
- phpcms v9 模板标签技巧,标签调用方法大全
- 华为java机试题整理(二)
- Mysql表操作