zoukankan      html  css  js  c++  java
  • 题解报告(CDUT暑期集训——第五场)

    题解报告(CDUT暑期集训——第五场)


    B - Beautiful Now

    HDU - 6351

    • __思路:直接暴力全排列就行了 最多(10!)次 题目限制2500ms 全排列大概是2000多ms(最开始数组开的20疯狂t 结束前十几秒听到尧神说把数组开小过了就马上改了一交过了(%%尧神 时间卡的太死了( __

    • AC代码


    #include<stdio.h>
    #include<iostream>
    #include<math.h>
    #include<algorithm>
    #include<string.h>
    #include<queue>
    #include<set>
    #include<string>
    #include<sstream>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll Pow_mod(ll a, ll b, ll c){
        ll ans = 1;
        a %= c;
        while (b){
            if (b & 1) ans = (ans * a) % c;
            a = (a * a) % c;
            b >>= 1;
        }
        return (ans % c);
    }
    
    int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a % b);
    }
    
    const int N = 10;
    const int M = 20;
    const int INF = 0x3f3f3f3f;
    
    int t, k, len, init_val, ans_min, ans_max, cnt, cnt_, sum;
    int n_[N], pos[N], vis[N];
    char n[M];
    
    void init(){
        init_val = 0;
        len = strlen(n);
        for (int i = 0; i < len; i ++ ){
            n_[i] = (n[i] - '0');
            pos[i] = i;
            init_val = init_val * 10 + n_[i];
        }
        ans_min = init_val;
        ans_max = init_val;
    }
    
    bool judge(){
        memset(vis, 0, sizeof(vis));
        cnt = 0;
        for (int i = 0; i < len; i ++ ){
            if (!vis[i]){
                cnt_ = 0;
                while (!vis[i]){
                    vis[i] = 1;
                    cnt_ ++;
                    i = pos[i];
                }
                cnt += (cnt_ - 1);
            }
            if (cnt > k) return false;
        }
        return true;
    }
    
    void calc(){
        while (next_permutation(pos, pos + len)){
            if (n_[pos[0]] && judge()){
                sum = 0;
                for (int i = 0; i < len; i ++ )
                    sum = sum * 10 + n_[pos[i]];
                ans_min = min(ans_min, sum);
                ans_max = max(ans_max, sum);
            }
        }
    }
    
    int main(){
        scanf("%d", &t);
        while (t -- ){
            scanf("%s%d", n, &k);
            init();
            calc();
            printf("%d %d
    ", ans_min, ans_max);
        }
        return 0;
    }
    

    E - Everything Has Changed

    HDU - 6354

    • 思路:水题 计算几何 画图工具一画就出来了 最开始忘了判断包含的情况调过贡献了一发wa(菜是原罪

    • AC代码


    #include<stdio.h>
    #include<iostream>
    #include<math.h>
    #include<algorithm>
    #include<string.h>
    #include<queue>
    #include<set>
    #include<string>
    #include<sstream>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll Pow_mod(ll a, ll b, ll c){
        ll ans = 1;
        a %= c;
        while (b){
            if (b & 1) ans = (ans * a) % c;
            a = (a * a) % c;
            b >>= 1;
        }
        return (ans % c);
    }
    
    int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a % b);
    }
    
    const double pi = acos(-1);
    
    int t, m;
    double R, x, y, r, d, ans, alpha, beta;
    
    int main(){
        scanf("%d", &t);
        while (t -- ){
            scanf("%d%lf", &m, &R);
            ans = 2 * pi * R;
            while (m -- ){
                scanf("%lf%lf%lf", &x, &y, &r);
                d = sqrt(x * x + y * y);
                if (d >= R + r) continue;
                else if (d == R - r) ans += 2 * pi * r;
                else if (d > fabs(R - r)){
                    alpha = 2 * acos((R * R + d * d - r * r) / (2 * R * d));
                    beta = 2 * acos((d * d + r * r - R * R) / (2 * d * r));
                    ans += (beta * r - alpha * R);
                }
            }
            printf("%.20lf
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    python(九)、线程
    python(八)、进程
    python网络编程(二):网络编程之socket与socketserver
    20145226夏艺华 《Java程序设计》第6周学习总结
    20145226夏艺华《网络对抗》第一次实验拓展:shellcode注入+return-to-libc
    20145226夏艺华《网络对抗》免杀原理与实践
    20145226 《Java程序设计》第5周学习总结
    20145226 《Java程序设计》第4周学习总结
    20145226夏艺华 后门原理与实践
    20145226夏艺华 《Java程序设计》第3周学习总结
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11276197.html
Copyright © 2011-2022 走看看