pku3668 Game of Lines
http://poj.org/problem?id=3668
水题,STL
#include <stdio.h>
#include <set> using namespace std; set<pair<int, int> > set1; int gcd(int x, int y)
{
return y? gcd(y, x%y): x;
} int abs(int x)
{
return x<? -*x: x;
} struct P
{
int x, y;
}p[]; int main()
{
int n, i, j;
int x, y, gcd_xy;
while(~scanf("%d", &n))
{
set1.clear();
for(i=; i<=n; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
}
for(i=; i<=n-; i++)
{
for(j=i+; j<=n; j++)
{
x = p[i].x - p[j].x;
y = p[i].y - p[j].y;
if(x < )
{
x *= -;
y *= -;
}
gcd_xy = gcd(abs(x), abs(y));
x /= gcd_xy;
y /= gcd_xy;
if(x == )
{
y = ;
}
if(y == )
{
x = ;
}
//printf("%d %d : %d %d\n", i, j, x, y);
set1.insert(make_pair(x, y));
}
}
printf("%d\n", (int)set1.size());
}
return ;
}
pku3668 Game of Lines的更多相关文章
- extracting lines bases a list using awk
extracting lines bases a list using awk awk 'NR==FNR{a[$1]=$0; next}($1 in a){print a[$1]"\n&qu ...
- Enum:Game of Lines(POJ 3668)
画直线 题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条 数据量比较少,直接暴力枚举,然后放到set查找即可 #include <iostream> #include < ...
- 我的常用mixin 之 lines
/** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...
- uva 1471 defence lines——yhx
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- [CareerCup] 13.1 Print Last K Lines 打印最后K行
13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
随机推荐
- MyEclipse 2014 + JSP+ Servlet
来自:http://blog.csdn.net/21aspnet/article/details/21867241 1.安装准备 1).下载安装MyEclipse2014,这已经是最新版本. 2).下 ...
- NFC(3)Android上的NFC,开启NFC,3种NDEF数据
Android对NFC技术的支持 Android2.3.1(API Level = 9)开始支持NFC技术,但Android2.x和Android3.x对NFC的支持非常有限.而从Android4.0 ...
- 关于BigDecimal的四舍五入和截断 (2007-08-10 15:06:26)
关于四舍五入:ROUND_HALF_UP: 遇到.5的情况时往上近似,例: 1.5 ->;2ROUND_HALF_DOWN : 遇到.5的情况时往下近似,例: 1.5 ->;1 BigDe ...
- 1287. Mars Canals(DP)
1287 水DP #include <iostream> #include<cstdio> #include<cstring> #include<algori ...
- BCB遍历所有窗体的组件
for(iFormIdx=0; iFormIdx<Screen->FormCount; iFormIdx++) { TForm *pForm = Screen->Forms[iFor ...
- uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)
题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...
- 信息:Could not publish server configuration for Tomcat v6.0 Server at localhost. Multiple Context
需要把server.xml更正一下,去掉重复的context.或者把整个server文件夹都删掉,重新添加服务器.也可以在server窗口中删除server,再新添加一个server.
- java 语言里 遍历 collection 的方式
我来简单说一下吧,一般有2种方法来遍历collection中的元素,以HashSet为例子HashSet hs=new HashSet();hs.add("hello");hs.a ...
- Java与正则表达式
Java与正则表达式 标签: Java基础 正则 正如正则的名字所显示的是描述了一个规则, 通过这个规则去匹配字符串. 学习正则就是学习正则表达式的语法规则 正则语法 普通字符 字母, 数字, 汉字, ...
- SQL Server索引怎么用
什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...