zoukankan      html  css  js  c++  java
  • Codeforces_813

    A.统计总时间,从总时间开始找第一个能提交的点。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,m,a[1005],ok[100005] = {0};
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n;
        int sum = 0;
        for(int i = 1;i <= n;i++)   cin >> a[i],sum += a[i];
        cin >> m;
        for(int i = 1;i <= m;i++)
        {
            int x,y;
            cin >> x >>y;
            for(int j = x;j <= y;j++)   ok[j] = 1;
        }
        for(int i = sum;i <= 100000;i++)
        {
            if(ok[i])
            {
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
        return 0;
    }
    View Code

    B.把每个unlucky值都算出来,再算最长段。

    #include<bits/stdc++.h>
    using namespace std;
    
    long long x,y,l,r,a[105],b[105];
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> x >> y >> l >> r;
        int cnt1 = 0,cnt2 = 0;
        a[++cnt1] = 1;
        b[++cnt2] = 1;
        while(a[cnt1] <= r/x)
        {
            a[cnt1+1] = a[cnt1]*x;
            cnt1++;
        }
        while(b[cnt2] <= r/y)
        {
            b[cnt2+1] = b[cnt2]*y;
            cnt2++;
        }
        set<long long> s;
        for(int i = 1;i <=cnt1;i++)
        {
            if(a[i] > r)    continue;
            for(int j = 1;j <= cnt2;j++)
            {
                if(b[j] > r) continue;
                if(a[i]+b[j] < l) continue;
                if(a[i]+b[j] > r) continue;
                s.insert(a[i]+b[j]);
            }
        }
        s.insert(l-1);
        s.insert(r+1);
        long long ans = 0;
        for(auto it = ++s.begin();it != s.end();it++)
        {
            long long xx = *it;
            it--;
            long long yy = *it;
            it++;
            ans = max(ans,xx-yy-1);
        }
        cout << ans << endl;
        return 0;
    }
    View Code

    C.分两种情况,Bob一直往下跑到叶子节点或者先往上跑,再往下跑到更深的叶子节点。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,x,a[200005] = {0},maxx[200005],ok[200005] = {0};
    int ans;
    vector<int> v[200005];
    
    void dfs1(int now,int pre)
    {
        maxx[now] = a[now];
        for(int i = 0;i < v[now].size();i++)
        {
            int t = v[now][i];
            if(t == pre)    continue;
            a[t] = a[now]+1;
            dfs1(t,now);
            if(ok[t])   ok[now] = 1;
            maxx[now] = max(maxx[now],maxx[t]);
        }
    }
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n >> x;
        ok[x] = 1;
        for(int i = 1;i < n;i++)
        {
            int x,y;
            cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        dfs1(1,-1);
        ans = maxx[x];
        for(int i = 2;i <= n;i++)
        {
            if(ok[i])
            {
                if(a[x]-a[i] < a[i])    ans = max(ans,maxx[i]);
            }
        }
        cout << ans*2 << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    ubuntu 下安装memcache 以及php扩展
    js控制页面显示和表单提交
    phpcms--使用添加php原生支持
    phpcms v9 升级视频云问题推荐位不能添加
    phpcms—— 内容中的附件调用和添加远程地址的调用
    phpcms--模型管理,推荐位管理,类别管理
    linux shell 编程
    css中的定位和框模型问题
    php生成静态文件
    打印机问题win7 和xp
  • 原文地址:https://www.cnblogs.com/zhurb/p/7253234.html
Copyright © 2011-2022 走看看