博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
7_9_2013 A: Triangles
阅读量:7038 次
发布时间:2019-06-28

本文共 2187 字,大约阅读时间需要 7 分钟。

hot3.png

Problem A: Triangles

Time Limit: 2 Sec  
Memory Limit: 128 MB
Submit: 20  
Solved: 9
[ ][ ][ ]

Description

You are given a figure consisting of points in a 2D-plane and m segments connecting some of them. We guarantee that any two segments don’t share points except their ends and there’s no more than one segment between the same pair of points. Please count the total number of triangles in the given figure. 

Input

There’re multiple test cases. In each case:

The first line contains two positive integers and m. (≤ 200, ≤ 20000)

Each of the following lines contains two real numbers xand yindicating the coordinates of the i-th point. (100000 < xi, y100000)

Each of the following m lines contains four real numbers xiyixjy. It means (xi,yi) and (xj,yj) are connected by a segment. We guarantee that these points are part of the given points. 

Output

For each test case, print a single line contains the total number of triangles in the given figure. 

Sample Input

4 5 0 0 1 1 2 0 1 0 0 0 1 1 1 1 2 0 2 0 1 0 1 0 0 0 1 1 1 0

Sample Output

3

這個題目一開始看沒有看懂題目,不明白爲什麽說明了點還要說明邊,就沒有去寫對我來說第二個難點就是不知道如何去實現邊關係的存儲,雖然以前寫過用二維數組實現邊關係的存儲,而這題有一點不同,在usc_w隊長的指導下,明白了要用map實現哈希對應如此來就是一道簡單的搜索題目了

#include 
#include
#include
#include
#include
using namespace std;int n, m, sum;int edge[210][210];struct p{ double x, y;}point[210];map
number;bool if_line(int i, int j, int k){ return fabs((point[j].x-point[i].x)*(point[k].y-point[j].y)- (point[k].x-point[j].x)*(point[j].y-point[i].y))<1e-8 ? true: false;}/*bool if_line(int i, int j, int k){ double xx1=point[j].x-point[i].x; double yy1=point[j].y-point[i].y; double xx2=point[k].x-point[j].x; double yy2=point[k].y-point[j].y; if(fabs(xx1*yy2-xx2*yy1)<1e-8) return true; return false;}*/voidslove(){ for(int i=0; i
>n>>m){ sum=0; number.clear(); memset(edge, 0, sizeof(edge)); for(int i=0; i
>point[i].x>>point[i].y; number[point[i].x*200000+point[i].y]=i; } for(int i=0; i
>x1>>y1>>x2>>y2; int u=number[x1*200000+y1]; int v=number[x2*200000+y2]; edge[u][v]=edge[v][u]=1; } slove(); cout<
<

转载于:https://my.oschina.net/dianpaopao/blog/143991

你可能感兴趣的文章
Oracle死锁处理实例
查看>>
[转]Android Studio创建Xposed模块项目时BridgeApi的正确添加方式
查看>>
【hive】——Hive sql语法详解
查看>>
python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)...
查看>>
一篇网络流的好blog
查看>>
Python基础之继承与派生
查看>>
filter、map、every函数的使用
查看>>
黑马程序员——iOS学习——UITableView表视图单元样式
查看>>
Bash基础——减号-
查看>>
Android适配文件dimen自动生成代码
查看>>
走马观花--快餐学python笔记
查看>>
jquery轻量级富文本编辑器Trumbowyg
查看>>
(二十八)static关键字
查看>>
vue条件渲染
查看>>
转 MySQL数据库基础
查看>>
ubuntu 解压命令全部
查看>>
Chrome教程(一)NetWork面板分析网络请求
查看>>
第十八回  基础才是重中之重~开发人员应学会用throw
查看>>
Rosenblatt's perceptron
查看>>
1570:基础练习 分解质因数
查看>>