zoukankan      html  css  js  c++  java
  • Codeforces 955 LR询问 多次幂处理

    A

    模拟题

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-10;
    const double EPS = 1.0e-4;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    //const int maxn = 3e5 + 10;
    const int  maxn = 100005;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    const int turn2[8][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}, {1, -1}, { -1, -1}, {1, 1}, { -1, 1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int main()
    {
            double h, m, C;
            cin >> h >> m;
            int H, D, N;
            cin >> H >> D >> C >> N;
            double ans = 0;
            double duce = 0;
            if (h < 20)
            {
                    duce = 1.0 * (20 - h) * 60 - m;
            }
            else
            {
                    C = 0.8 * C;
            }
            int need = H / N + (1 - (H % N == 0));
            double ans1 = 1.0 * need * C;
            if (duce != 0)
            {
                    H += D * duce;
                    C = 0.8 * C;
                    need = H / N + (1 - (H % N == 0));
                    ans = need * C;
                    printf("%.4f
    ", min(ans, ans1));
            }
            else
            {
                    printf("%.4f
    ", ans1);
            }
    }
    View Code

    B

    阅读理解

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-10;
    const double EPS = 1.0e-4;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    //const int maxn = 3e5 + 10;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int ch[30];
    int main()
    {
            int sum = 0;
            string a;
            cin >> a;
            for (int i = 0; i < a.size(); i++)
            {
                    if (ch[a[i] - 'a'] == 0)
                    {
                            sum++;
                    }
                    ch[a[i] - 'a']++;
            }
            if (sum > 4)
            {
                    cout << "No" << endl;
                    return 0;
            }
            if (sum == 4)
            {
                    cout << "Yes" << endl;
            }
            else if (sum == 3)
            {
                    for (int i = 0; i <= 25; i++)
                    {
                            if (ch[i] > 1)
                            {
                                    cout << "Yes" << endl;
                                    return 0;
                            }
                    }
                    cout << "No" << endl;
            }
            else if (sum == 2)
            {
                    for (int i = 0; i <= 25; i++)
                    {
                            if (ch[i] == 1)
                            {
                                    cout << "No" << endl;
                                    return 0;
                            }
                    }
                    cout << "Yes" << endl;
            }
            else
            {
                    cout << "No" << endl;
            }
            return 0;
    }
    View Code

    C

    给你Q(1~1e5)个询问 每个询问有L,R(1~1e18)

    问你L~R之间有多少个"good number"  “good number"是a^p的数 a>0 p>1

    因为总共有1e18个数 所以当p固定时 就有10^(18/p)个数 当p为2的时候很大 特殊处理 二分枚举checkL和R的sqrt得到答案

    再来处理3~60部分(因为2^60>1e18)的答案 因为最大的10^(18/3)只有1e6所以可以全部枚举出来再nlogn排序去重 预处理复杂度为nlogn

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-10;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    //const int maxn = 3e5 + 10;
    const int  maxn = 100005;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    const int turn2[8][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}, {1, -1}, { -1, -1}, {1, 1}, { -1, 1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    ll nowmaxn = 1e18;
    ll anser1;
    ll anser2;
    ll num[2000005];
    int pop = 1;
    //ll qpow(ll a, ll b)
    //{
    //        ll ans = 1, base = a;
    //        while (b != 0)
    //        {
    //                if (b & 1 != 0)
    //                {
    //                          ans *= base;
    //                }
    //                base *= base;
    //                b >>= 1ll;
    //                 
    //        }
    //        return ans;
    //}
    bool judge(ll x)
    {
            ll s = sqrt(x);
            for (ll i = s; i <= s + 1; i++)
            {
                    if (1LL * i * i == x)
                    {
                            return true;
                    }
            }
            return false;
    }
    void init()
    {
            ll now;
            ll limit;
            for (ll i = 2; i <= 1000000; i++)
            {
                    limit = nowmaxn / i;
                    now = 1LL * i * i;
                    for (ll j = 3;; j++)
                    {
                            now = 1LL * i * now;
                            if (!judge(now))
                            {
                                    num[pop++] = now;
                            }
                            if (now > limit)
                            {
                                    break;
                            }
                    }
            }
            sort(num + 1, num + pop);
            pop = unique(num + 1, num + pop) - num;
    }
    ll gettwo(ll x)
    {
            ll ans;
            ll l = 0;
            ll r = 2e9;
            while (l < r - 1)
            {
                    ll mid = (l + r) >> 1;
                    if (mid * mid <= x)
                    {
                            l = mid;
                    }
                    else
                    {
                            r = mid;
                    }
            }
            return l;
    }
    int main()
    {
            init();
            //        for (int i = 1; i <= 10; i++)
            //        {
            //                cout << num[i] << " ";
            //        }
            //        cout << endl;
            ll L, R;
            int q;
            cin  >> q;
            for (int i = 1; i <= q; i++)
            {
                    anser1 = anser2 = 0;
                    scanf("%lld %lld", &L, &R);
                    if (L == 1)
                    {
                            anser1++;
                    }
                    anser1 = gettwo(R) - gettwo(L - 1);
                    //cout << anser1 << endl;
                    int L1 = lower_bound(num + 1, num + pop, L) - num;
                    int R1 = lower_bound(num + 1, num + pop, R) - num;
                    //cout << "   " << L1 << " " << R1 << endl;
                    if (L1 == R1)
                    {
                            if (num[L1] == R)
                            {
                                    anser2++;
                            }
                    }
                    else
                    {
                            anser2 = R1 - L1 + (num[R1] == R);
                    }
                    cout << anser1 + anser2 << endl;
            }
    }
    View Code
  • 相关阅读:
    20162304 2017-2018-1 《程序设计与数据结构》第十周学习总结
    20162304 2017-2018-1 《程序设计与数据结构》第九周学习总结
    20162304 2017-2018-1 《程序设计与数据结构》第八周学习总结
    20162302 2017-2018-1《程序设计与数据结构》课程总结
    20162302 实验五《数据结构综合应用》实验报告
    20162302 实验四《图的实现与应用》实验报告
    20162302 《程序设计与数据结构》第十一周学习总结
    20162302 《程序设计与数据结构》第十周学习总结
    20162302 实验三《查找与排序》实验报告
    20162302 《程序设计与数据结构》第九周学习总结
  • 原文地址:https://www.cnblogs.com/Aragaki/p/8654621.html
Copyright © 2011-2022 走看看