zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    CC++ 文件操作
    loadrunner之Paramater在负载测试中的数据生成规则
    loadrunner关联及web_reg_save_param方法浅析
    mysql union 与 union all 语法及用法
    sql 语句中as的用法和作用
    数据库主从复制和读写分离
    《剑指offer》算法题第十二天
    《剑指offer》算法题第十一天
    《剑指offer》算法题第十天
    《剑指offer》算法题第九天
  • 原文地址:https://www.cnblogs.com/widsom/p/9525149.html
Copyright © 2011-2022 走看看