zoukankan      html  css  js  c++  java
  • Codeforces Round #668 (Div. 2)题解

    Problem B

    emmm,我们肯定想让尽可能多的正数去消掉后面的负数,所以我们累加一个前缀和,如果这个前缀和当前元素为负数,表示前面的所有元素不需要花费代价的操作进行后,还剩余这些数量,需要花费代价去清除,那么我们就对这个前缀和数组里面的负数取一个最小值就好了。

    Problem C

    简单模拟我们发现,所有mod k相同的i和j必须不冲突,否则答案就是no。然后如果1和0的元素大于k/2,答案也是no。

    Problem D

    树上博弈。首先,da大于两人的距离,先手必赢。或者是db<=da2(先手一直追,后手必定到达叶子节点,只能往回走,如果回走这一步后还在先手的范围内,那么必输),先手必赢。还有一种情况,就是树的直径小于2da先手也必胜。

    代码实现

    #include<cstdio>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<set>
    #include<map>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    #define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
    #define per(i,n,a) for (int i=n;i>=a;i--)
    #define MT(x,i) memset(x,i,sizeof(x) )
    #define rev(i,start,end) for (int i=start;i<end;i++)
    #define inf 0x3f3f3f3f
    #define mp(x,y) make_pair(x,y)
    #define lowbit(x) (x&-x)
    #define MOD 1000000007
    #define exp 1e-8
    #define N 1000005 
    #define fi first 
    #define se second
    #define pb push_back
    typedef long long ll;
    const ll INF=0x3f3f3f3f3f3f3f3f;
    typedef vector <int> VI;
    typedef pair<int ,int> PII;
    typedef pair<int ,PII> PIII;
    ll gcd (ll a,ll b) {return b?gcd (b,a%b):a; }
    inline int read() {
        char ch=getchar(); int x=0, f=1;
        while(ch<'0'||ch>'9') {
            if(ch=='-') f=-1;
            ch=getchar();
        } while('0'<=ch&&ch<='9') {
            x=x*10+ch-'0';
            ch=getchar();
        } return x*f;
    }
    
    const int maxn=3e5+10;
    int n,a,b,da,db;
    int deep[maxn];
    int dist,diam;
    vector <int> G[maxn];
    int root1,root2;
    
    void dfs (int u,int fa,int &diam,int &root) {
        deep[u]=deep[fa]+1;
        if (diam<deep[u]) {
            diam=deep[u];
            root=u;
        }
        for (auto it:G[u]) {
            if (it==fa) continue;
            dfs (it,u,diam,root);
        }
    }
    
    int main () {
        ios::sync_with_stdio (false);
        int t;
        cin>>t;
        while (t--) {
            cin>>n>>a>>b>>da>>db;
            rep (i,1,n) G[i].clear ();
            rep (i,1,n-1) {
                int u,v;
                cin>>u>>v;
                G[u].pb (v);
                G[v].pb (u);
            }
            diam=0;
            root1=0,root2=0;
            dfs (b,0,diam,root1);
            dist=deep[a]-deep[b];
            dfs (root1,0,diam,root2);
            diam--;
    
            if (dist>da&&db>=2*da+1&&diam>=2*da+1) cout<<"Bob"<<endl;
            else cout<<"Alice"<<endl;
        }    
        
        return 0;
    }
    
  • 相关阅读:
    array and ram
    char as int
    pointer of 2d array and address
    Install SAP HANA EXPRESS on Google Cloud Platform
    Ubuntu remount hard drive
    Compile OpenSSL with Visual Studio 2019
    Install Jupyter notebook and tensorflow on Ubuntu 18.04
    Build OpenCV text(OCR) module on windows with Visual Studio 2019
    Reinstall VirtualBox 6.0 on Ubuntu 18.04
    Pitfall in std::vector<cv::Mat>
  • 原文地址:https://www.cnblogs.com/hhlya/p/13628343.html
Copyright © 2011-2022 走看看