Codeforces 101173 C - Convex Contour
Posted widsom
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 101173 C - Convex Contour相关的知识,希望对你有一定的参考价值。
思路:
如果所有的图形都是三角形,那么答案是2*n+1
否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的
我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分
如果最左边或最由边是正方形,那么不需要删
如果最左边或最由边是圆形,那么删取2 - pi/2
如果如果最左边或最由边是三角形,那么我们需要找到一段连续的三角形,然后考虑怎么删去
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pii pair<int, int> #define piii pair<pii, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head int main() { fio; int n; string s; cin >> n; cin >> s; bool f = true; for (int i = 0; i < n; i++) if(s[i] != ‘T‘) f = false; if(f) { cout << 2*n + 1 << endl; } else { double ans = 2*n + 2; if(s[0] == ‘T‘) { int x = 1; for (int i = 1; i < n; i++) { if(s[i] == ‘T‘) { x++; } else if(s[i] == ‘C‘){ double tot = x + 0.5; double t = sqrt((sqrt(3)/2 - 0.5)*(sqrt(3)/2 - 0.5) + x*x - 0.25); tot -= t; double a = atan((sqrt(3)/2 - 0.5) / x); double b = atan(t*2); double c = pi/2 -a - b; tot -= c*0.5; ans -= tot; break; } else if(s[i] == ‘S‘) { double tot = x; double t = sqrt((1-sqrt(3)/2)*(1-sqrt(3)/2) + (x-0.5) * (x-0.5)); tot -= t; ans -= tot; break; } } } else if(s[0] == ‘C‘) { ans -= 2 - pi/2; } reverse(s.begin(), s.end()); if(s[0] == ‘T‘) { int x = 1; for (int i = 1; i < n; i++) { if(s[i] == ‘T‘) { x++; } else if(s[i] == ‘C‘){ double tot = x + 0.5; double t = sqrt((sqrt(3)/2 - 0.5)*(sqrt(3)/2 - 0.5) + x*x - 0.25); tot -= t; double a = atan((sqrt(3)/2 - 0.5) / x); double b = atan(t*2); double c = pi/2 -a - b; tot -= c*0.5; ans -= tot; break; } else if(s[i] == ‘S‘) { double tot = x; double t = sqrt((1-sqrt(3)/2)*(1-sqrt(3)/2) + (x-0.5) * (x-0.5)); tot -= t; ans -= tot; break; } } } else if(s[0] == ‘C‘) { ans -= 2 - pi/2; } cout << fixed << setprecision(9) << ans << endl; } return 0; }
以上是关于Codeforces 101173 C - Convex Contour的主要内容,如果未能解决你的问题,请参考以下文章
CodeforcesGym 101173B Bipartite Blanket 霍尔定理+状压DP
GYM 101173 F.Free Figurines(贪心||并查集)
Gym - 101173H Hangar Hurdles(bfs+克鲁斯卡尔重构树)