2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest
2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest
https://codeforces.com/gym/102028
2020-12-11 --时间
-
A.
- 签到
const int maxn = 1e5 + 7; int t, n; char s[10][1000] = {"Typically Otaku", "Eye-opener", "Young Traveller", "Excellent Traveller", "Contemporary Xu Xiake"}; void solve() { cin >> t; while (t--) { int cnt = 0; for (int i = 1; i <= 4; i++) { cin >> n; if (n) cnt++; } cout << s[cnt] << endl; } }
- 签到
-
I.
- 贪心+前缀和
const int maxn = 1e5 + 7; int t, n; ll a[maxn], pre[maxn], sum; void solve() { cin >> t; while (t--) { cin >> n; pre[1] = 0; for (int i = 1; i < n; i++) cin >> a[i], pre[i] = a[i] + pre[i - 1]; ll lasum = 0, ad = 0; for (int k = 1; k <= n; k++) { if (k % 2 == 0) ad += pre[n - k / 2] - pre[k / 2 - 1]; lasum += ad; if (k != n) cout << lasum << " "; else cout << lasum << endl; } } }
- 贪心+前缀和
-
D.计算几何
- 相似三角,计算时避免使用 arctan,还有就是a > b 改成 a > b - esp
-
const int maxn = 1e5 + 7; int t, n; const long double pi = acos(-1); void solve() { cin >> t; while (t--) { long double a, b, r, d; cin >> a >> b >> r >> d; long double len = sqrt((r + a) * (r + a) + b * b); long double tand = acos((a + r) / len); d = d / 180 * pi; if (d >= tand || fabs(d - tand) < 1e-6) cout << fixed << setprecision(13) << len - r << endl; else { long double B = a + r, A = tan(d) * B, C = B / cos(d); long double c0 = b - A, a0 = c0 * sin(d); cout << fixed << setprecision(13) << a0 + C - r << endl; } } }
-
E.大数+素数
- 计算前60个素数组成所有集合的倒数和,推下公式打表写.不然会tle
- tle代码:
#include <bits/stdc++.h> #define ll long long using namespace std; #ifndef ONLINE_JUDGE clock_t prostart = clock(); #endif const int maxn = 1e4 + 7; struct Wint : vector<int> { Wint(int n = 0) { push_back(n); check(); } Wint &check() { while (!empty() && !back()) pop_back(); if (empty()) return *this; for (int i = 1; i < size(); ++i) { (*this)[i] += (*this)[i - 1] / 10; (*this)[i - 1] %= 10; } while (back() >= 10) { push_back(back() / 10); (*this)[size() - 2] %= 10; } return *this; } }; istream &operator>>(istream &is, Wint &n) { string s; is >> s; n.clear(); for (int i = s.size() - 1; i >= 0; --i) n.push_back(s[i] - '0'); return is; } ostream &operator<<(ostream &os, const Wint &n) { if (n.empty()) os << 0; for (int i = n.size() - 1; i >= 0; --i) os << n[i]; return os; } bool operator!=(const Wint &a, const Wint &b) { if (a.size() != b.size()) return 1; for (int i = a.size() - 1; i >= 0; --i) if (a[i] != b[i]) return 1; return 0; } bool operator==(const Wint &a, const Wint &b) { return !(a != b); } bool operator<(const Wint &a, const Wint &b) { if (a.size() != b.size()) return a.size() < b.size(); for (int i = a.size() - 1; i >= 0; --i) if (a[i] != b[i]) return a[i] < b[i]; return 0; } bool operator>(const Wint &a, const Wint &b) { return b < a; } bool operator<=(const Wint &a, const Wint &b) { return !(a > b); } bool operator>=(const Wint &a, const Wint &b) { return !(a < b); } Wint &operator+=(Wint &a, const Wint &b) { if (a.size() < b.size()) a.resize(b.size()); for (int i = 0; i != b.size(); ++i) a[i] += b[i]; return a.check(); } Wint operator+(Wint a, const Wint &b) { return a += b; } Wint &operator-=(Wint &a, Wint b) { if (a < b) swap(a, b); for (int i = 0; i != b.size(); a[i] -= b[i], ++i) if (a[i] < b[i]) { int j = i + 1; while (!a[j]) ++j; while (j > i) { --a[j]; a[--j] += 10; } } return a.check(); } Wint operator-(Wint a, const Wint &b) { return a -= b; } Wint operator*(const Wint &a, const Wint &b) { Wint n; n.assign(a.size() + b.size() - 1, 0); for (int i = 0; i != a.size(); ++i) for (int j = 0; j != b.size(); ++j) n[i + j] += a[i] * b[j]; return n.check(); } Wint &operator*=(Wint &a, const Wint &b) { return a = a * b; } Wint divmod(Wint &a, const Wint &b) { Wint ans; for (int t = a.size() - b.size(); a >= b; --t) { Wint d; d.assign(t + 1, 0); d.back() = 1; Wint c = b * d; while (a >= c) { a -= c; ans += d; } } return ans; } Wint operator/(Wint a, const Wint &b) { return divmod(a, b); } Wint &operator/=(Wint &a, const Wint &b) { return a = a / b; } Wint &operator%=(Wint &a, const Wint &b) { divmod(a, b); return a; } Wint operator%(Wint a, const Wint &b) { return a %= b; } Wint pow(const Wint &n, const Wint &k) { if (k.empty()) return 1; if (k == 2) return n * n; if (k.back() % 2) return n * pow(n, k - 1); return pow(pow(n, k / 2), 2); } void solve(); void files() { #ifndef ONLINE_JUDGE freopen("../data.in", "r", stdin); freopen("../data.out", "w", stdout); #endif solve(); #ifndef ONLINE_JUDGE cout << "运行时间:" << 1.0 * (clock() - prostart) << "ms" << "\n"; #endif } ll p[maxn], tot; //* p[0] = 2,p[1] = 3... tot为素数个数 bool vis[maxn]; //* vis[i] == 0 -> i为素数 void init(int n = maxn - 1) // 1e7 -> 125ms { for (int i = 2; i <= n; i++) { if (!vis[i]) p[tot++] = i; for (int j = 0; j < tot; j++) { if (p[j] * i > n) break; vis[p[j] * i] = 1; if (i % p[j] == 0) break; } } } int main() { files(); } int t; Wint gcd(Wint a, Wint b) { if (a % b == 0) return b; return gcd(b, a % b); } pair<Wint, Wint> add(pair<Wint, Wint> p1, pair<Wint, Wint> p2) { pair<Wint, Wint> res; Wint fz = p1.first * p2.second + p1.second * p2.first; Wint fm = p1.second * p2.second; Wint gc = gcd(fz, fm); res.first = fz / gc, res.second = fm / gc; return res; } void solve() { Wint n; cin >> t; init(); while (t--) { cin >> n; Wint base = 1; int pl = 0; for (int i = 0; base * p[i] <= n; i++, pl++) base *= p[i]; Wint fz = 0; pair<Wint, Wint> now = {0, 1}, la; for (int i = 0; i < pl; i++) { la = now; now.second *= p[i]; now = add(now, {1, p[i]}); now = add(now, la); } now = add(now, {1, 1}); cout << now.second << '/' << now.first << endl; } } - 打表代码
string res[100] = { "1/1", "2/3", "1/2", "5/12", "35/96", "385/1152", "715/2304", "12155/41472", "46189/165888", "1062347/3981312", "30808063/119439360", "955049953/3822059520", "1859834119/7644119040", "76253198879/321052999680", "298080686527/1284211998720", "14009792266769/61642175938560", "742518990138757/3328677500682240", "43808620418186663/199720650040934400", "86204059532560853/399441300081868800", "339745411098916303/1597765200327475200", "24121924188023057513/115039094423578214400", "47591904479072518877/230078188847156428800", "3759760453846728991283/18406255107772514304000", "312060117669278506276489/1546125429052891201536000", "27773350472565787058607521/139151288614760208138240000", "2694014995838881344684929537/13636826284246500397547520000", "272095514579727015813177883237/1390956280993143040549847040000", "2155833692439375586827486305647/11127650247945144324398776320000", "230674205091013187790541034704229/1201786226778075587035067842560000", "25143488354920437469168972782760961/132196484945588314573857462681600000", "2841214184106009434016093924451988593/15070399283797067861419750745702400000", "360834201381463198120043928405402551311/1929011108326024686261728095449907200000", "47269280380971678953725754621107734221741/254629466299035258586548108599387750400000", "281560496182309565941757755786598242972979/1527776797794211551519288651596326502400000", "39136908969341029665904328054337155773244081/213888751691189617212700411223485710336000000", "5831399436431813420219744880096236210213368069/32083312753678442581905061683522856550400000000", "880541314901203826453181476894531667742218578419/4876663538559123272449569375895474195660800000000", "1749936537208721528520879643954955339690231858377/9753327077118246544899138751790948391321600000000", "6957064769878575832900082486942871228524580315011/39013308308472986179596555007163793565286400000000", "1161829816569722164094313775319459495163604912606837/6554235795823461678172221241203517318968115200000000", "6930915802295239116838492521733327333217367237275269/39325414774940770069033327447221103913808691200000000", "1240633928610847801914090161390265592645908735472273151/7078574659489338612425998940499798704485564416000000000", "224554741078563452146450319211638072268909481120481440331/1288300588027059627461531807170963364216372723712000000000", "42889955546005619359972010969422871803361710894011955103221/247353712901195448472614106976824965929543562952704000000000", "85337746601846232334789671310294992351018661881900075617749/494707425802390896945228213953649931859087125905408000000000", "16811536080563707769953565248128113493150676390734314896696553/97952070308873397595155186362822686508099250929270784000000000", "3345495680032177846220759484377494585136984601756128664442614047/19590414061774679519031037272564537301619850185854156800000000000", "13318860160128104255709061343465119952149127376802700909384746489/78361656247098718076124149090258149206479400743416627200000000000", "2970105815708567249023120679592721749329255405027002302792798467047/17553010999350112849051809396217825422251385766525324492800000000000", "674214020165844765528248394267547837097740976941129522733965252019669/4002086507851825729583812542337664196273315954767773984358400000000000", "154395010617978451305968882287268454695382683719518660706078042712504201/920479896805919917804276884737662765142862669596588016402432000000000000", "35974037473988979154290749572933549944024165306647847944516183952013478833/215392295852585260766200791028613087043429864685601595838169088000000000000", "8597794956283366017875489147931118436621775508288835658739367964531221441087/51694151004620462583888189846867140890423167524544383001160581120000000000000", "2072068584464291210307992884651399543225847897497609393756187679452024367301967/12509984543118151945300941942941848095482406540939740686280860631040000000000000", "520089214700537093787306214047501285349687822271899957832803107542458116192793717/3152516104865774290215837369621345720061566448316814652942776879022080000000000000", "3108440190186931002403202256051344891508599309857634631698381363683993857245301983/18915096629194645741295024217728074320369398689900887917656661274132480000000000000", "817519770019162853632042193341503706466761618492557908136674298648890384455514421529/4993585510107386475701886393480211620577521254133834410261358576370974720000000000000", "219912818135154807627019350008864497039558875374498077288765386336551513418533379391301/1348268087728994348439509326239657137555930738616135290770566815620163174400000000000000", }; void solve() { Wint n; cin >> t; init(); Wint now = 1; while (t--) { cin >> n; Wint base = 1; int pl = 0; for (int i = 0; base * p[i] <= n; i++, pl++) base *= p[i]; cout << res[pl] << endl; } }
-
F.输入处理 + bfs
- 处理有点恶心,记得初始化,gets比较快
const int maxn = 1e3 + 7; int n, m; int sx, sy, ex, ey; char c[maxn << 4][maxn << 4]; int dy[] = {3, 3, -3, -3, 0, 0}, dx[] = {1, -1, 1, -1, 2, -2}; vector<int> mp[maxn * maxn]; int id[maxn << 3][maxn << 3], tot = 1; int sp[maxn * maxn]; bool vis[maxn * maxn]; void idd(int x, int y) { vis[tot] = 0; sp[tot] = 1; mp[tot].clear(); id[x][y] = tot++; } void add(int x1, int y1, int x2, int y2) { mp[id[x1][y1]].push_back(id[x2][y2]); mp[id[x2][y2]].push_back(id[x1][y1]); } void solve(int x, int y) { if (c[x][y] == 'S') sx = x, sy = y; if (c[x][y] == 'T') ex = x, ey = y; for (int i = 0; i < 6; i++) if (c[x + dx[i]][y + dy[i]] == ' ') add(x, y, x + dx[i] * 2, y + dy[i] * 2); } int bfs(int st) { queue<int> que; que.push(st); int ed = id[ex][ey]; while (que.size()) { int tp = que.front(); que.pop(); for (auto i:mp[tp]) { if (!vis[i]) { vis[i] = 1; que.push(i); sp[i] = sp[tp] + 1; } if (i == ed) return sp[i]; } } return -1; } int t; void solve() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); getchar(); tot = 1; for (int i = 1; i <= 4 * n + 3; i++) gets(c[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (j % 2) idd(4 * i - 1, j / 2 * 12 + 5); else idd(4 * i + 1, 6 * j - 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (j % 2) solve(4 * i - 1, j / 2 * 12 + 5); else solve(4 * i + 1, 6 * j - 1); printf("%d\n", bfs(id[sx][sy])); } }
- 处理有点恶心,记得初始化,gets比较快
我看见 你

浙公网安备 33010602011771号