-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1aexample.cpp
More file actions
126 lines (105 loc) · 2.58 KB
/
Copy path1aexample.cpp
File metadata and controls
126 lines (105 loc) · 2.58 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
#define INF 1000000000
int main() {
//cout:
cout << " ";
//cin:
cin >> "";
//debug cerr
//round up
(A+(B-1)) /B
return 0;
}
//with cases
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
#define INF 1000000000
int main() {
int t;
cin >> t;
int cases = 1;
while(t--) {
//cout:
cout << " ";
//cin:
cin >> "";
//debug cerr
//round up
(A+(B-1)) /B
cout << "Case #" << cases++ << ": " << ans << endl; //case++
}
return 0;
}
// Ways to change to binary
//the 32 can be changed to the number you need,
//ie 10110 is 5 long so use bitset<5>
bitset<32> bs (number);
__builtin_popcount(number)
//set stack size on windows
g++ -Wl,--stack,numinbytes -std=c++......
//string concatenation to int
string a;
string r = a;
stoi(a+r);
//string word parsing
int main() {
string line, word;
while(getline(cin, line)) {
istringstream iss(line);
while(iss>>word) {
// code goes here
}
}
}
//sort
sort(begin(t), end(t)); //== sort(t.begin(), t.end())DONT USE
//sort greatest/largest
sort(begin(t), end(t), cmp); //greater<int>, orcomparison a>b, a<b
//->reversible containers can be looped backwards
sort(t.rbegin(), t.rend()); //increasing order backwards
//replace
replace(begin(t),end(t),'-',' ');
//function that can compute relative primes of n (non-factors), gcd(x, n) = 1
//Euler phi function(p^k - p^(k-1)) = p^(k-1) * (p-1)
//uninitialized for loop ex:
int n, m;
vector<int> t(n), l(m);
int t_i = 0. l_i = 0;
for( ; l_i < m; l_i++){
for ( ; t_i < n && t[t_i] > l[l_i]; t_i++)
;
if (t_i++ >= n) break;
}
//for checking diff in cmd line
prog < input | diff - output
//random minSwaps function
int minSwaps(vector<int> arr, int n) {
vector<pair<int, int>> arrPos(n);
for(int i=0; i<n;i++){
arrPos[i].first = arr[i];
arrPos[i].second = i;
}
sort(arrPos.begin(), arrPos.end());
vector<bool> visited(n, false);
int ans = 0;
for(int i=0;i<n;i++){
if (visited[i] || arrPos[i].second == i)
continue;
int cycle_size = 0;
int j = i;
while(!visited[j]){
visited[j] = 1;
j = arrPos[j].second;
cycle_size++;
}
if(cycle_size > 0){
ans += (cycle_size - 1);
}
}
return ans;
}