Skip to content

Commit d9ad8db

Browse files
committed
add recent solved problems
1 parent 28c15ac commit d9ad8db

File tree

9 files changed

+1394
-0
lines changed

9 files changed

+1394
-0
lines changed

greedy/3-c712-C.cpp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
#include <cassert>
3+
#include <numeric>
4+
#include <functional>
5+
#include <iostream>
6+
#include <bitset>
7+
#include <cctype>
8+
#include <algorithm>
9+
#include <string>
10+
#include <vector>
11+
#include <cmath>
12+
#include <set>
13+
#include <string>
14+
#include <map>
15+
#include <stack>
16+
#include <cstdio>
17+
#include <cstring>
18+
#include <deque>
19+
#include <sstream>
20+
#include <queue>
21+
#include <tuple>
22+
#include <climits>
23+
#include <complex>
24+
using namespace std;
25+
26+
#define pb push_back
27+
#define pf push_front
28+
#define mp make_pair
29+
#define mt make_tuple
30+
#define INF 0x3f3f3f3f
31+
#define F first
32+
#define S second
33+
#define speedup ios_base::sync_with_stdio(0);cin.tie(0)
34+
#define in_d(a) scanf("%Lf", &a)
35+
#define in_d2(a,b) scanf("%Lf%Lf", &a, &b)
36+
#define in_d3(a,b,c) scanf("%Lf%Lf%Lf", &a, &b, &c)
37+
#define in_d4(a,b,c,d) scanf("%Lf%Lf%Lf%Lf", &a, &b, &c, &d)
38+
#define in_l(a) scanf("%I64d", &a)
39+
#define in_l2(a,b) scanf("%I64d%I64d", &a, &b)
40+
#define in_l3(a,b,c) scanf("%I64d%I64d%I64d", &a, &b, &c)
41+
#define in_l4(a,b,c,d) scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d)
42+
#define in_i(a) scanf("%d", &a)
43+
#define in_i2(a,b) scanf("%d%d", &a, &b)
44+
#define in_i3(a,b,c) scanf("%d%d%d", &a, &b, &c)
45+
#define in_i4(a,b,c,d) scanf("%d%d%d%d", &a, &b, &c, &d)
46+
#define in_s(a) scanf("%s", a)
47+
#define all(c) c.begin(), c.end()
48+
#define rep(i, j, k) for (int i = (j); i < (int)(k); i++)
49+
#define rep2(i,j, f1,t1, f2,t2) for (int i = (f1); i < (int)(t1); i++) for (int j = (f2); j < (int)(t2); j++)
50+
#define Rep(i, j, k) for (int i = (j); i <= (int)(k); i++)
51+
#define Rep2(i,j, f1,t1, f2,t2) for (int i = (f1); i <= (int)(t1); i++) for (int j = (f2); j <= (int)(t2); j++)
52+
#define per(i, j, k) for (int i = (j); i >= (int)(k); i--)
53+
#define out_i(a) printf("%d\n", a);
54+
#define out_i2(a,b) printf("%d %d\n", a, b);
55+
#define out_i3(a,b,c) printf("%d %d %d\n", a, b, c);
56+
#define out_i4(a,b,c,d) printf("%d %d %d %d\n", a, b, c, d);
57+
#define out_l(a) printf("%I64d\n", a);
58+
#define out_l2(a,b) printf("%I64d %I64d\n", a, b);
59+
#define out_l3(a,b,c) printf("%I64d %I64d %I64d\n", a, b, c);
60+
#define out_l4(a,b,c,d) printf("%I64d %I64d %I64d %I64d\n", a, b, c, d);
61+
#define out_d(a) printf("%.10Lf\n", a);
62+
#define out_d2(a,b) printf("%.10Lf %.10Lf\n", a, b);
63+
#define out_d3(a,b,c) printf("%.10Lf %.10Lf %.10Lf\n", a, b, c);
64+
#define out_d4(a,b,c,d) printf("%.10Lf %.10Lf %.10Lf %.10Lf\n", a, b, c, d);
65+
#define out_s(s) printf("%s\n", s);
66+
#define out_ci(c) if (!c.empty()) printf("%d", c[0]); rep(i, 1, c.size()) printf(" %d", c[i]); puts("")
67+
#define out_cd(c) if (!c.empty()) printf("%.10Lf", c[0]); rep(i, 1, c.size()) printf(" %.10Lf", c[i]); puts("")
68+
#define out_cl(c) if (!c.empty()) printf("%I64d", c[0]); rep(i, 1, c.size()) printf(" %I64d", c[i]); puts("")
69+
typedef long long LL;
70+
typedef long double LD;
71+
typedef pair<LL, LL> PLL;
72+
typedef pair<int, int> PII;
73+
typedef pair<LD, LD> PDD;
74+
typedef vector<LD> VD;
75+
typedef vector<PDD> VDD;
76+
typedef vector< vector<PDD> > VVD;
77+
typedef vector<LL> VL;
78+
typedef vector<PLL> VLL;
79+
typedef vector< vector<PLL> > VVL;
80+
typedef vector<int> VI;
81+
typedef vector<PII> VII;
82+
typedef vector<vector<PII> > VVI;
83+
#define N 103000
84+
85+
int cur[4];
86+
87+
int main() {
88+
int x, y;
89+
cin >> x >> y;
90+
if (x > y) swap(x, y);
91+
cur[0] = cur[1] = cur[2] = x;
92+
93+
int ans = 0;
94+
bool ok = 0;
95+
while (!ok) {
96+
ok = 1;
97+
rep(i,0,3) if (cur[i] < y) ok = 0;
98+
int mi=-1, mv=0x3f3f3f3f;
99+
rep(i, 0, 3) {
100+
if (mv > cur[i]) {
101+
mv = cur[i];
102+
mi = i;
103+
}
104+
}
105+
int sum = 0;
106+
rep(i, 0, 3) sum += cur[i];
107+
cur[mi] = sum - cur[mi] - 1;
108+
ans++;
109+
}
110+
cout << ans-1 << endl;
111+
112+
return 0;
113+
}

implementation/5-hihocoder-1383.cpp

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
2+
#include <cassert>
3+
#include <numeric>
4+
#include <functional>
5+
#include <iostream>
6+
#include <bitset>
7+
#include <cctype>
8+
#include <algorithm>
9+
#include <string>
10+
#include <vector>
11+
#include <cmath>
12+
#include <set>
13+
#include <string>
14+
#include <map>
15+
#include <stack>
16+
#include <cstdio>
17+
#include <cstring>
18+
#include <deque>
19+
#include <sstream>
20+
#include <queue>
21+
#include <tuple>
22+
#include <climits>
23+
#include <complex>
24+
using namespace std;
25+
26+
#define pb push_back
27+
#define pf push_front
28+
#define mp make_pair
29+
#define mt make_tuple
30+
#define INF 0x3f3f3f3f
31+
#define F first
32+
#define S second
33+
#define speedup ios_base::sync_with_stdio(0);cin.tie(0)
34+
#define in_d(a) scanf("%Lf", &a)
35+
#define in_d2(a,b) scanf("%Lf%Lf", &a, &b)
36+
#define in_d3(a,b,c) scanf("%Lf%Lf%Lf", &a, &b, &c)
37+
#define in_d4(a,b,c,d) scanf("%Lf%Lf%Lf%Lf", &a, &b, &c, &d)
38+
#define in_l(a) scanf("%lld", &a)
39+
#define in_l2(a,b) scanf("%lld%lld", &a, &b)
40+
#define in_l3(a,b,c) scanf("%lld%lld%lld", &a, &b, &c)
41+
#define in_l4(a,b,c,d) scanf("%lld%lld%lld%lld", &a, &b, &c, &d)
42+
#define in_i(a) scanf("%d", &a)
43+
#define in_i2(a,b) scanf("%d%d", &a, &b)
44+
#define in_i3(a,b,c) scanf("%d%d%d", &a, &b, &c)
45+
#define in_i4(a,b,c,d) scanf("%d%d%d%d", &a, &b, &c, &d)
46+
#define in_s(a) scanf("%s", a)
47+
#define all(c) c.begin(), c.end()
48+
#define rep(i, j, k) for (int i = (j); i < (int)(k); i++)
49+
#define rep2(i,j, f1,t1, f2,t2) for (int i = (f1); i < (int)(t1); i++) for (int j = (f2); j < (int)(t2); j++)
50+
#define Rep(i, j, k) for (int i = (j); i <= (int)(k); i++)
51+
#define Rep2(i,j, f1,t1, f2,t2) for (int i = (f1); i <= (int)(t1); i++) for (int j = (f2); j <= (int)(t2); j++)
52+
#define per(i, j, k) for (int i = (j); i >= (int)(k); i--)
53+
#define out_i(a) printf("%d\n", a);
54+
#define out_i2(a,b) printf("%d %d\n", a, b);
55+
#define out_i3(a,b,c) printf("%d %d %d\n", a, b, c);
56+
#define out_i4(a,b,c,d) printf("%d %d %d %d\n", a, b, c, d);
57+
#define out_l(a) printf("%lld\n", a);
58+
#define out_l2(a,b) printf("%lld %lld\n", a, b);
59+
#define out_l3(a,b,c) printf("%lld %lld %lld\n", a, b, c);
60+
#define out_l4(a,b,c,d) printf("%lld %lld %lld %lld\n", a, b, c, d);
61+
#define out_d(a) printf("%.10Lf\n", a);
62+
#define out_d2(a,b) printf("%.10Lf %.10Lf\n", a, b);
63+
#define out_d3(a,b,c) printf("%.10Lf %.10Lf %.10Lf\n", a, b, c);
64+
#define out_d4(a,b,c,d) printf("%.10Lf %.10Lf %.10Lf %.10Lf\n", a, b, c, d);
65+
#define out_s(s) printf("%s\n", s);
66+
#define out_ci(c) if (!c.empty()) printf("%d", c[0]); rep(i, 1, c.size()) printf(" %d", c[i]); puts("")
67+
#define out_cd(c) if (!c.empty()) printf("%.10Lf", c[0]); rep(i, 1, c.size()) printf(" %.10Lf", c[i]); puts("")
68+
#define out_cl(c) if (!c.empty()) printf("%lld", c[0]); rep(i, 1, c.size()) printf(" %lld", c[i]); puts("")
69+
typedef long long LL;
70+
typedef long double LD;
71+
typedef pair<LL, LL> PLL;
72+
typedef pair<int, int> PII;
73+
typedef pair<LD, LD> PDD;
74+
typedef vector<LD> VD;
75+
typedef vector<PDD> VDD;
76+
typedef vector< vector<PDD> > VVD;
77+
typedef vector<LL> VL;
78+
typedef vector<PLL> VLL;
79+
typedef vector< vector<PLL> > VVL;
80+
typedef vector<int> VI;
81+
typedef vector<PII> VII;
82+
typedef vector<vector<PII> > VVI;
83+
#define N 103
84+
85+
struct T {
86+
int t; string s; string pa;
87+
bool operator < (const T o) const {
88+
if (t == o.t) {
89+
if (s == o.s) {
90+
return pa < o.pa;
91+
}
92+
else {
93+
return s < o.s;
94+
}
95+
}
96+
else {
97+
return t < o.t;
98+
}
99+
}
100+
bool operator == (const T o) const {
101+
return t == o.t && s == o.s && pa == o.pa;
102+
}
103+
};
104+
105+
vector< vector<T> > book;
106+
vector<T> numed;
107+
bool isbook[N];
108+
vector<T> son[N];
109+
110+
vector<T> split(string s) {
111+
int cur = 0;
112+
vector<T> ret;
113+
for (int i = 0; i < s.size(); i++) {
114+
if (s[i] == '/') {
115+
if (ret.empty()) {
116+
ret.pb({0,s.substr(cur, i-cur), ""});
117+
}
118+
else {
119+
ret.pb({0,s.substr(cur, i-cur), ret.back().s});
120+
}
121+
cur = i+1;
122+
}
123+
}
124+
if (ret.empty()) {
125+
ret.pb({1,s.substr(cur, s.size()-cur), ""});
126+
}
127+
else {
128+
ret.pb({1,s.substr(cur, s.size()-cur), ret.back().s});
129+
}
130+
return ret;
131+
}
132+
133+
int getid(T s) {
134+
return lower_bound(numed.begin()+1, numed.end(), s) - numed.begin();
135+
}
136+
137+
void build() {
138+
for (auto it : book) {
139+
son[0].pb(it[0]);
140+
for (int i = 0; i < it.size()-1; i++) {
141+
int id1 = getid(it[i]);
142+
son[id1].pb(it[i+1]);
143+
}
144+
}
145+
146+
for (int i = 0; i < N; i++) {
147+
sort(all(son[i]));
148+
auto ed = unique(all(son[i]));
149+
son[i].erase(ed, son[i].end());
150+
}
151+
}
152+
153+
void numberbook() {
154+
numed.pb({0,"", ""});
155+
for (auto it : book) {
156+
for (auto it1: it) {
157+
numed.pb(it1);
158+
}
159+
}
160+
sort(numed.begin()+1, numed.end());
161+
auto ed = unique(numed.begin()+1, numed.end());
162+
numed.erase(ed, numed.end());
163+
}
164+
165+
void findbook() {
166+
for (auto it1 : book) {
167+
isbook[getid(it1.back())] = 1;
168+
}
169+
}
170+
171+
void init() {
172+
book.clear();
173+
numed.clear();
174+
memset(isbook, 0, sizeof(isbook));
175+
for (int i = 0; i < N; i++) {
176+
son[i].clear();
177+
}
178+
}
179+
180+
void print(int id, int lv) {
181+
for (int i = 0; i < lv; i++) cout << " ";
182+
cout << numed[id].s << endl;
183+
184+
if (!isbook[id]) {
185+
for (auto it : son[id]) {
186+
print(getid(it), lv+1);
187+
}
188+
}
189+
190+
}
191+
192+
int main() {
193+
freopen("a.in", "r", stdin);
194+
int kase = 0;
195+
while (1) {
196+
init();
197+
kase++;
198+
string tmp;
199+
if (!getline(cin, tmp)) {
200+
break;
201+
}
202+
book.pb(split(tmp));
203+
while (1) {
204+
getline(cin, tmp);
205+
if (tmp.size() == 1 && tmp[0] == '0') break;
206+
book.pb(split(tmp));
207+
}
208+
209+
sort(all(book));
210+
auto ed = unique(all(book));
211+
book.erase(ed, book.end());
212+
213+
numberbook();
214+
findbook();
215+
build();
216+
217+
cout << "Case " << kase << ":";
218+
print(0,-1);
219+
220+
// for (auto it : book) {
221+
// for (auto k : it) {
222+
// cout << k << '/';
223+
// }
224+
// cout << endl;
225+
// }
226+
227+
}
228+
return 0;
229+
}

0 commit comments

Comments
 (0)