-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.cpp
More file actions
84 lines (67 loc) · 1.71 KB
/
utils.cpp
File metadata and controls
84 lines (67 loc) · 1.71 KB
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
//
// Created by wang mengbo on 2019-09-02.
//
#include "utils.h"
namespace SuperTAD::utils {
int boundariesIntersection(Boundary &b1, Boundary &b2)
{
if (b1.first > b2.second || b2.first > b1.second)
return 0;
else {
int s = std::max(b1.first, b2.first);
int e = std::min(b1.second, b2.second);
// printf("b1=(%d, %d), b2=(%d, %d)\n", b1.first, b1.second, b2.first, b2.second);
return e-s+1;
}
}
// including low but excluding high
int randInt(int low, int high)
{
double d = (double)rand() / (double)RAND_MAX * (high - low);
double intpart;
if (modf(d, &intpart) > 0.5) {
int r = ceil (d);
if (r >= high)
return high - 1;
return r;
}
else
return floor(d);
}
double randDouble(double low, double high)
{
return (double)rand() / (double)RAND_MAX * (high - low);
}
// void copyDoubleArray(double from[], double to[], int n)
// {
// for (int i = 0; i < n; i++) {
// to[i] = from[i];
// }
// }
int LCM(int num1, int num2)
{
int min, max, temp;
if (num1 < num2)
{
max = num2;
min = num1;
}
else
{
max = num1;
min = num2;
}
while (max%min != 0)
{
temp = max%min;
max = min;
min = temp;
}
temp = num1*num2 / temp;
return temp;
}
std::string version()
{
return "SuperTAD v2.0";
}
}