Skip to content

Commit

Permalink
adding uva and 2 codeforces problems
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Jun 1, 2015
1 parent c9e5316 commit 19e3a4b
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 21 deletions.
13 changes: 8 additions & 5 deletions LiveArchive/ElectricCarRally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using namespace std;
typedef long long Int;
typedef unsigned uint;

const int MAXN = 555;
const int MAXL = 601*481 + 10;
const int INF = 10101011;
const int MAXN = 705;
const int MAXL = MAXN*481 + 10;
const int INF = 20101011;

int N, M;
vector<int> graph[MAXN];
Expand Down Expand Up @@ -52,14 +52,16 @@ struct state {
*/

int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
while (cin >> N >> M && !(N == 0 && M == 0)) {
int A, B, X, Y, Z;

for (int i = 0; i < MAXN; i++) {
graph[i].clear();
for (int j = 0; j < MAXN; j++) {
info[i][j].clear();
}
}
}
for (int i = 0; i < M; i++) {
cin >> A >> B;
Expand Down Expand Up @@ -87,7 +89,7 @@ int main(void) {
memset(stim, 63, sizeof(stim));

dist[base.code] = 0;
stim[base.code] = 0;
stim[base.code] = 720;

for ( ; !q.empty(); ) {
state now = q.top();
Expand All @@ -99,6 +101,7 @@ int main(void) {

if (now.id == N - 1) {
chmin(ans, dist[now.code]);
continue;
}

for (int i = 0; i < (int) graph[now.id].size(); i++) {
Expand Down
Binary file modified LiveArchive/a.out
Binary file not shown.
54 changes: 54 additions & 0 deletions URI/AndyDictionary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned uint;

string S;

bool isletter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

int main(void) {
set<string> dict;

while (getline(cin, S)) {
int N = (int) S.size();
string buff = "";

for (int i = 0; i < N; i++) {
if (isletter(S[i])) {
buff += S[i];
} else {
if (!buff.empty()) {
transform(buff.begin(), buff.end(), buff.begin(), ::tolower);
dict.insert(buff);
}
buff = "";
}
}
if (!buff.empty()) {
transform(buff.begin(), buff.end(), buff.begin(), ::tolower);
dict.insert(buff);
}
}

for (string curr: dict) {
cout << curr << "\n";
}
return 0;
}
27 changes: 16 additions & 11 deletions URI/PlayingWithNumbersOBI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef unsigned uint;

string S;
Int N, all = 0, len;
map<int, Int> dp[1 << 13];

Int str_to_int(string arg) {
Int ans = 0;
Expand All @@ -32,20 +33,23 @@ Int str_to_int(string arg) {

bool func(Int x) {
Int sq = (Int) sqrt(x + 0.5);

return sq * sq == x;
}

void rec(int id, int mask, Int val) {
if (id == len) {
if (func(val + N)) all += 1;
Int rec(int mask, Int val) {
if (mask == (1 << len) - 1) {
return func(val + N);
} else {
for (int i = 0; i < len; i++) {
if (id == 0 && S[i] == '0') continue;
if (!(mask & (1 << i))) {
rec(id + 1, mask | (1 << i), val * 10 + (S[i] - '0'));
if (dp[mask].find(val) == dp[mask].end()) {
for (int i = 0; i < len; i++) {
if (mask == 0 && S[i] == '0') continue;
if (!(mask & (1 << i))) {
dp[mask][val] += rec(mask | (1 << i), val * 10 + (S[i] - '0'));
}
}
}

return dp[mask][val];
}
}

Expand All @@ -54,18 +58,19 @@ int main(void) {

len = (int) S.size();
N = str_to_int(S);
rec(0, 0, 0);
//rec(0, 0, 0);

/* sort(S.begin(), S.end());
int ans = 0;
do {
if (S[0] == '0') continue;
if (func(N + str_to_int(S))) {
ans += 1;
}
} while (next_permutation(S.begin(), S.end()));
cout << ans << "\n";
*/
cout << all << endl;
cout << rec(0, 0) << endl;

return 0;
}
60 changes: 60 additions & 0 deletions URI/TellMeTheFrequencies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <bits/stdc++.h>

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned uint;

string S;
int F[500];

bool st(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first) {
return a.first < b.first;
} else {
return a.second > b.second;
}
}

int main(void) {
bool done = false;
while (getline(cin, S)) {
if (done) cout << "\n";
done = true;

int N = (int) S.size();

memset(F, 0, sizeof(F));

for (int i = 0; i < N; i++) {
F[(int) S[i]] += 1;
}

vector<pair<int, int> > ans;

for (int i = 32; i <= 128; i++) {
if (F[i]) {
ans.push_back(make_pair(F[i], i));
}
}

sort(ans.begin(), ans.end(), st);

for (int i = 0; i < (int) ans.size(); i++) {
cout << ans[i].second << " " << ans[i].first << "\n";
}
}
return 0;
}
Binary file modified URI/a.out
Binary file not shown.
6 changes: 1 addition & 5 deletions URI/i.in
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
1
3
Fred Barney
Barney Betty
Betty Wilma
1234567890

0 comments on commit 19e3a4b

Please sign in to comment.