-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.hpp
89 lines (70 loc) · 1.64 KB
/
utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* File: utils.hpp
* Author: einstein
*
* Created on 26 de Setembro de 2011, 09:27
*/
#ifndef UTILS_HPP
#define UTILS_HPP
#define EPSLON 0.0001
//#define INFINITY 999999
//#define min(A,B) ((A<B)?A:B)
//#define max(A,B) ((A>B)?A:B)
//#define debug
#include <iostream>
#include <cctype>
#include <cmath>
using namespace std;
int comparaDec(const void * a, const void * b, void * cost) {
double * score = (double*) cost;
if (score[*(int*) a] > score[*(int*) b])
return -1;
if (score[*(int*) a] + EPSLON < score[*(int*) b])
return 1;
return 0;
}
int comparaCres(const void * a, const void * b, void * cost) {
double * score = (double*) cost;
if (score[*(int*) a] > score[*(int*) b])
return 1;
if (score[*(int*) a] < score[*(int*) b])
return -1;
return 0;
}
int comparaCresInt(const void* a, const void* b, void* cost) {
int * score = (int*) cost;
if (score[*(int*) a] > score[*(int*) b])
return 1;
if (score[*(int*) a] < score[*(int*) b])
return -1;
return 0;
}
int comparaDecInt(const void* a, const void* b, void* cost) {
int * score = (int*) cost;
if (score[*(int*) a] > score[*(int*) b])
return -1;
if (score[*(int*) a] < score[*(int*) b])
return 1;
return 0;
}
void swap(int &a, int &b) {
int aux = a;
a = b;
b = aux;
}
void swap(double &a, double &b) {
double aux = a;
a = b;
b = aux;
}
double dist(double x1, double y1, double x2, double y2) {
x1 -= x2;
y1 -= y2;
x1 *= x1;
y1 *= y1;
return sqrt(x1 + y1);
}
double quadrado(double x) {
return x*x;
}
#endif /* UTILS_HPP */