• Codeforces 1186


    A.

    水题。略。

    B. (Aborted)

    给你一个 (n*m) 的矩阵,你可以用 (1*2) 的砖铺满矩阵,但要求砖与砖之间不能有公共边或公共点。求最多能放几块砖。

    看上去只要这样放就可以:

    <>.<>.^
    ......v
    <>.<>..
    ......^
    <>.<>.v
    

    但是你有没有考虑过 (5*6(ans=7))

    <>.^.^
    ...v.v
    <>....
    ...^.^
    <>.v.v
    

    (6*6(ans=8))

    <>.^.^
    ...v.v
    <>....
    ....<>
    ^.^...
    v.v.<>
    

    (4*4(ans=4))

    <>.^
    ...v
    ^.<>
    v...
    

    看样子这道题是没有贪心的算法的,然后这道题就被删了,这场比赛就变成了unrated
    std Wrong Answer
    后来有人证明出这道题是有 (O(1)) 算法的,答案 (=frac{(n+1)(m+1)}{6})
    证明如下:
    First, if we extend 1x2 pieces to 2x3 (by adding a row to the bottom and column to the right), 2x1 to 3x2, and the board to (n+1)x(m+1), then we now only care about actual overlaps. This gives an upperbound of (frac{(n+1)(m+1)}{6}) .

    Let's see how it's always possible to achieve the upperbound (from now we consider n and m as increased by 1):

    If we can always leave less than 6 free cells then we achieved the upperbound. Also notice that now (n,m≥2) .

    First, observe that whenever (6|nm) , we can cover the whole board. It can be seen easily for small (n) (upto 7), and for larger (n) we can always break the board into pieces with small (n) and areas divisible by 6.

    This means that from a big board we can always remove pieces with height and width bigger than 1, and area divisible by 6. It only remains to leave less than 6 free cells when (n,m≤7) (if one of them is at least 8 we can remove 6 and obtain the subproblem).

    • (n=2,3): trivial.
    • (n=4): place 2x3 blocks from the left. If you have < 2 columns remaining then it's okay, otherwise place a 3x2 piece.
    • (n=5): when (m<5) we can use the above cases. (m=5) has a construction with a hole in the middle, (m=6) is divisible by 3, and (m=7) can use the hole from (m=5) + a 3x2 piece.
    • (n=6): divisible by 6.
    • (n=7): when (m<7) we can use the above cases, so now (m=7) ; there is a construction very similar to (n,m=5) , which leaves a hole in the middle.

    C.

    两个长度相等的01字符串 (s_1,s_2) ,定义 (f(s_1,s_2))(s_1[i]≠s_2[i])(i) 的个数。现给定两个01字符串 (s,t(|s|>|t|)) ,求 (s) 有多少个长度等于 (|t|) 的子串 (x) 满足 (f(x,t)) 为偶数。 ((|s|,|t|le 10^6))

    如果 (s_1) 包含1的个数和 (s_2) 包含1的个数的奇偶性相同,那么 (f(s_1,s_2)) 是偶数,否则是奇数。
    前缀和处理。时间复杂度 (O(n))

    D.

    给你一个实数序列 (a) ,现在要把 (a) 中的所有元素向上或向下取整,使得序列之和为0。保证有解。输出一种方案。

    先让所有元素全部向下取整,然后把不够的加到不是整数的元素上。
    本题卡精度,ceil() floor()请慎用。最好加上一个eps。

    E.

    将一个给定的01矩阵复制无穷遍得到一个无限大的网络,其中行号+列号为偶数的为原矩阵,为奇数的为原矩阵所有元素取反得到的矩阵,每次询问两个坐标,问两个坐标之间有多少个1。

    很明显的前缀和+边界特判,但是实在是烦,所以代码就咕了。

    F.

    有一张图,现在要你删掉若干条边,你只能保留不超过 (lceil frac{n+m}{2} ceil) 条边,而且你要保证对于每个节点 (i)(lceil frac{d_i}{2} ceil le f_i) ,其中 (d_i) 为操作前节点的度数, (f_i) 为操作后节点的度数。 ((1le n,mle 10^6))

    对每条边从大到小按 (min (f_u-lceil frac{d_u}{2} ceil,f_v-lceil frac{d_v}{2} ceil)) 排序,然后一波很神奇的操作

    Code

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1000003;
    struct edge{
    	int from,to;
    	bool del;
    	edge():del(0){}
    	edge(int u,int v):from(u),to(v),del(0){}
    }e[maxn];
    int n,m,deg[maxn],f[maxn];
    int w(int u){
    	return f[u]-(deg[u]+1)/2;
    }
    bool operator <(edge x,edge y){
    	return min(w(x.from),w(x.to))>min(w(y.from),w(y.to));
    }
    int main(){
    	scanf("%d%d",&n,&m);
    	for(int i=1;i<=m;i++){
    		int u,v;
    		scanf("%d%d",&u,&v);
    		deg[u]++,deg[v]++;
    		e[i]=edge(u,v);
    	}
    	for(int i=1;i<=n;i++)f[i]=deg[i];
    	sort(e+1,e+m+1);
    	int k=m,c=m;
    	while(k>(n+m+1)/2){
    		int u=e[1].from,v=e[1].to;
    		f[u]--,f[v]--;
    		if(w(u)<0||w(v)<0){
    			f[u]++,f[v]++;
    		}
    		else{
    			k--;
    			e[1].del=1;
    		}
    		swap(e[1],e[c]);
    		c--;
    	}
    	printf("%d
    ",k);
    	for(int i=1;i<=m;i++){
    		if(!e[i].del){
    			printf("%d %d
    ",e[i].from,e[i].to);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    c#图像处理
    事件机制(复习)
    .net控件Control透明
    什么东西
    btn控件
    Tao 1.2.0图形框架发布
    java 泛型的类型擦除与桥方法
    来博客园的第一篇博文
    fastjson @JSONField
    java文件编译后,出现xx$1.class的原因
  • 原文地址:https://www.cnblogs.com/BlogOfchc1234567890/p/11109249.html
Copyright © 2020-2023  润新知