• 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;
    }
    
  • 相关阅读:
    Java连接各种数据库的实例
    解决Android SDK Manager 更新、下载慢以及待安装包列表不显示
    This version of the rendering library is more recent than your version of ADT plug-in. Please update
    注册asp.net 4.0 到iis
    linux下常用的截图、录屏工具
    汉化Eclipse+配色方法(官方语言包)
    用了皮肤控件之后,报错:容量超出了最大容量 参数名:capacity
    自定义DateTimeInput(时间)控件的显示格式
    SQL语句增加列、修改列类型、修改列、删除列
    GDI+ DrawString字间距问题
  • 原文地址:https://www.cnblogs.com/hhlya/p/13628343.html
Copyright © 2020-2023  润新知