-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,180 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
typedef long long Int; | ||
|
||
int T; | ||
string ss1, ss2, s1, s2; | ||
map<char, char> mp; | ||
|
||
//Solver for mathematical expressions | ||
void doOp(stack<Int> &num, stack<char> &op){ | ||
Int A = num.top(); num.pop(); | ||
Int B = num.top(); num.pop(); | ||
char oper = op.top(); op.pop(); | ||
Int ans; | ||
if(oper == '+'){ | ||
ans = A+B; | ||
}else if(oper == '-'){ | ||
ans = B-A; | ||
}else if(oper == '*'){ | ||
ans = A*B; | ||
}else{ | ||
if(A != 0){ | ||
ans = B/A; | ||
}else{ | ||
//division by 0 | ||
ans = -1; | ||
} | ||
} | ||
num.push(ans); | ||
} | ||
|
||
Int parse(string s){ | ||
stack<char> op; | ||
stack<Int> num; | ||
map<char,Int> pr; | ||
|
||
//setting the priorities, greater values with higher pr | ||
pr['+'] = 0; | ||
pr['-'] = 0; | ||
pr['*'] = 1; | ||
pr['/'] = 1; | ||
|
||
for (int i = 0; i < s.size(); i++){ | ||
if (s[i] == ')'){ | ||
while(!op.empty() && op.top() != '('){ | ||
doOp(num,op); | ||
} | ||
op.pop(); | ||
} else if(s[i] == '('){ | ||
op.push('('); | ||
} else if(!(s[i] >= '0' && s[i] <= '9')){ | ||
while(!op.empty() && pr[s[i]] <= pr[op.top()] && op.top() != '('){ | ||
doOp(num,op); | ||
} | ||
op.push(s[i]); | ||
} else { | ||
Int ans = 0; | ||
while(i < s.size() && s[i] >= '0' && s[i] <= '9'){ | ||
ans = ans * 10 + (s[i] - '0'); | ||
i++; | ||
} | ||
i--; | ||
num.push(ans); | ||
} | ||
} | ||
while (op.size()) { | ||
doOp(num,op); | ||
} | ||
return num.top(); | ||
} | ||
|
||
int main(void) { | ||
|
||
for(char c='a'; c<='z'; c++) { | ||
mp[c] = '1'; | ||
} | ||
|
||
cin >> T; | ||
cin.ignore(); | ||
while(T--) { | ||
|
||
getline(cin, ss1); | ||
getline(cin, ss2); | ||
|
||
bool ans = true; | ||
int sz1 = ss1.size(), sz2 = ss2.size(); | ||
s1 = ""; | ||
s2 = ""; | ||
|
||
string vals = "+-*()"; | ||
|
||
for(int i=0; i<sz1; i++) { | ||
if (ss1[i] == ' ' || ss1[i] == '\t') continue; | ||
if (isalnum(ss1[i]) || vals.find(ss1[i]) != string::npos) { | ||
s1 += tolower(ss1[i]); | ||
} | ||
} | ||
for(int i=0; i<sz2; i++) { | ||
if (ss2[i] == ' ' || ss2[i] == '\t') continue; | ||
if (isalnum(ss2[i]) || vals.find(ss2[i]) != string::npos) { | ||
s2 += tolower(ss2[i]); | ||
} | ||
} | ||
|
||
sz1 = s1.size(); | ||
sz2 = s2.size(); | ||
|
||
for(char c='a'; c <= 'z'; c++) { | ||
mp[c] = '9'; | ||
string a1 = s1, a2 = s2; | ||
for(int i=0; i<sz1; i++) { | ||
if(a1[i] >= 'a' && a1[i] <= 'z') | ||
a1[i] = mp[a1[i]]; | ||
} | ||
for(int i=0; i<sz2; i++) { | ||
if(a2[i] >= 'a' && a2[i] <= 'z') | ||
a2[i] = mp[a2[i]]; | ||
} | ||
//cout << parse(a1) << " " << parse(a2) << "\n"; | ||
if(parse(a1) != parse(a2)) { | ||
ans = false; | ||
break; | ||
} | ||
} | ||
|
||
cout << (ans ? "YES\n" : "NO\n"); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const double INF = 10010010011010.0; | ||
const int MAXN = 45; | ||
const int MAX_PROFIT = 200 * 32; | ||
|
||
int N; | ||
string S; | ||
int D; | ||
pair<int, int> P[MAXN]; | ||
int SC[MAXN]; | ||
double dist[MAXN][MAX_PROFIT]; | ||
|
||
int can(int max_spent, int gain) { | ||
priority_queue<pair<pair<double, int>, int> > q; | ||
q.push(make_pair(make_pair(0.0, 0), 0)); | ||
|
||
for (int i = 0; i < MAXN; i++) { | ||
for (int j = 0; j < MAX_PROFIT; j++) { | ||
dist[i][j] = INF; | ||
} | ||
} | ||
|
||
dist[0][0] = 0; | ||
|
||
while (!q.empty()) { | ||
double len = -q.top().first.first; | ||
int pro = +q.top().first.second; | ||
int pos = q.top().second; | ||
q.pop(); | ||
|
||
if (len + hypot(P[pos].first, P[pos].second) > max_spent) { | ||
continue; | ||
} | ||
|
||
if (pro >= gain) { | ||
return 1; | ||
} | ||
|
||
for (int i = pos + 1; i <= N; i++) { | ||
double next_len = len + hypot(P[pos].first - P[i].first, P[pos].second - P[i].second); | ||
int next_pro = pro + SC[i]; | ||
int next = i; | ||
|
||
if (dist[next][next_pro] > dist[pos][pro] + next_len) { | ||
dist[next][next_pro] = dist[pos][pro] + next_len; | ||
q.push(make_pair(make_pair(-next_len, next_pro), next)); | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main() { | ||
int test = 1; | ||
|
||
while (cin >> N && N != 0) { | ||
cout << "Race " << test++ << "\n"; | ||
|
||
P[0].first = 0; | ||
P[0].second = 0; | ||
|
||
for (int i = 1; i <= N; i++) { | ||
cin >> P[i].first >> P[i].second >> SC[i]; | ||
} | ||
|
||
while (cin >> S >> D) { | ||
if (S == "#") break; | ||
|
||
int l = 0, h = MAX_PROFIT, m; | ||
int best = 0; | ||
|
||
while (l <= h) { | ||
m = (l + h) / 2; | ||
|
||
if (can(D, m)) { | ||
best = m; | ||
l = m + 1; | ||
} else { | ||
h = m - 1; | ||
} | ||
} | ||
|
||
cout << S << ": " << best << "\n"; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int T; | ||
string S; | ||
|
||
string func(int x, int mx) { | ||
string ans = ""; | ||
|
||
for (int i = 0; i < x; i++) { | ||
ans += "+"; | ||
} | ||
|
||
while (ans.size() < mx) { | ||
ans = "*" + ans; | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
int main() { | ||
cin >> T; | ||
|
||
while (cin >> S) { | ||
vector<string> arg; | ||
int mx = 0; | ||
|
||
for (int i = 0; i < (int) S.size(); i++) { | ||
mx = max(mx, S[i] - '0'); | ||
} | ||
|
||
for (int i = 0; i < (int) S.size(); i++) { | ||
if (i == 0) { | ||
arg.push_back(func(S[i] - '0', mx)); | ||
} else { | ||
if (S[i - 1] < S[i]) { | ||
for (int j = S[i - 1] - '0' + 1; j <= S[i] - '0'; j++) { | ||
arg.push_back(func(j, mx)); | ||
} | ||
} else if (S[i - 1] > S[i]) { | ||
for (int j = S[i - 1] - '0' - 1; j >= S[i] - '0'; j--) { | ||
arg.push_back(func(j, mx)); | ||
} | ||
} else { | ||
arg.push_back(func(S[i] - '0', mx)); | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < mx; i++) { | ||
for (int j = 0; j < arg.size(); j++) { | ||
cout << arg[j][i]; | ||
} | ||
cout << "\n"; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef unsigned long long Hash; | ||
|
||
const int MAXN = 50050; | ||
|
||
int T; | ||
string L, R; | ||
|
||
Hash C1 = 5831ULL; | ||
Hash B1 = 991ULL; | ||
|
||
Hash C2 = 523ULL; | ||
Hash B2 = 617ULL; | ||
|
||
Hash C[MAXN][2]; | ||
Hash poww[MAXN][2]; | ||
Hash h[MAXN][2][2]; | ||
|
||
void pre() { | ||
poww[0][0] = 1ULL; | ||
poww[0][1] = 1ULL; | ||
|
||
C[0][0] = C1; | ||
C[0][1] = C2; | ||
|
||
for (int i = 1; i < MAXN; i++) { | ||
poww[i][0] = poww[i-1][0] * B1; | ||
poww[i][1] = poww[i-1][1] * B2; | ||
|
||
C[i][0] = C[i-1][0] * C1; | ||
C[i][1] = C[i-1][1] * C2; | ||
} | ||
} | ||
|
||
void buildHash(string arg, int id) { | ||
h[0][id][0] = 0ULL; | ||
h[0][id][1] = 0ULL; | ||
|
||
for (int i = 1; i <= (int) arg.size(); i++) { | ||
h[i][id][0] = h[i - 1][id][0] * B1 + (arg[i - 1] - 'a'); | ||
h[i][id][1] = h[i - 1][id][1] * B2 + (arg[i - 1] - 'a'); | ||
} | ||
} | ||
|
||
pair<Hash, Hash> getHash(int id, int a, int b){ | ||
Hash ha = h[b][id][0] - h[a][id][0] * poww[b-a][0] + C[b-a][0]; | ||
Hash hb = h[b][id][1] - h[a][id][1] * poww[b-a][1] + C[b-a][1]; | ||
|
||
return make_pair(ha, hb); | ||
} | ||
|
||
int main() { | ||
cin.tie(0); | ||
ios_base::sync_with_stdio(false); | ||
|
||
cin >> T; | ||
|
||
pre(); | ||
|
||
for (int t = 1; t <= T; t++) { | ||
cin >> L >> R; | ||
|
||
buildHash(L, 0); | ||
buildHash(R, 1); | ||
|
||
int ans = 0; | ||
|
||
//cout << getHash(0, 0, 1).first << "\n"; | ||
|
||
for (int i = 0; i <= (int) L.size(); i++) { | ||
if (i > R.size()) break; | ||
pair<Hash, Hash> cl = getHash(0, L.size() - i, L.size()); | ||
pair<Hash, Hash> cr = getHash(1, 0, i); | ||
|
||
|
||
if (cl.first == cr.first && cl.second == cr.second) { | ||
//cout << L.substr(L.size() - i - 1, i + 1) << " " << R.substr(0, i + 1) << "\n"; | ||
//cout << L.substr(L.size() - i - 1, i + 1) << " "; | ||
//cout << R.substr(0, i + 1) << "\n"; | ||
//cout << cl.first << " " << cr.first << "\n"; | ||
|
||
|
||
ans += 1; | ||
} | ||
} | ||
|
||
cout << ans << "\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
aajjbb@aajjbb-notebook.1400:1467926877 |
Oops, something went wrong.