• Codeforces 938 正方形方格最多0/1 足球赛dijkstra建图


    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-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 3e7 + 10;
    const int  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    ll mod = 1e9 + 7;
    string ans;
    int n;
    string a;
    int flag;
    bool ok(char x)
    {
            if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y')
            {
                    return true;
            }
            return false;
    }
    int main()
    {
            cin >> n >> a;
            flag = 0;
            for (int i = 0; i < n; i++)
            {
                    if (flag)
                    {
                            if (ok(a[i]))
                            {
                                    continue;
                            }
                            else
                            {
                                    ans += a[i];
                                    flag = 0;
                            }
                    }
                    else
                    {
                            if (ok(a[i]))
                            {
                                    flag = 1;
                                    ans += a[i];
                            }
                            else
                            {
                                    ans += a[i];
                                    flag = 0;
                            }
                    }
            }
            cout << ans << endl;
            return 0;
    }
    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-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 3e7 + 10;
    const int  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    ll mod = 1e9 + 7;
    int number[1000005];
    int anser = 0;
    int main()
    {
            int n;
            cin >> n;
            for (int i = 1; i <= n; i++)
            {
                    int cur;
                    cin >> cur;
                    number[cur] = 1;
            }
            for (int i = 2; i <= 500000; i++)
            {
                    if (number[i])
                    {
                            anser = max(anser, i - 1);
                    }
            }
            for (int i = 999999; i >= 500001; i--)
            {
                    if (number[i])
                    {
                            anser = max(anser, 1000000 - i);
                    }
            }
            cout << anser << endl;
            return 0;
    }
    View Code

    C

    N*N的方格里 每个方格可以填0或者1 要求每个M*M的小方格里面必须要有一个0

    题目给你一个数 问你有没有一对 N,M使之成立

    总共有N^2个方格 因为每个M*M的小方格里面需要有一个0 所以每行和每列最少都需要N/M个0 总共就是(N/M)*(N/M)个0

    所以答案就是N^2-(N/M)^2个 利用立方差公式可以分解为 (N+(N/M)*(N-(N/M)=ANS 也就是分解质因数 复杂度T*SQRT X

    每次遇到一个N M都要检测是否符合条件

    #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  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int main()
    {
            int n;
            cin >> n;
            while (n--)
            {
                    int flag = 0;
                    int x;
                    cin >> x;
                    if (x == 0)
                    {
                            cout << 1 << " " << 1 << endl;
                            continue;
                    }
                    for (int i = 1; i <= ((int)sqrt(x) + 1) && (!flag); i++)
                    {
                            if (x % i == 0)
                            {
                                    int chu;
                                    int beichu;
                                    int a;
                                    a = x / i;
                                    chu = abs(i - a) / 2;
                                    if (chu == 0)
                                    {
                                            continue;
                                    }
                                    beichu = min(i, a) + chu;
                                    int m;
                                    m = beichu / chu;
                                    if (beichu * beichu - (beichu / m) * (beichu / m) == x)
                                    {
                                            cout << beichu << " " << m << endl;
                                            flag = 1;
                                    }
                                    //break;
                            }
                    }
                    if (!flag)
                    {
                            cout << -1 << endl;
                    }
            }
    }
    View Code

    D

    给你N个点 每个点可以都办足球比赛 票价为Ai 同时有M条路(不保证图联通)每条路有COST

    问你在城市i的球迷想看球需要的最少的钱(往返加球票钱)

    用floyd肯定不行 需要建一个超级源点 然后上堆优化的迪杰斯特拉跑一边 超级源点与原来每个点之间连的边的COST为其票价

    #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  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int n, m;
    priority_queue<pair<ll, int> > que;
    vector<pair<int, ll> > gra[200005];
    ll sdis[200005];
    int visit[200005];
    int main()
    {
            for (int i = 1; i <= 200000; i++)
            {
                    sdis[i] = 1e18;
            }
            cin >> n >> m;
            int from, to;
            ll cost;
            for (int i = 1; i <= m; i++)
            {
                    scanf("%d %d %lld", &from, &to, &cost);
                    cost *= 2LL;
                    gra[from].pb(make_pair(to, cost));
                    gra[to].pb(make_pair(from, cost));
            }
            for (int i = 1; i <= n; i++)
            {
                    scanf("%lld", &cost);
                    gra[0].pb(make_pair(i, cost));
            }
            que.push({0, 0});
            while (!que.empty())
            {
                    int now = que.top().second;
                    que.pop();
                    if (visit[now])
                    {
                            continue;
                    }
                    visit[now] = 1;
                    int len = gra[now].size();
                    for (int i = 0; i < len; i++)
                    {
                            to = gra[now][i].first;
                            ll value = gra[now][i].second;
                            if (!visit[to] && sdis[to] > sdis[now] + value)
                            {
                                    sdis[to] = sdis[now] + value;
                                    que.push({ -sdis[to], to});
                            }
                    }
            }
            for (int i = 1; i <= n; i++)
            {
                    cout << sdis[i] << " ";
            }
            cout << endl;
    }
    View Code
  • 相关阅读:
    Activiti 开发案例之动态指派任务
    SpringBoot开发案例之打造十万博文Web篇
    「玩转Python」打造十万博文爬虫篇
    SpringBoot开发案例Nacos配置管理中心
    「玩转Python」突破封锁继续爬取百万妹子图
    SpringBoot开发案例之分布式集群共享Session
    「玩转树莓派」树莓派 3B+ 配置无线WiFi
    「玩转树莓派」搭建智能家居远程监控系统
    「玩转树莓派」搭建属于自己的云盘服务
    「玩转树莓派」为女朋友打造一款智能语音闹钟
  • 原文地址:https://www.cnblogs.com/Aragaki/p/8633266.html
Copyright © 2020-2023  润新知