Skip to content

Commit

Permalink
notebook windows changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Aug 15, 2013
1 parent 9738ca8 commit 4901423
Show file tree
Hide file tree
Showing 10 changed files with 5,200 additions and 2,443 deletions.
36 changes: 20 additions & 16 deletions LiveArchive/DanceDanceRevolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace std;
typedef long long Int;
typedef unsigned uint;

const int MAXN = 400;
const int MAXN = 10010;

int N;

Expand All @@ -65,7 +65,8 @@ vector<int> split (string str) {
return ans;
}

int dp[MAXN][5][5];
Int dp[MAXN][5][5];
int V[MAXN];

int move(int f, int t) {
if (f == 0) return 2;
Expand All @@ -77,31 +78,34 @@ int move(int f, int t) {
return 3;
}

int func(vector<int>& V, int index, int left, int right) {
if (index == N) return 0;
Int func(int index, int left, int right) {
if (index == N) return 0LL;

int& ans = dp[index][left][right];
Int& ans = dp[index][left][right];

if (ans != -1) return ans;
if (ans != -1) return ans;


ans = 100101010010010LL;

ans = move(left, V[index]) + func(V, index + 1, V[index], right);
chmin(ans, move(left, V[index]) + func(index + 1, V[index], right));

ans = min(ans, move(right, V[index]) + func(V, index + 1, left, V[index]));
chmin(ans, move(right, V[index]) + func(index + 1, left, V[index]));

return ans;
}

int main(void) {
for ( ; ; ) {
vector<int> V = split(string(gets(str)));

N = V.size() - 1;

if (N == 0) break;
int a;

while( scanf( "%d", &a ), a ) {
V[0] = a;
N = 0;
while ( scanf( "%d", &V[++N]), V[N] );

memset(dp, -1, sizeof(dp));
memset(dp, -1LL, sizeof(dp));

printf("%d\n", func(V, 0, 0, 0));
printf("%lld\n", func(0, 0, 0));
}
return 0;
}
Binary file modified LiveArchive/DanceDanceRevolution.o
Binary file not shown.
65 changes: 65 additions & 0 deletions PKU/BankInterest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
#include <iomanip>
#include <numeric>
#include <functional>
#include <new>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cctype>
#include <ctime>

#define REP(i, n) for(int (i) = 0; i < n; i++)
#define FOR(i, a, n) for(int (i) = a; i < n; i++)
#define FORR(i, a, n) for(int (i) = a; i <= n; i++)
#define for_each(q, s) for(typeof(s.begin()) q=s.begin(); q!=s.end(); q++)
#define sz(n) n.size()
#define pb(n) push_back(n)
#define all(n) n.begin(), n.end()

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;

int R, M, Y;

int main(void) {
R = in(), M = in(), Y = in();

int i;

double ans = (double) M, rate = 1.0 + (R / 100.0);

for (i = 0; i < Y; i++) {
ans *= rate;
}

cout << setprecision(0) << fixed << floor(ans) << "\n";

return 0;
}
Binary file added PKU/BankInterest.o
Binary file not shown.
99 changes: 45 additions & 54 deletions SPOJ/CampeonatoSMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ using namespace std;
typedef long long Int;
typedef unsigned uint;

const int MAXN = 170;
const int MAXN = 300;

int N;
string buff, str;

double dp[MAXN][15][15];
double dist[15][15];
double dp[MAXN][12][12];
double dist[12][12];

map<char, int> belong;
map<char, int> types;
int belong[512];
int types[512];

int decode(int a, int b) {
if (a == 1 && b == 2) return 2;
Expand All @@ -72,8 +72,39 @@ int decode(int a, int b) {
}

void build(void) {
int i, j, k, l;
}

void clear(void) {
int i, j, k;
memset(dp, -100.0, sizeof(dp));
}

int same(char a, char b) {
return belong[a] == belong[b];
}

double move_cost (int a, char b) {
return dist[a][belong[b]];
}

double func(int index, int l, int r) {
if (index >= str.size()) return 0.0;

double& ans = dp[index][l][r];

if (ans >= 0) return ans;

double l_cost = move_cost(l, str[index]);
double r_cost = move_cost(r, str[index]);

ans = l_cost + func(index + 1, belong[str[index]], r);

ans = min(ans, r_cost + func(index + 1, l, belong[str[index]]));

return ans;
}

int main(void) {
belong['a'] = belong['b'] = belong['c'] = 2;
belong['d'] = belong['e'] = belong['f'] = 3;
belong['g'] = belong['h'] = belong['i'] = 4;
Expand All @@ -91,6 +122,8 @@ void build(void) {
types['b'] = types['e'] = types['h'] = types['k'] = types['n'] = types['q'] = types['u'] = types['x'] = 2;
types['c'] = types['f'] = types['i'] = types['l'] = types['o'] = types['r'] = types['v'] = types['y'] = 3;
types['s'] = types['z'] = 4;

int i, j, k, l;

for (i = 1; i <= 4; i++) {
for (j = 1; j <= 3; j++) {
Expand All @@ -100,58 +133,12 @@ void build(void) {

if (id_a == -1 || id_b == -1) continue;

//printf("%d %d - %.2lf\n", decode(i, j), decode(k, l), hypot(i - k, j - l));

dist[id_a][id_b] = (double) hypot(i - k, j - l);
}
}
}
}
}

void clear(void) {
int i, j, k;

for (i = 0; i < MAXN; i++) {
for (j = 0; j < 15; j++) {
for (k = 0; k < 15; k++) {
dp[i][j][k] = -1.0;
}
}
}
}

int same(char a, char b) {
return belong[a] == belong[b];
}

double move_cost (int a, char b) {
return dist[a][belong[b]];
}

double func(int index, int l, int r) {
if (index >= str.size()) return 0.0;

double& ans = dp[index][l][r];

if (ans != -1.0) return ans;

double l_cost = move_cost(l, str[index]);
double r_cost = move_cost(r, str[index]);

ans = l_cost + func(index + 1, belong[str[index]], r);

ans = min(ans, r_cost + func(index + 1, l, belong[str[index]]));

return ans;
}

int main(void) {
freopen("i.in", "r", stdin);
//freopen("o.ot", "w", stdout);
int i;

build();

for ( ; getline(cin, buff); ) {
clear();
Expand All @@ -167,9 +154,13 @@ int main(void) {
}
str += buff[i];
clicks += (double) types[buff[i]];
}
}

N = str.size();

double ans = func(0, 4, 6) / 30.0 + clicks * 0.20;

printf("%.2lf\n", (func(0, 4, 6) / 30.0) + clicks * 0.20);
printf("%.2lf\n", ans);
}
return 0;
}
Binary file modified SPOJ/CampeonatoSMS.o
Binary file not shown.
52 changes: 19 additions & 33 deletions SPOJ/CampeonatoSMS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ using namespace std;
typedef long long Int;
typedef unsigned uint;

const int MAXN = 300;
const int MAXN = 285;
const double EPS = 1e-7;

int N;
string buff, str;

double dp[MAXN][7][7][7][7];
double dist[15][15];
double dp[MAXN][5][5][5][5];

map<char, pair<int, int> > belong;
map<char, int> types;
int types[512];

int decode(int a, int b) {
if (a == 1 && b == 2) return 2;
Expand All @@ -75,10 +74,10 @@ int decode(int a, int b) {
void build(void) {
int i, j, k, l;

belong.clear(); types.clear();
belong.clear();

belong['a'] = belong['b'] = belong['c'] = make_pair(1, 1);
belong['d'] = belong['e'] = belong['f'] = make_pair(1, 2);
belong['a'] = belong['b'] = belong['c'] = make_pair(1, 2);
belong['d'] = belong['e'] = belong['f'] = make_pair(1, 3);
belong['g'] = belong['h'] = belong['i'] = make_pair(2, 1);
belong['j'] = belong['k'] = belong['l'] = make_pair(2, 2);
belong['m'] = belong['n'] = belong['o'] = make_pair(2, 3);
Expand All @@ -99,18 +98,8 @@ void build(void) {

void clear(void) {
int i, j, k, l, m;

for (i = 0; i < MAXN; i++) {
for (j = 0; j < 7; j++) {
for (k = 0; k < 7; k++) {
for (l = 0; l < 7; l++) {
for (m = 0; m < 7; m++) {
dp[i][j][k][l][m] = -1.0;
}
}
}
}
}

memset(dp, -100.0, sizeof(dp));
}

int same(char a, char b) {
Expand All @@ -122,23 +111,19 @@ double func(int index, int l_i, int l_j, int r_i, int r_j) {

double& ans = dp[index][l_i][l_j][r_i][r_j];

if (ans != -1.0) return ans;
if (ans >= 0) return ans;

pair<int, int> p = belong[str[index]];

if (p.first == l_i && p.second == l_j) return ans = func(index + 1, l_i, l_j, r_i, r_j);
if (p.first == r_i && p.second == r_j) return ans = func(index + 1, l_i, l_j, r_i, r_j);

double go_l = (double) hypot(l_i - p.first, l_j - p.second) + (double) func(index + 1, p.first, p.second, r_i, r_j);
double go_r = (double) hypot(r_i - p.first, r_j - p.second) + (double) func(index + 1, l_i, l_j, p.first, p.second);

return ans = min(go_l, go_r);
ans = (double) hypot(l_i - p.first, l_j - p.second) + func(index + 1, p.first, p.second, r_i, r_j);
chmin(ans, (double) hypot(r_i - p.first, r_j - p.second) + func(index + 1, l_i, l_j, p.first, p.second));

return ans;
}

int main(void) {
int main(void) {
freopen("i.in", "r", stdin);
//freopen("o.ot", "w", stdout);
/freopen("o.ot", "w", stdout);
int i;

build();
Expand All @@ -157,10 +142,11 @@ int main(void) {
}
str += buff[i];
clicks += (double) types[buff[i]];
}
}

double ans = func(0, 2, 1, 2, 3) / 30.0 + clicks * 0.20;

printf("%.2lf\n", ((double) func(0, 2, 1, 2, 3) * 0.033333333) + ((double) clicks * 0.20));
cout << setprecision(2) << fixed << ans << "\n";
}
return 0;
}

}
Binary file modified SPOJ/CampeonatoSMS2.o
Binary file not shown.
Loading

0 comments on commit 4901423

Please sign in to comment.