Skip to content

Commit 628dd31

Browse files
committed
Adding & Formatting
Checkpoints & Answers of V-Ball, MagicCircle and FlingLikFullOfVim added
1 parent 93e0bed commit 628dd31

Some content is hidden

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

67 files changed

+405382
-37
lines changed

Answers/FlingLikFullOfVim.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// main.cpp
3+
// FlingLikFullOfVim
4+
//
5+
// Created by Robert He on 2024/11/13.
6+
//
7+
8+
#include<cstdio>
9+
#include<cstring>
10+
#include<algorithm>
11+
12+
const int M=77777,K=11;
13+
const int inf=1e9+7;
14+
15+
void gmin(int &A,int B){A=std::min(A,B);}
16+
17+
int n,len,cnt_e,s[M];
18+
char str[M];
19+
bool key[M];
20+
21+
int f[M][K],g[M][K][K];
22+
23+
int main(){
24+
scanf("%d",&len);
25+
scanf(" %s",str+1);
26+
27+
bool flag=true;
28+
for(int i=1;i<=len;i++){
29+
if(str[i]=='e'){
30+
flag=true;
31+
cnt_e++;
32+
} else {
33+
key[++n]=flag;
34+
s[n]=str[i]-'a';
35+
flag=false;
36+
}
37+
}
38+
for(int i=0;i<=n;i++)
39+
for(int x=0;x<K;x++) f[i][x]=inf;
40+
for(int i=0;i<=n;i++)
41+
for(int x=0;x<K;x++)
42+
for(int y=0;y<K;y++) g[i][x][y]=inf;
43+
f[0][s[1]]=0;
44+
for(int i=1;i<=n;i++){
45+
// f -> f
46+
for(int x=0;x<K;x++){
47+
if(!key[i]&&x!=s[i]) gmin(f[i][x],f[i-1][x]);
48+
gmin(f[i][x],f[i-1][s[i]]+2);
49+
}
50+
51+
// f -> g
52+
for(int x=0;x<K;x++)
53+
for(int y=0;y<K;y++){
54+
if(x!=s[i]) gmin(g[i][x][y],f[i-1][x]+3);
55+
gmin(g[i][x][y],f[i-1][s[i]]+5);
56+
}
57+
58+
// g -> f
59+
for(int x=0;x<K;x++){
60+
if(x!=s[i]) gmin(f[i][x],g[i-1][s[i]][x]);
61+
gmin(f[i][x],g[i-1][s[i]][s[i]]+2);
62+
}
63+
64+
// g -> g
65+
for(int x=0;x<K;x++)
66+
for(int y=0;y<K;y++){
67+
if(x!=s[i]&&y!=s[i]) gmin(g[i][x][y],g[i-1][x][y]+1);
68+
if(y!=s[i]) gmin(g[i][x][y],g[i-1][s[i]][y]+3);
69+
if(x!=s[i]) gmin(g[i][x][y],g[i-1][x][s[i]]+3);
70+
gmin(g[i][x][y],g[i-1][s[i]][s[i]]+5);
71+
}
72+
}
73+
printf("%d\n",f[n][10]-2+2*cnt_e);
74+
return 0;
75+
}

Answers/MagicCircle.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// MagicCircle.cpp
3+
// AngryCodeProposition2024
4+
//
5+
// Created by Robert He on 2024/11/16.
6+
//
7+
8+
#include <algorithm>
9+
#include <iostream>
10+
using namespace std;
11+
#define il inline
12+
#define re register
13+
#define D double
14+
15+
il int read() {
16+
re int x = 0, f = 1;
17+
re char c = getchar();
18+
while (c < '0' || c > '9') {
19+
if (c == '-')
20+
f = -1;
21+
c = getchar();
22+
}
23+
while (c >= '0' && c <= '9') {
24+
x = x * 10 + c - 48;
25+
c = getchar();
26+
}
27+
return x * f;
28+
}
29+
30+
#define rep(i, s, t) for (re int i = s; i <= t; ++i)
31+
#define eps 1e-12
32+
#define maxn 100005
33+
#define ff(x) (x) * (x)
34+
int n, m;
35+
D r;
36+
37+
struct node {
38+
D x, y;
39+
} o, e[maxn];
40+
il D dis(node a, node b) { return sqrt(ff(a.x - b.x) + ff(a.y - b.y)); }
41+
42+
il void get(node a, node b, node c) {
43+
D a1 = b.x - a.x, a2 = c.x - a.x, b1 = b.y - a.y, b2 = c.y - a.y;
44+
D c1 = (ff(b.x) - ff(a.x) + ff(b.y) - ff(a.y));
45+
D c2 = (ff(c.x) - ff(a.x) + ff(c.y) - ff(a.y));
46+
o = (node){(b2 * c1 - b1 * c2) / (b2 * a1 * 2 - b1 * a2 * 2),
47+
(a2 * c1 - a1 * c2) / (a2 * b1 * 2 - a1 * b2 * 2)};
48+
r = dis(a, o);
49+
}
50+
51+
il void work() {
52+
o = e[1];
53+
r = 0;
54+
rep(i, 2, n) {
55+
if (dis(o, e[i]) > r + eps) {
56+
o = e[i];
57+
r = 0;
58+
rep(j, 1, i - 1) {
59+
if (dis(o, e[j]) > r + eps) {
60+
o.x = (e[i].x + e[j].x) / 2;
61+
o.y = (e[i].y + e[j].y) / 2;
62+
r = dis(o, e[j]);
63+
rep(k, 1, j - 1) if (dis(o, e[k]) > r + eps) get(e[i], e[j], e[k]);
64+
}
65+
}
66+
}
67+
// printf("%.10lf\n%.10lf %.10lf\n", r, o.x, o.y);
68+
}
69+
}
70+
71+
int main() {
72+
n = read();
73+
rep(i, 1, n) scanf("%lf%lf", &e[i].x, &e[i].y);
74+
random_shuffle(e + 1, e + n + 1);
75+
work();
76+
printf("%.10lf\n%.10lf %.10lf", r, o.x, o.y);
77+
78+
return 0;
79+
}

Answers/V-Ball.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//
2+
// main.cpp
3+
// V-Ball
4+
//
5+
// Created by Robert He on 2024/11/12.
6+
//
7+
8+
#include <cstdio>
9+
#include <cstring>
10+
#include <iostream>
11+
using namespace std;
12+
using namespace chrono;
13+
14+
const double Maxn = 1e9;
15+
const int N = 205, M = 8e4 + 5;
16+
const double eps = 1e-8;
17+
int pre[N], nxt[M], to[M], lst[N], fr[M], flw[M], Q[M];
18+
int n, s, t, T;
19+
bool vis[N];
20+
double a[N][N], b[N][N], cst[M], Ans, dis[N];
21+
22+
template <class T>
23+
inline void CkMin(T &a, const T b) {
24+
if (a > b)
25+
a = b;
26+
}
27+
inline void Add(const int x, const int y, const int z, const double g) {
28+
nxt[++T] = lst[x];
29+
lst[x] = T;
30+
to[T] = y;
31+
fr[T] = x;
32+
flw[T] = z;
33+
cst[T] = g;
34+
nxt[++T] = lst[y];
35+
lst[y] = T;
36+
to[T] = x;
37+
fr[T] = y;
38+
flw[T] = 0;
39+
cst[T] = -g;
40+
}
41+
inline bool Bul() {
42+
for (int i = s; i <= t; ++i)
43+
dis[i] = -Maxn;
44+
int te = 0, we = 1, x, y;
45+
dis[Q[1] = s] = 0.0;
46+
while (te < we) {
47+
x = Q[++te];
48+
vis[x] = false;
49+
for (int i = lst[x]; i; i = nxt[i])
50+
if (dis[y = to[i]] < dis[x] + cst[i] && flw[i]) {
51+
dis[y] = dis[x] + cst[i];
52+
pre[y] = i;
53+
if (!vis[y]) {
54+
vis[y] = true;
55+
Q[++we] = y;
56+
}
57+
}
58+
}
59+
return dis[t] > -Maxn;
60+
}
61+
inline void Deal() {
62+
int Mif = Maxn;
63+
for (int i = pre[t]; i; i = pre[fr[i]])
64+
CkMin(Mif, flw[i]);
65+
for (int i = pre[t]; i; i = pre[fr[i]]) {
66+
flw[i] -= Mif;
67+
flw[i ^ 1] += Mif;
68+
Ans += (double)Mif * cst[i];
69+
}
70+
}
71+
inline bool check(const double mi) {
72+
T = 1;
73+
memset(lst, 0, sizeof(lst));
74+
for (int i = 1; i <= n; ++i)
75+
Add(s, i, 1, 0), Add(i + n, t, 1, 0);
76+
for (int i = 1; i <= n; ++i)
77+
for (int j = 1; j <= n; ++j)
78+
Add(i, j + n, 1, a[i][j] - mi * b[i][j]);
79+
Ans = 0.0;
80+
while (Bul())
81+
Deal();
82+
return (Ans <= 0);
83+
}
84+
85+
int main() {
86+
scanf("%d", &n);
87+
s = 0;
88+
t = (n << 1) + 1;
89+
90+
for (int i = 1; i <= n; ++i)
91+
for (int j = 1; j <= n; ++j)
92+
scanf("%lf", &a[i][j]);
93+
94+
for (int i = 1; i <= n; ++i)
95+
for (int j = 1; j <= n; ++j)
96+
scanf("%lf", &b[i][j]);
97+
98+
double l = 0, r = 1e4;
99+
while (r - l >= eps) {
100+
double mid = (l + r) / 2;
101+
(check(mid) ? r : l) = mid;
102+
}
103+
104+
105+
106+
printf("%.6lf\n", l);
107+
108+
return 0;
109+
}

Checkpoints/FlingLikFullOfVim/1.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
decedbeeea
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
15

Checkpoints/FlingLikFullOfVim/10.in

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
36423

Checkpoints/FlingLikFullOfVim/2.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
50
2+
fdeeebcedefegegefbegeiagaedejejaceeegejebdaecbjeeh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
67

Checkpoints/FlingLikFullOfVim/3.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
100
2+
ccbdficdcaeaecgejchceeedcgfjchediaefjfdaechfjagcighadjeajhffdjeiedbafeaacjbihffgggdbacajbcggcfaaeidb

0 commit comments

Comments
 (0)