zoukankan      html  css  js  c++  java
  • Daliy Algorithm (思维,堆,dfs)-- day 81

    Nothing to fear


    种一棵树最好的时间是十年前,其次是现在!

    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.5.17


    人一我十,人十我百,追逐青春的梦想,怀着自信的心,永不言弃!

    PAT-A1155 Heap Path

    读题太慢 hhh

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <queue>
    
    using namespace std;
    
    const int N = 10005;
    int a[N] , n;
    bool maxc = false,minc = false;
    void dfs(int now,vector<int> path)
    {
        int ls = now * 2;
        int rs = now * 2 + 1;
        if(ls > n && rs > n)
        {
            for(int i = 0; i < path.size() ;i ++)
            {
                if(i == path.size() - 1)printf("%d",path[i]);
                else printf("%d ",path[i]);
            }
            cout << endl;
            return;
        }
        if(rs <= n)
        {
            if(a[now] <= a[rs])minc = 1;
            else maxc = 1;
            path.push_back(a[rs]);
            dfs(rs , path);
            path.pop_back();
        }   
        if(ls <= n)
        {
            if(a[now] <= a[ls])minc = 1;
            else maxc = 1;
            path.push_back(a[ls]);
            dfs(ls , path);
            path.pop_back();
        }
    }
    int main()
    {
        cin >> n;
        for(int i = 1;i <= n ;i ++)scanf("%d",&a[i]);
        vector<int> path;
        path.push_back(a[1]);
        dfs(1,path);
        if(minc && maxc)
        {
            cout << "Not Heap" << endl;
            return 0;
        }
        if(minc)cout << "Min Heap" << endl;
        if(maxc)cout << "Max Heap" << endl;
        return 0;
    }
    

    Sequence with Digits

    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <iomanip>
    #include <cmath>
    #include <ctime>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    
    int getmin(ll x)
    {
        int ans = 11;
        while(x)
        {
            int t = x % 10;
            ans = min(ans , t);
            x /= 10;
        }
        return ans;
    }   
    int getmax(ll x)
    {
        int ans = -1;
        while(x)
        {
            int t = x % 10;
            ans = max(ans ,t);
            x /= 10;
        }
        return ans;
    }
    void slove()
    {
        ll a, k , b;
        cin >> a >> k;
        b = a;
        while(k > 1)
        {
            b = a + getmax(a) * getmin(a);
            if(b == a)
            {
                cout << b << endl;
                return;
            }else a = b;
            k--;
        }
        cout << b << endl;
    }
    int main()
    {
    #ifdef LOCAL
        auto start_time = clock();
        cerr << setprecision(3) << fixed; // 在iomanip中
    #endif
        SIS;
        cin >> t;
        while(t--)
        {
            slove();
        }
    #ifdef LOCAL
        auto end_time = clock();
        cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms
    ";
    #endif
    }
    

    Young Explorers

    题目读不懂真的是一大痛点

    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <iomanip>
    #include <cmath>
    #include <ctime>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    /*
    规定自身经验为 e 得人 所在的队伍的人数必须大于等于e
    */
    bool cmp(int a,int b)
    {
        return a > b;
    }
    void slove()
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i = 0;i < n ;i ++)cin >> a[i];
        sort(a.begin(),a.end());
        int ans = 0, cnt = 0;
        for(int i = 0;i < n ;i ++)
        {
            if(++cnt == a[i])
            {
                ans++;cnt = 0;
            }
        }
        cout << ans << endl;
    }
    int main()
    {
    #ifdef LOCAL
        auto start_time = clock();
        cerr << setprecision(3) << fixed; // 在iomanip中
    #endif
        SIS;
        cin >> t;
        while(t--)
        {
            slove();
        }
    #ifdef LOCAL
        auto end_time = clock();
        cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms
    ";
    #endif
    }
    

    Alarm Clock

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <iomanip>
    #include <cmath>
    #include <ctime>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    
    void slove()
    {
        // a 表示睡眠总时长
        // b 第一次醒来的时间
        // c 表示下一次定闹钟会多久后响
        // d 表示过去多久才能入睡
        ll a , b , c ,d , tot;
        cin >> a >> b >> c >> d;
        tot = b;
        a = a - b;
        int k = c - d;
        if(a <= 0)
        {
            cout << tot << endl;
            return;
        }
        if(k <= 0 && a > 0)
        {// 下不了床
            cout << -1 << endl;
            return;
        }
        if(k > 0 && a > 0)
        {
            ll t = ceil(a * 1.0 / k);
            cout << tot + (ll)t * c << endl;
        }
    }
    int main()
    {
    #ifdef LOCAL
        auto start_time = clock();
        cerr << setprecision(3) << fixed; // 在iomanip中
    #endif
        SIS;
        cin >> t;
        while(t--)
        {
            slove();
        }
    #ifdef LOCAL
        auto end_time = clock();
        cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms
    ";
    #endif
    }
    
  • 相关阅读:
    UDP 远程主机强迫关闭了一个现有连接
    CSS float 理解
    C# 启用事务提交多条带参数的SQL语句
    EF学习之DBFirst
    说一说JavaScript 中的原型ProtoType
    Unity
    Unity
    Unity
    Unity
    Godot
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12906615.html
Copyright © 2011-2022 走看看