Skip to content

Commit df990cc

Browse files
committed
Sept 28
1 parent 0695a32 commit df990cc

File tree

9 files changed

+457
-0
lines changed

9 files changed

+457
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <cctype>
4+
using namespace std;
5+
6+
/*
7+
8+
g++ -std=c++11 a-a-plus-b.cpp -o k
9+
1 to 2*10^5 strings
10+
*/
11+
12+
void debug() {
13+
cout << "DEBUG" << endl;
14+
}
15+
16+
17+
char change_case (char c, int i) {
18+
if (i != 0)
19+
return std::tolower(c);
20+
else
21+
return std::toupper(c);
22+
}
23+
24+
int main() {
25+
// concatenate b before a and change case
26+
string a, b, c;
27+
cin >> a; cin >> b;
28+
c = b + a;
29+
for(int i = 0; i < c.size(); i++) {
30+
c[i] = change_case(c[i], i);
31+
}
32+
cout << c << endl;
33+
34+
return 0;
35+
}

2019/sept28/practice/b-harmony.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <cctype>
4+
#include <cmath>
5+
#include <utility>
6+
using namespace std;
7+
8+
/*
9+
10+
g++ -std=c++11 b-harmony.cpp -o k
11+
1 to 2*10^5 strings
12+
*/
13+
14+
void debug() {
15+
cout << "DEBUG" << endl;
16+
}
17+
18+
// "larger" or "higher", "smaller" or "lower"
19+
// p : q <=> p/q
20+
pair<string, string> notes[] = {
21+
make_pair("A", "G#"), // -11
22+
make_pair("A", "G"), // -10
23+
make_pair("A", "F#"), // -9
24+
make_pair("A", "F"), // -8
25+
make_pair("A", "E"), // -7
26+
make_pair("A", "D#"), // -6
27+
make_pair("A", "D"), // -5
28+
make_pair("A", "C#"), // -4
29+
make_pair("A", "C"), // -3
30+
make_pair("A", "B"), // -2
31+
make_pair("A", "A#"), // -1
32+
make_pair("A", "A"), // 0
33+
make_pair("A", "G#"), // 1
34+
make_pair("F", "G"), // 2
35+
make_pair("A", "F#"), // 3
36+
make_pair("A", "F"), // 4
37+
make_pair("A", "E"), // 5
38+
make_pair("A", "D#"), // 6
39+
make_pair("A", "D"), // 7
40+
make_pair("A", "C#"), // 8
41+
make_pair("A", "C"), // 9
42+
make_pair("A", "B"), // 10
43+
make_pair("A", "A#") // 11
44+
};
45+
46+
int main() {
47+
// concatenate b before a and change case
48+
int p, q;
49+
cin >> p; cin >> q;
50+
float c = log2( ((float) p) / ((float) q) );
51+
int c1, c2;
52+
string a1, a2;
53+
54+
c = c - trunc(c);
55+
c = 12 * c;
56+
int i = -11;
57+
for(; i < 12; i++) {
58+
if((-0.5 - 0.006 <= c - ((float) i)) && (c - ((float) i) <= 0.5 + 0.006)) {
59+
break;
60+
}
61+
}
62+
63+
c = 100.0*(c - ((float) i));
64+
int j = -50;
65+
for(; j < 51; j++) {
66+
if(-0.6 <= c - ((float) j) && c - ((float) j) <= 0.6) {
67+
break;
68+
}
69+
}
70+
71+
if(j >= 25) {
72+
c1 = 25; c2 = -(j - 25);
73+
} else if(j >= 0) {
74+
c1 = j; c2 = 0;
75+
} else if(j >= -24) {
76+
c1 = 0; c2 = -j;
77+
} else { // j >= -50
78+
c1 = j + 25; c2 = 25;
79+
}
80+
81+
pair<string, string> note = notes[i + 11];
82+
a1 = note.first; a2 = note.second;
83+
cout << a1 << " " << c1 << endl;
84+
cout << a2 << " " << c2 << endl;
85+
86+
return 0;
87+
}
88+

2019/sept28/practice/problems.pdf

161 KB
Binary file not shown.

2019/sept28/tryouts/a-abnormal.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <cctype>
4+
#include <cmath>
5+
#include <utility>
6+
using namespace std;
7+
8+
/*
9+
https://stackoverflow.com/questions/522778/caesar-cipher-in-c
10+
g++ -std=c++11 a-abnormal.cpp -o k
11+
*/
12+
13+
void debug() {
14+
cout << "DEBUG" << endl;
15+
}
16+
17+
char encode(char ch, int key) {
18+
ch -= 'a';
19+
ch = ( ch + key + 26 ) % 26;
20+
ch += 'a';
21+
return ch;
22+
}
23+
24+
char decode(char ch, int key) {
25+
ch -= 'a';
26+
ch = ( ch - key + 26 ) % 26;
27+
ch += 'a';
28+
return ch;
29+
}
30+
31+
int main() {
32+
char e;
33+
int s;
34+
string w;
35+
cin >> e >> s >> w;
36+
for(int i = 0; i < w.size(); i++) {
37+
if(e == 'E')
38+
w[i] = encode(w[i], s);
39+
else
40+
w[i] = decode(w[i], s);
41+
}
42+
cout << w << endl;
43+
return 0;
44+
}
45+
46+
47+
48+
49+
50+

2019/sept28/tryouts/b-balanced.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <cctype>
4+
#include <cmath>
5+
#include <vector>
6+
#include <utility>
7+
#include <set>
8+
using namespace std;
9+
10+
/*
11+
g++ -std=c++11 b-balanced.cpp -o k
12+
SUCCESS!
13+
14+
1
15+
TheStrong 90 60 10
16+
17+
5
18+
TheStrong 90 60 10
19+
TheInvincible 10000 10000 10000
20+
TheTough 70 50 25
21+
TheBrick 3 1 4159
22+
TheResilient 160 40 10
23+
24+
10
25+
TheStrong 90 60 10
26+
TheInvincible 10000 10000 10000
27+
TheTough 70 50 25
28+
TheBrick 3 1 4159
29+
TheResilient 160 40 10
30+
2TheStrong 90 60 10
31+
2TheInvincible 10000 10000 10000
32+
2TheTough 70 50 25
33+
2TheBrick 3 1 4159
34+
2TheResilient 160 40 10
35+
*/
36+
37+
void debug() {
38+
cout << "DEBUG" << endl;
39+
}
40+
41+
bool i_beats_j(int hpi, int ati, int dfi, int hpj, int atj, int dfj) {
42+
if(atj - dfi <= 0 && ati - dfj <= 0) {
43+
return false;
44+
} else if(atj - dfi <= 0) {
45+
return true;
46+
} else if(ati - dfj <= 0) {
47+
return false;
48+
} else {
49+
if(ceil( ((float) hpi) / (atj - dfi)) == ceil( ((float) hpj) / (ati - dfj))) {
50+
return false;
51+
} else if(ceil( ((float) hpi) / (atj - dfi)) > ceil( ((float) hpj) / (ati - dfj))) {
52+
return true;
53+
} else {
54+
return false;
55+
}
56+
}
57+
}
58+
59+
int main() {
60+
int N, acc; acc = 0;
61+
vector<string> sol;
62+
cin >> N;
63+
string name[N];
64+
int HP[N];
65+
int AT[N];
66+
int DF[N];
67+
set<int> b[N];
68+
bool tmp;
69+
for(int i = 0; i < N; i++) {
70+
cin >> name[i] >> HP[i] >> AT[i] >> DF[i];
71+
b[i] = set<int>();
72+
}
73+
74+
if(N < 3) {
75+
cout << 0 << endl;
76+
return 0;
77+
}
78+
79+
for(int i = 0; i < N; i++) {
80+
// compare against fighter
81+
for(int j = 0; j < N; j++) {
82+
tmp = i_beats_j(HP[i], AT[i], DF[i], HP[j], AT[j], DF[j]);
83+
if(i != j && tmp)
84+
b[i].insert(j);
85+
}
86+
}
87+
88+
set<set<int>> touched;
89+
set<int> tmps;
90+
for(int i = 0; i < N; i++) {
91+
for(int j : b[i]) {
92+
for(int k : b[j]) {
93+
if(b[k].count(i) != 0) {
94+
// we found it
95+
tmps = set<int>();
96+
tmps.insert(i);
97+
tmps.insert(j);
98+
tmps.insert(k);
99+
if(touched.count(tmps) == 0) {
100+
acc += 1;
101+
sol.push_back(name[i] + " " + name[j] + " " + name[k]);
102+
touched.insert(tmps);
103+
}
104+
}
105+
}
106+
}
107+
}
108+
109+
cout << acc << endl;
110+
for(const string& str : sol) {
111+
cout << str << endl;
112+
}
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)