zoukankan      html  css  js  c++  java
  • Codeforces Round #539 (Div. 1)

    果然还是太菜啊 试着打一次div1就很凉凉啊
    (本文正在施工)

    比赛链接

    cf

    A

    询问有多少个长度是偶数的区间,左半边异或和等于右半边异或和
    (n leq 3e5)

    相当于询问有多少个长度是偶数的区间的异或和为0

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <map>
    #define P(x, y) 1ll * (x) * inv(y) % P
    using namespace std;
    typedef long long ll;
    const int N = 3e5 + 5;
    const ll P = 1e9 + 7;
    map<long long, long long> mp[2];
    int n;
    long long a[N], cnt, ans;
    int main(){
    	scanf("%d", &n);
    	mp[0][0] = 1;
    	for(int i = 1; i <= n; ++i){
    		scanf("%lld", &a[i]), cnt ^= a[i];
    		//printf("%d %lld
    ", i, cnt);
    		ans += mp[i & 1][cnt];
    		++mp[i & 1][cnt];
    	}
    	printf("%lld
    ", ans);
    	return 0;
    }
    

    B

    给一个回文串 问至少切几刀能把切下来的块重组成一个新回文串
    (len leq 5000)

    只有中间那个字符出现奇数次 所以它一定换完之后还是中心
    它两边的字符如果都相等那么一定是impossible
    否则最多切两刀 然后暴枚只切一次的情况是否存在就好啦

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <map>
    #define P(x, y) 1ll * (x) * inv(y) % P
    using namespace std;
    typedef long long ll;
    const int N = 10000 + 5;
    const ll P = 1e9 + 7;
    int n, m, ans;
    char str[N];
    bool check(int l, int r){
    	bool flag = 0;
    	for(int i = l; i <= r; ++i) flag |= (str[i] != str[i - l + 1]);
    	if(!flag) return 0;
    	for(int i = 0; i < (n >> 1); ++i){
    		if(str[l + i] != str[r - i]) return 0;
    	}
    	return 1;
    }
    int main(){
    	scanf("%s", str + 1); n = strlen(str + 1);
    	bool flag = 0;
    	for(int i = 1; i <= (n >> 1); ++i){
    		if(str[i] != str[1]) flag = 1;
    	}
    	if(!flag){
    		printf("Impossible
    "); return 0;
    	}
    	
    	flag = 0;
    	for(int i = 1; i < n; ++i){
    		str[i + n] = str[i];
    	    flag |= check(i + 1, i + n);
    	}
    	
    	if(!flag) ans = 2;
    	else ans = 1;
    	printf("%d
    ", ans);
    	return 0;
    }
    

    C

    有一个装耐心的容器,容量为v,有一个水龙头会喷或吸耐心【雾
    如果容器装满了就会爆炸
    有三种操作:
    在时刻t将水龙头的速率改为s
    删除时刻t的修改
    询问假如容器容量为v,那么从l时刻开始接耐心,r时刻前会不会爆炸
    如果爆炸是什么时候,不爆炸输出-1
    (1 le t le 10^9, -10^9 le s le 10^9, 1 le l le r le 10^9, 0 le v le 10^9)
    误差允许1e-6

    D

    所有边权都是 [1,m] 中的整数的所有 n 个点的树中,
    统计编号为a的点到编号为b的点的距离恰好是 m 的树的个数
    (n,m leq 1e6)

    假设给定的a,b之间有i条边
    那么这i条边分配权值的方式有(C_{m-1}^{i-1})
    然后这路径上的点的种类和排列有(A_{n−2}^{i−1})

    接下来就是把剩下的点接到这个路径上
    剩下的这些边显然可以随便分配(m^{n−i−1})
    然后这些点(所有的n个点)的形态就是i+1个森林挂在路径上
    根据广义 Cayley 定理:
    n 个带标号点形成一个有 k 颗树的森林,
    使得给定的 k 个点没有两个点属于
    同一颗树的方案数为(k*n^{n−k−1})
    方案数应该是((i + 1) * n^{n - i - 2})

    (p.s. Carley定理:n个点完全图的生成树个数是(n^(n - 2))
    这和prufer序列那个结论是一样的)
    贴一个证明
    orz

    然后答案就是

    [f(i)=A(n-2, i-1) cdot C(m-1,i-1)cdot m^{n-i-1} cdot (i+1) cdot n^{n-i-2} ]

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    #define mp(x, y) make_pair(x, y)
    #define P(x, y) 1ll * (x) * inv(y) % P
    #define sit set<Node> :: iterator
    using namespace std;
    typedef long long ll;
    //typedef pair<int, long long> PIL;
    const int N = 1e6 + 5;
    const ll P = 1e9 + 7;
    const ll inf = 1e10;
    int n, m, a, b;
    ll inv[N], jie[N], jv[N], ans;
    inline ll C(int x, int y){
    	return jie[x] * jv[y] % P * jv[x - y] % P;
    }
    inline ll A(int x, int y){
    	return jie[x] * jv[x - y] % P;
    }
    inline void add(ll &x, ll y){
    	x += y; if(x > P) x -= P; 
    }
    inline ll qpow(ll x, ll y){
    	ll res = 1;
    	//printf("qpow %lld %lld
    ", x, y);
    	while(y){
    		if(y & 1) res = res * x % P;
    		x = x * x % P, y >>= 1;
    	}
    	return res;
    }
    int main(){
    	scanf("%d%d%d%d", &n, &m, &a, &b);
    	inv[0] = jie[0] = jv[0] = inv[1] = jie[1] = jv[1] = 1;
    	for(int i = 2; i <= n || i <= m; ++i) 
    	    jie[i] = jie[i - 1] * i % P , inv[i] = (P - P / i) * inv[P % i] % P, jv[i] = jv[i - 1] * inv[i] % P;
    	for(int i = 1; i <= m && i < n; ++i){
    		//printf("i : %d
    ", i);
    		add(ans, A(n - 2, i - 1) * C(m - 1, i - 1) % P
    		* qpow(m, n - i - 1) % P
    		* (i == n - 1 ? 1ll : ((i + 1) % P * qpow(n, n - i - 2) % P)) % P);
    	}
    	printf("%lld
    ", ans);
    	return 0;
    }
    

    E

    F

  • 相关阅读:
    windows下如何添加、删除和修改静态路由
    node.js后台快速搭建在阿里云(二)(pm2和nginx篇)
    使用PM2守护Nodejs命令行程序
    使用pm2管理nodejs应用
    ubuntu 下安装nodejs以及pm2
    nginx优化缓冲缓存
    nginx proxy_buffer_size 解决后端服务传输数据过多,其实是header过大的问题
    经济规律 宏观调控 与个体
    宏观调控
    《论教育》-------叔本华
  • 原文地址:https://www.cnblogs.com/hjmmm/p/10838682.html
Copyright © 2011-2022 走看看