POJ 3668 Game of Lines (暴力,判重)

题意:给定 n 个点,每个点都可以和另一个点相连,问你共有多少种不同斜率的直线。

析:那就直接暴力好了,反正数也不大,用set判重就好,注意斜率不存在的情况。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 30000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int m, n;
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
int x[maxn], y[maxn];
set<double> sets;

int main(){
    while(scanf("%d", &n) == 1){
        sets.clear();
        for(int i = 0; i < n; ++i)  scanf("%d %d", &x[i], &y[i]);
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                if(x[i] == x[j])  sets.insert(inf);
                else  sets.insert((y[i]-y[j])*1.0/(x[i]*1.0-x[j]*1.0));
        printf("%d\n", sets.size());
    }
    return 0;
}
时间: 2024-12-04 21:50:29

POJ 3668 Game of Lines (暴力,判重)的相关文章

poj 1465 &amp; zoj 1136 Multiple (BFS+余数重判)

Multiple Time Limit: 1000MS   Memory Limit: 32768K Total Submissions: 6177   Accepted: 1346 Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the small

poj 1269 Intersecting Lines(判相交交点与平行)

http://poj.org/problem?id=1269 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10379   Accepted: 4651 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in

HDU 4474&amp;&amp;POJ 1465 BFS&amp;&amp;余数判重

两道题只是输入输出格式略有不同 给出n,m,m个数 要求生成一个数x,是n的倍数,并且只由这M个数构成(或不能含有这M个数中的任意一个),求最小的x,没有则输出-1(0): BFS找每一个满足n的倍数的数,用余数判重优化 对于给定两个数A,B,如果A和B模N都相同,设为C,即: A=x*N+C B=y*N+C 那么如果在A后面加上一个数字能够被N整除,则在B后面加上这个数字也肯定可以被N整除 即:(A*10+X)%N==(B*10+X)%N 因此可以利用模N的结果进行判重,只保留相同余数的最小数

poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)

题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一个边界外,跳到了另一边的边界外,每跳一次对那个点进行标记. 现在给你很多青蛙跳过后的所标记的所有点,那请你从这些点里面找出 一条可能的路径里面出现过的标记点最多. 分析:先排序(目的是方便剪枝,break),然后枚举两个点,这两个 点代表这条路径的起始的两个点.然后是三个剪枝,下面有. 开始遍历时,

POJ 1101 The Game(BFS+判方向)

    The Game Description One morning, you wake up and think: "I am such a good programmer. Why not make some money?'' So you decide to write a computer game. The game takes place on a rectangular board consisting of w * h squares. Each square might o

hdu 5012 bfs --- 慎用STL 比如MAP判重

http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 如果Sting s = '1'+'2'+'3'; s!="123"!!!!!!  而是有乱码 先贴一份自己的TLE 代码, 超时应该是因为: 1.cin 2.map判重 map find太花时间 3.string花时间 4.其实不用两个都旋转,只要旋转一个就行,这样可以省下很多时间 包括少用了make_pair pair的判重等等....哎  二笔了  太暴力了 #include

poj1840Eqs(哈希判重)

题目链接: 传送门 思路: 这道题是一个简单的hash的应用,如果直接暴力的话肯定承受不了5重for循环,所以比赛的时候我先到分成两组,但是后来用到了许多数组,然后想到数字太大,还先到stl判重, 后来搞出来还是在本地跑的很慢,就放弃了..后来看到题解,不得不说太牛了,我的思路是对的,首先把方程分成左右两边,然后分别暴力,因为计算结果的上限可能达到 50*50*50*50*2=1250000,所以取值范围为-12500000--12500000,所以为了避免冲突,应该将hash数组开到2*125

poj1465Multiple(经典BFS+余数判重)

Multiple Time Limit: 1000MS   Memory Limit: 32768K Total Submissions: 6936   Accepted: 1495 Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the small

[bfs+余数判重+路径记录] hdu 4474 Yet Another Multiple Problem

题意: 给一个n和m个数字(一位数) 求最小的n的倍数不含有这m个数字,不存在输出-1 思路: 首先有可能这个数超long long 所以无法暴力解决 所以这题应该是一个bfs 为什么能用余数判重呢 对于当前的余数进到队列里,一定是这个余数对应数的最小值 接下来再怎么添加到满足条件的后续东西应该是一样的 所以就可以余数判重了,类似数位dp的记录方式 然后再加上一个路径记录就好了 代码: #include"cstdlib" #include"cstdio" #incl