Skip to content

Commit

Permalink
Add 300 set, more learnset solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
enwask committed Sep 13, 2024
1 parent d3fbb66 commit fd0bed7
Show file tree
Hide file tree
Showing 64 changed files with 6,335 additions and 0 deletions.
52 changes: 52 additions & 0 deletions solutions/ucf/300/2024/p001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef vector<int> vi;

vector<string> res;
bool go(string &str, int n, int k, int i = 0) {
if (i == n) {
for (char ch : str) if (ch < 'a' || ch > 'z') return false;
return res.push_back(str), false;
}
if (sz(res) >= 10000) return true;

if (i) {
if ((int) str[i - 1] + k > (int) 'z') return false;
for (str[i] = (char) (str[i - 1] + k); str[i] <= 'z'; str[i]++) {
if (go(str, n, k, i + 1)) return true;
}
return false;
}

for (; str[0] <= 'z'; str[0]++) {
if (go(str, n, k, 1)) return true;
}
return false; // shouldn't get here
}

void solve() {
int k, n, r;
cin >> k >> n >> r, k++, r--;
string str;
rep(i, 0, n) str += 'a';
res.clear();
go(str, n, k);
sort(all(res)); // don't need this but it makes me feel better
cout << res[r] << "\n";
}

int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);

int t = 1;
cin >> t;
while (t--) solve();

return 0;
}
109 changes: 109 additions & 0 deletions solutions/ucf/300/2024/p002.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

const ld pi = acos(-1);
void solve() {
int c, n;
cin >> c >> n;
vi rads(c);
for (int &rad : rads) cin >> rad;
vector<vector<pair<ld, int>>> pts(c); // [circle_index] = {{angle, node index}}
vector<vector<pair<int, ld>>> adj(2 * n + 2); // {v, w}
rep(i, 0, n) {
int id = 2 * (i + 1);
int d, tmp;
cin >> d >> tmp, d--;

ld th = (tmp % 360) * pi / 180.l;
pts[d].emplace_back(th, id);
pts[d + 1].emplace_back(th, id + 1);

adj[id].emplace_back(id + 1, rads[d + 1] - rads[d]);
adj[id + 1].emplace_back(id, rads[d + 1] - rads[d]);
}

int sc, sa, fc, fa;
cin >> sc >> sa >> fc >> fa, sc--, fc--;
ld th1 = (sa % 360) * pi / 180.l;
ld th2 = (fa % 360) * pi / 180.l;
pts[sc].emplace_back(th1, 0);
pts[fc].emplace_back(th2, 1);

// int i = 0;
// cout << "\n";
// for (auto &vec : pts) {
// cout << "i = " << i++ << " {\n";
// for (auto &[th, id] : vec) {
// cout << "\t" << id << " @ " << th << "\n";
// }
// cout << "}\n";
// }

rep(i, 0, c) {
auto &vec = pts[i];
sort(all(vec));

int m = sz(vec);
if (m <= 1) continue;

rep(j, 0, m) {
if (m == 2 && j == m - 1) break; // skip duplicate edges with m=2
auto [th_u, u] = vec[j];
auto [th_v, v] = vec[(j + 1) % m];

ld delta = abs(th_v - th_u);
if (delta > pi) delta = 2 * pi - delta;
// cout << u << "->" << v << " delta = " << delta << "\n";
ld w = delta * rads[i];

adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
}

// cout << "\n";
// rep(u, 0, 2 * n + 2) {
// cout << "u = " << u << " {\n";
// for (auto [v, w] : adj[u]) {
// cout << "\t-> " << v << " = " << w << "\n";
// }
// cout << "}\n";
// }

vector<ld> dist(2 * n + 2, 1e20l);
priority_queue<pair<ld, int>, vector<pair<ld, int>>, greater<>> pq;
pq.emplace(dist[0] = 0, 0);
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
// assert(d >= 0);

if (d != dist[u]) continue;
for (auto [v, w] : adj[u]) {
if (d + w >= dist[v]) continue;
// cout << u << "->" << v << " = " << w << " : " << d + w << "\n";
pq.emplace(dist[v] = d + w, v);
}
}

cout << dist[1] << "\n";
}

int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cout << setprecision(2) << fixed;

int t = 1;
cin >> t;
while (t--) solve();

return 0;
}
54 changes: 54 additions & 0 deletions solutions/ucf/300/2024/p003_wip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

typedef bitset<20> B;
const ld eps = 1e-8;

ld go(B &bs, const vector<ld> &ps) {
if (bs.none()) return 0.l;

ld res = 0;
rep(i, 0, sz(ps)) {
if (!bs[i]) continue;
ld p0 = 1 - ps[i], p1 = ps[i];
ld p_a0 = 1, p_a1 = 1;
rep(j, 0, sz(ps)) {
if (j == i || !bs[j]) continue;
p_a0 *= 1 - ps[j], p_a1 *= ps[j];
}

int r;
ld p;
for (r = 1, p = p0 * p_a0; p > eps; r++, p *= p0 * p_a0) ; // wait what the fuck
// res +=
}
}

void solve() {
int n;
cin >> n;
vector<ld> ps(n);
for (ld &p : ps) cin >> p;

B bs;
ld res = go(bs, ps);
cout << setprecision(8) << fixed << res << "\n";
}

int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);

int t = 1;
// cin >> t;
while (t--) solve();

return 0;
}
107 changes: 107 additions & 0 deletions solutions/ucf/300/2024/p004.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

template<class T>
int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x = 0, T y = 0) : x(x), y(y) {}
bool operator<(P p) const {
return tie(x, y) < tie(p.x, p.y);
}
bool operator==(P p) const {
return tie(x, y) == tie(p.x, p.y);
}
P operator+(P p) const { return P(x + p.x, y + p.y); }
P operator-(P p) const { return P(x - p.x, y - p.y); }
P operator*(T d) const { return P(x * d, y * d); }
P operator/(T d) const { return P(x / d, y / d); }
T dot(P p) const { return x * p.x + y * p.y; }
T cross(P p) const { return x * p.y - y * p.x; }
T cross(P a, P b) const {
return (a - *this).cross(b - *this);
}
T dist2() const { return x * x + y * y; }
double dist() const { return sqrt((double) dist2()); }
// angle to x-axis in interval [-pi, pi]
double angle() const { return atan2(y, x); }
P unit() const { return *this / dist(); } // makes dist()=1
P perp() const { return P(-y, x); } // rotates +90 degrees
P normal() const { return perp().unit(); }
// returns point rotated 'a' radians ccw around the origin
P rotate(double a) const {
return P(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a));
}
friend ostream &operator<<(ostream &os, P p) {
return os << "(" << p.x << "," << p.y << ")";
}
};
typedef Point<ll> P;
typedef Point<ld> Pd;

const ld eps = 1e-8l;
void solve() {
int n;
cin >> n;
vector<P> pts(n);
for (auto &[x, y] : pts) cin >> x >> y;
cout << setprecision(8) << fixed;

ll A2 = 0, A2l = 0;
rep(i, 2, n) A2 += pts[0].cross(pts[i - 1], pts[i]);
// cout << "A2 = " << A2 << "\n";
int l = 1;
for (; l < n - 1; l++) {
ll A2ln = A2l + pts[0].cross(pts[l], pts[l + 1]);
// cout << "A2ln = " << A2ln << "\n";
// if (A2ln * 2 == A2)
// return void(cout << pts[l + 1].x << " "
// << pts[l + 1].y << "\n");
if (A2ln * 2 > A2) {
l++;
break;
}
A2l = A2ln;
}
l--;
// cout << "l = " << l << "\n";

ld tgt = A2 / 2.l - A2l;
// cout << "tgt = " << tgt << "\n";
Pd p{(ld) pts[0].x, (ld) pts[0].y},
lo{(ld) pts[l].x, (ld) pts[l].y},
hi{(ld) pts[l + 1].x, (ld) pts[l + 1].y},
mp, a{lo.x, lo.y};
rep(_, 0, 50) {
mp = lo + (hi - lo) * .5l;

ld A = p.cross(a, mp);
// cout << "A = " << A << "\n";
// cout << "A2tri = " << (A2l + A2tri) * 2 << "\n";

if (abs(A - tgt) < eps) break;
if (A > tgt) hi = mp;
else lo = mp;
}
cout << mp.x << " " << mp.y << "\n";
}

int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);

int t = 1;
// cin >> t;
while (t--) solve();

return 0;
}
Loading

0 comments on commit fd0bed7

Please sign in to comment.