• Codeforces 101173 C


    思路:

    如果所有的图形都是三角形,那么答案是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;
    }
  • 相关阅读:
    安装tomcat
    sed
    a'w'k
    dwr??
    tomcat-性能?
    windows清理命令
    markdown超链接怎么写?
    ※剑指offer系列19:二叉搜索树与双向链表
    剑指offer系列17:二叉搜索树的后序遍历序列
    剑指offer系列18:二叉树中和为某一值得路径
  • 原文地址:https://www.cnblogs.com/widsom/p/9525149.html
Copyright © 2020-2023  润新知