Skip to content

Commit 5b43b6b

Browse files
author
unknown
committed
Initiate project from Google code
1 parent cc854eb commit 5b43b6b

File tree

1,088 files changed

+89087
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,088 files changed

+89087
-0
lines changed

CodeForces/23/A.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
#define REP(i,n) for(int i=0;i<(n);++i)
5+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
6+
7+
void run() {
8+
string str;
9+
cin >> str;
10+
int len = str.length();
11+
12+
int res = 0;
13+
REP(i,len-res) {
14+
FOR(j,i+1,len-1-res) {
15+
int ct = 0;
16+
while (j + ct < len && str[i + ct] == str[j + ct]) ++ct;
17+
res = max(res, ct);
18+
}
19+
}
20+
21+
cout << res << endl;
22+
}
23+
24+
int main() {
25+
run();
26+
return 0;
27+
}

CodeForces/23/B.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
void run() {
5+
int n;
6+
cin >> n;
7+
cout << max(n - 2, 0) << endl;
8+
}
9+
10+
int main() {
11+
int kase;
12+
for (cin >> kase; kase; --kase) {
13+
run();
14+
}
15+
return 0;
16+
}

CodeForces/23/C.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
#define REP(i,n) for(int i=0;i<(n);++i)
7+
typedef long long LL;
8+
9+
class box {
10+
public:
11+
int a, o, idx;
12+
bool operator<(const box &r) const {
13+
return a < r.a;
14+
}
15+
};
16+
17+
void run() {
18+
int n;
19+
cin >> n;
20+
int m = (n << 1) - 1;
21+
22+
vector<box> boxes(m);
23+
24+
LL totalo = 0;
25+
REP(i,m) {
26+
cin >> boxes[i].a >> boxes[i].o;
27+
boxes[i].idx = i + 1;
28+
totalo += boxes[i].o;
29+
}
30+
sort(boxes.begin(), boxes.end());
31+
32+
LL tmp = 0;
33+
REP(i,n) {
34+
tmp += boxes[i << 1].o;
35+
}
36+
37+
cout << "YES" << endl;
38+
if ((tmp << 1) >= totalo) {
39+
REP(i,n) {
40+
if (i) cout << " ";
41+
cout << boxes[i << 1].idx;
42+
}
43+
cout << endl;
44+
} else {
45+
REP(i,n-1) {
46+
if (i) cout << " ";
47+
cout << boxes[(i << 1) + 1].idx;
48+
}
49+
cout << " " << boxes[m - 1].idx << endl;
50+
}
51+
}
52+
53+
int main() {
54+
int kase;
55+
for (cin >> kase; kase; --kase) {
56+
run();
57+
}
58+
return 0;
59+
}

CodeForces/24/A.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <sstream>
4+
#include <fstream>
5+
#include <memory>
6+
#include <string>
7+
#include <vector>
8+
#include <queue>
9+
#include <set>
10+
#include <map>
11+
#include <cstdio>
12+
#include <cstdlib>
13+
#include <cctype>
14+
#include <cmath>
15+
#include <cstring>
16+
using namespace std;
17+
18+
#define REP(i,n) for(int i=0;i<(n);++i)
19+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
20+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
21+
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
22+
#define CLR(x) memset((x),0,sizeof((x)))
23+
typedef long long LL;
24+
typedef vector<int> VI;
25+
typedef vector<string> VS;
26+
27+
int n, idx;
28+
int vv[105];
29+
int mat[105][105];
30+
int mm[105];
31+
32+
void dfs(int now) {
33+
mm[idx] = now;
34+
vv[now] = 1;
35+
++idx;
36+
if (idx == n) return;
37+
38+
REP(i,n) {
39+
if (vv[i] == 1) continue;
40+
if (mat[now][i] == 0) continue;
41+
dfs(i);
42+
return;
43+
}
44+
}
45+
46+
void run() {
47+
cin >> n;
48+
memset(mat, 0, sizeof(mat));
49+
REP(i,n) {
50+
int a, b, c;
51+
cin >> a >> b >> c;
52+
--a, --b;
53+
mat[a][b] = c;
54+
mat[b][a] = -c;
55+
}
56+
memset(vv, 0, sizeof(vv));
57+
idx = 0;
58+
dfs(0);
59+
60+
int cost1 = 0, cost2 = 0;
61+
REP(i,n) {
62+
int f = mm[i], t = mm[(i + 1) % n];
63+
if (mat[f][t] > 0) cost1 += mat[f][t];
64+
else cost2 -= mat[f][t];
65+
}
66+
67+
cout << min(cost1, cost2) << endl;
68+
}
69+
70+
int main() {
71+
run();
72+
return 0;
73+
}

CodeForces/24/B.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <sstream>
4+
#include <fstream>
5+
#include <memory>
6+
#include <string>
7+
#include <vector>
8+
#include <queue>
9+
#include <set>
10+
#include <map>
11+
#include <cstdio>
12+
#include <cstdlib>
13+
#include <cctype>
14+
#include <cmath>
15+
#include <cstring>
16+
using namespace std;
17+
18+
#define REP(i,n) for(int i=0;i<(n);++i)
19+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
20+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
21+
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
22+
#define CLR(x) memset((x),0,sizeof((x)))
23+
typedef long long LL;
24+
typedef vector<int> VI;
25+
typedef vector<string> VS;
26+
27+
class driver {
28+
public:
29+
string name;
30+
int points;
31+
int places[55];
32+
};
33+
34+
vector<driver> mm;
35+
36+
bool cmp1(const driver& a, const driver& b) {
37+
if (a.points != b.points) return b.points < a.points;
38+
REP(i,50) {
39+
if (a.places[i] != b.places[i]) return b.places[i] < a.places[i];
40+
}
41+
42+
return false;
43+
}
44+
45+
bool cmp2(const driver& a, const driver& b) {
46+
if (a.places[0] != b.places[0]) return b.places[0] < a.places[0];
47+
if (a.points != b.points) return b.points < a.points;
48+
FOR(i,1,49) {
49+
if (a.places[i] != b.places[i]) return b.places[i] < a.places[i];
50+
}
51+
52+
return false;
53+
}
54+
55+
int scores[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
56+
57+
map<string, int> mp;
58+
map<string, int>::iterator itr;
59+
60+
void run() {
61+
mp.clear();
62+
mm.clear();
63+
int idx = 0;
64+
int T;
65+
cin >> T;
66+
REP(t,T) {
67+
int n;
68+
cin >> n;
69+
REP(i,n) {
70+
string name;
71+
cin >> name;
72+
itr = mp.find(name);
73+
if (itr == mp.end()) {
74+
driver d = driver();
75+
d.name = name;
76+
d.points = 0;
77+
memset(d.places, 0, sizeof(d.places));
78+
mm.push_back(d);
79+
mp[name] = idx++;
80+
}
81+
82+
int id = mp[name];
83+
if (i < 10) mm[id].points += scores[i];
84+
mm[id].places[i] += 1;
85+
}
86+
}
87+
88+
sort(mm.begin(), mm.end(), cmp1);
89+
cout << mm[0].name << endl;
90+
sort(mm.begin(), mm.end(), cmp2);
91+
cout << mm[0].name << endl;
92+
}
93+
94+
int main() {
95+
run();
96+
return 0;
97+
}

CodeForces/24/C.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <sstream>
4+
#include <fstream>
5+
#include <memory>
6+
#include <string>
7+
#include <vector>
8+
#include <queue>
9+
#include <set>
10+
#include <map>
11+
#include <cstdio>
12+
#include <cstdlib>
13+
#include <cctype>
14+
#include <cmath>
15+
#include <cstring>
16+
using namespace std;
17+
18+
#define REP(i,n) for(int i=0;i<(n);++i)
19+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
20+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
21+
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
22+
#define CLR(x) memset((x),0,sizeof((x)))
23+
typedef long long LL;
24+
25+
void run() {
26+
LL n, idx;
27+
cin >> n >> idx;
28+
LL mx, my;
29+
vector<LL> xx(n), yy(n);
30+
cin >> mx >> my;
31+
REP(i,n) cin >> xx[i] >> yy[i];
32+
33+
idx %= (n << 1);
34+
REP(i,idx) {
35+
int ii = (i % n);
36+
mx = (xx[ii] << 1) - mx;
37+
my = (yy[ii] << 1) - my;
38+
}
39+
40+
cout << mx << " " << my << endl;
41+
}
42+
43+
int main() {
44+
run();
45+
return 0;
46+
}

CodeForces/README.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://codeforces.com/

0 commit comments

Comments
 (0)