2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest[6/12]
2019-03-18 22:34
197 查看
版权声明:CopyRight@2018 BPM136 https://blog.csdn.net/qq_20139423/article/details/88651970
A
温暖签到
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int x, ans = 0; for (int j = 1; j <= 4; ++j) { cin >> x; if (x > 0) ++ans; } if (ans == 0) puts("Typically Otaku"); if (ans == 1) puts("Eye-opener"); if (ans == 2) puts("Young Traveller"); if (ans == 3) puts("Excellent Traveller"); if (ans == 4) puts("Contemporary Xu Xiake"); } }
B
待补
C
upsolved
对x和y分别排序然后维护左边和右边分别被合并的区间,因为答案只可能出现在角落,所以就可以四个ans来维护(比赛的时候没看到每行每列只有一个这句话写死我了)
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace fastIO{ #define BUF_SIZE 100000 #define OUT_SIZE 100000 //fread->read bool IOerror=0; inline char nc(){ static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; if (p1==pend){ p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); if (pend==p1){IOerror=1;return -1;} //{printf("IO error!\n");system("pause");for (;;);exit(0);} } return *p1++; } inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;} inline bool enter(char ch){return ch==10||ch==13;} inline void read(int &x){ bool sign=0; char ch=nc(); x=0; for (;blank(ch);ch=nc()); if (IOerror)return; if (ch==45)sign=1,ch=nc(); for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48; if (sign)x=-x; } inline void read(ll &x){ bool sign=0; char ch=nc(); x=0; for (;blank(ch);ch=nc()); if (IOerror)return; if (ch==45)sign=1,ch=nc(); for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48; if (sign)x=-x; } inline void read(double &x){ bool sign=0; char ch=nc(); x=0; for (;blank(ch);ch=nc()); if (IOerror)return; if (ch==45)sign=1,ch=nc(); for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48; if (ch==46){ double tmp=1; ch=nc(); for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48); } if (sign)x=-x; } inline void read(char *s){ char ch=nc(); for (;blank(ch);ch=nc()); if (IOerror)return; for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch; *s=0; }< 1aa6f /span> inline void readln(char *s) { char ch=nc(); for (;blank(ch);ch=nc()); if(IOerror)return; for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch; *s=0; } inline void read(char &c){ for (c=nc();blank(c);c=nc()); if (IOerror){c=-1;return;} } #undef OUT_SIZE #undef BUF_SIZE } using fastIO::read; int const N = 300005; struct node { int x, y, id; }; vector<node> detx, dety; int ans1, ans2, ans3, ans4; int lx, rx, ly, ry; int xmi, xma, ymi, yma; int dx, dy; int mark[N]; int n, m; void setpn(node a, int val) { if (mark[a.id] == 0) { mark[a.id] = val; return; } int& t = mark[a.id]; if (t == 1) { if (val == 3) ++ans1; if (val == 4) ++ans3; } if (t == 2) { if (val == 3) ++ans2; if (val == 4) ++ans4; if (val == 1) t = val; } if (t == 3) { if (val == 1) ++ans1; if (val == 2) ++ans2; } if (t == 4) { if (val == 1) ++ans3; if (val == 2) ++ans4; if (val == 3) t = val; } } void init(vector<node>& t) { for (int i = 0; i < n; ++i) mark[i] = 0; ans1 = ans2 = ans3 = ans4 = 0; dx = dy = 0; detx = t; dety = t; sort(detx.begin(), detx.end(), [] (node const& a, node const& b) { return a.x < b.x; }); sort(dety.begin(), dety.end(), [] (node const& a, node const& b) { return a.y < b.y; }); lx = 0, rx = n - 1; setpn(detx[0], 3); setpn(detx[n - 1], 4); xmi = detx[0].x; xma = detx[n - 1].x; ly = 0, ry = n - 1; setpn(dety[0], 1); setpn(dety[n - 1], 2); ymi = dety[0].y; yma = dety[n - 1].y; } void moveL(int step) { dy -= step; ymi = max(1, ymi - step); yma = max(1, yma - step); while (ly < ry && dety[ly + 1].y + dy <= ymi) { ++ly; if (ly == ry) return; setpn(dety[ly], 1); } } void moveR(int step) { dy += step; ymi = min(n, ymi + step); yma = min(n, yma + step); while (ly < ry && dety[ry - 1].y + dy >= yma) { --ry; if (ly == ry) return; setpn(dety[ry], 2); } } void moveU(int step) { dx -= step; xmi = max(1, xmi - step); xma = max(1, xma - step); while (lx < rx && detx[lx + 1].x + dx <= xmi) { ++lx; if (lx == rx) return; setpn(detx[lx], 3); } } void moveD(int step) { dx += step; xmi = min(n, xmi + step); xma = min(n, xma + step); while (lx < rx && detx[rx - 1].x + dx >= xma) { --rx; if (lx == rx) return; setpn(detx[rx], 4); } } int query(int const& x, int& mi, int& ma, int d) { if (x + d <= mi) return mi; if (x + d >= ma) return ma; return x + d; } long long C(int x) { return (long long) x * (x - 1) / 2; } long long QueryAns() { if (n == 1) return 0; if (xmi == xma && ymi == yma) return C(ans1 + ans2 + ans3 + ans4); if (xmi == xma) return C(ans1 + ans3) + C(ans2 + ans4); if (ymi == yma) return C(ans1 + ans2) + C(ans3 + ans4); return C(ans1) + C(ans2) + C(ans3) + C(ans4); } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); ios::sync_with_stdio(0); int T; read(T); while (T--) { read(n); read(m); auto a = vector<node>(n); for (int i = 0; i < n; ++i) { read(a[i].x); read(a[i].y); a[i].id = i; } init(a); ///////////////////// // cerr << "MARK : "; // for (int i = 0; i < n; ++i) // cerr << mark[i] << ' '; // cerr << '\n'; for (int o = 0; o < m; ++o) { char op; int x; read(op); if (op != '!') read(x); switch(op) { case 'L': moveL(x); break; case 'R': moveR(x); break; case 'U': moveU(x); break; case 'D': moveD(x); break; case '?': { int px = query(a[x - 1].x, xmi, xma, dx); int py = query(a[x - 1].y, ymi, yma, dy); cout << px << ' ' << py << '\n'; } break; default : cout << QueryAns() << '\n'; } } } }
D
pypy的小数居然是float,交Python就能过,这里提供相同的C++代码
#include <bits/stdc++.h> using namespace std; double const PI = acos(-1.0); double sqr(double x) { return x * x; } double calc(double a, double b, double r, double th) { th = th / 180.0 * PI; double l = sqrt(sqr(a + r) + sqr(b)); double th0 = atan(b / (a + r)); return l * cos(max(th0 - th, 0.0)) - r; } int main() { int T; cin >> T; while (T--) { double a, b, r, th; cin >> a >> b >> r >> th; double ans = calc(a, b, r, th); cout << fixed << setprecision(12) << ans << '\n'; } }
E
from math import gcd def primes(mx): ret = [] for i in range(2, mx): if all(i % p != 0 for p in ret): ret.append(i) return ret def select(ps, n): cur, xs = 1, [] for p in ps: if cur * p > n: return cur, xs cur *= p xs.append(p) def calc(n, ps): a, qs = select(ps, n) b = 1 for q in qs: b *= q + 1 g = gcd(a, b) return a // g, b // g def main(): ps = primes(300) for _ in range(int(input())): n = int(input()) a, b = calc(n, ps) print(f'{a}/{b}') main()
F
bfs
#include <iostream> #include <string> #include <queue> #include <utility> #include <algorithm> using Edges = std::vector<std::vector<int>>; int bfs(int n, const Edges &es, int ibeg, int iend) { const int INF = 1000 * 1000 + 10; auto q = std::queue<int>(); auto dis = std::vector<int>(n, INF); q.push(ibeg); dis[ibeg] = 0; while(!q.empty()) { int c = q.front(); q.pop(); if(c == iend) return 1 + dis[c]; for(int to: es[c]) if(dis[to] == INF) { dis[to] = dis[c] + 1; q.push(to); } } return -1; } int main() { std::ios::sync_with_stdio(false); int t; std::cin >> t; while(t--) { int r, c; std::cin >> r >> c; std::cin.get(); // Eat space. int n = r * c, ibeg, iend; std::vector<std::string> inp; for(int i = 0; i < 4 * r + 3; ++i) { std::string s; std::getline(std::cin, s); inp.push_back(std::move(s)); } auto es = Edges(n); auto adde = [&](int x1, int y1, int x2, int y2) { es[x1 * c + y1].push_back(x2 * c + y2); es[x2 * c + y2].push_back(x1 * c + y1); }; for(int i = 0; i < r; ++i) for(int j = 0; j < c; ++j) { int x = (j & 1 ? 4 : 2) + i * 4, y = 4 + j * 6; if(inp[x][y] == 'S') ibeg = i * c + j; if(inp[x][y] == 'T') iend = i * c + j; if(inp[x + 2][y] == ' ') adde(i, j, i + 1, j); if(inp[x + 1][y + 3] == ' ') { if(j & 1) adde(i, j, i + 1, j + 1); else adde(i, j, i, j + 1); } if(inp[x - 1][y + 3] == ' ') { if(j & 1) adde(i, j, i, j + 1); else adde(i, j, i - 1, j + 1); } } int ans = bfs(n, es, ibeg, iend); std::cout << ans << '\n'; } return 0; }
I
贪心取两边即可
#include<iostream> using namespace std; long long a[100010]; int main() { int t,n; cin>>t; while(t--) { long long ans=0,sum=0; cin>>n; for(int i=1;i<n;i++)cin>>a[i]; for(int i=1;i<n;i++)a[i]+=a[i-1]; for(int i=1;i<=n;i++) { if(i&1)ans+=sum; else sum+=a[n-i/2]-a[i/2-1],ans+=sum; cout<<ans; if(n!=i)cout<<" "; } cout<<endl; } }
相关文章推荐
- 2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest F. Honeycomb
- 2018-2019 ACM-ICPC, Asia Shenyang Regional Contest 一些题解
- 2018-2019 ACM-ICPC, Asia Nanjing Regional Contest 一些题解
- The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online(四题签到)
- 「备战PKUWC2018」2017-2018 ACM-ICPC, Asia Daejeon Regional Contest
- The 2018 ACM-ICPC Asia Beijing Regional Contest 一些题解
- 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest 一些题解
- The 2018 ACM-ICPC Asia Qingdao Regional Contest(部分题解)
- The 2016 ACM-ICPC Asia Dalian Regional Contest 一些题解
- 2014-2015 ACM-ICPC, Asia Tokyo Regional Contest G題 (线段树区间更新)
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest H. Palindromic Cut
- Codeforces GYM 100548 F - Color 2014-2015 ACM-ICPC, Asia Xian Regional Contest
- The 2013 ACM-ICPC Asia Changsha Regional Contest C Zoj Collision
- The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest(HDU4021-4030)
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1) F.Move Away 几何
- The 2011 ACM-ICPC Asia Dalian Regional Contest——D Hexadecimal View
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1) J.Treasure Map dp
- hdu 5045 Contest dp+状态压缩 2014 ACM/ICPC Asia Regional Shanghai Online
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest【solved :8 / 12 】
- ZOJ 3822 Domination / The 2014 ACM-ICPC Asia Mudanjiang Regional Contest