Codeforces Round #589 (Div. 2) - B

题目大意:给定一个 $h$ 行, $w$ 列的矩形,接下来一行 $h$ 个数字, $hi$ 代表第 $i$ 行从左到右有连续的 $hi$ 个染成黑色的方块,列同理,然后问满足条件的矩形的个数(% 1e9 + 7)。

比赛写的时候第一次挂掉了,因为判断原条件不成立的代码写挂了= = ,不知道自己当时在想什么。

我在处理数据时,开了两个数组,分别记录行与列的染色情况。

	forab(i, 1, h)
	{
		cin >> r[i];
		forab(k, 1, r[i])
			G[i][k] = 1, R[i][k] = 1;
	}
	forab(i, 1, w)
	{
		cin >> c[i];
		forab(k, 1, c[i])
			G[k][i] = 1, C[k][i] = 1;
	}

  

我判断原条件不成立的想法是:

	forab(i, 1, h)
	{
		if (C[i][r[i] + 1] == 1)
		{
			flag = 1;
			break;
		}
	}
	forab(i, 1, w)
	{
		if (R[c[i] + 1][i] == 1)
		{
			flag = 1;
			break;
		}
	}

最后计数的判断为:

	forab(i, 1, h)
	{
		forab(j, 1, w)
		{
			if (G[i][j])
				continue;
			if (r[i] + 1 == j || c[j] + 1 == i)
				continue;
			else
				ans = 2 * ans % MOD;
		}
	}

  

原文地址:https://www.cnblogs.com/zssst/p/11610845.html

时间: 2024-07-30 09:33:42

Codeforces Round #589 (Div. 2) - B的相关文章

Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\)的格子中填入\([1,k]\)之间的数字,并且保证每一行至少有一个\(1\),每一列至少有一个\(1\),问有多少种满足条件的填充方案. [Solution] 令\(R[i]\)表示为第\(i\)行至少有一个\(1\)的方案数,\(C[i]\)表示第\(i\)列至少有一个\(1\)的方案数.则题目要

Codeforces Round #589 (Div. 2) B——B. Filling the Grid

Suppose there is a h×wh×w grid consisting of empty or full cells. Let's make some definitions: riri is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1≤i≤h). In particular, ri=0ri=0 if the leftmost cell of the 

Codeforces Round 589 (Div. 2) 题解

Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virtual 玩. 开场先秒了 AB.C 居然差点没做出来,有点耻辱. 开 D.怎么不会--Div. 2 的 D 都能卡住我,我心态崩了. 调到 E. woc 这不是 sb 题吗-- 回来肝 D.想了想口胡出来了,然而心态已经崩了,用了很长很长时间才打出来. 最后只剩 20min 时开 F.这--辣鸡三合

Codeforces Round #589 (Div. 2) (e、f没写)

https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每一位的数字不相同,找出满足要求的最小的那个数输出,没有找到就输出-1: 1 #include<bits/stdc++.h> 2 using namespace std; 3 bool check(int n){ 4 int vis[15]={0}; 5 while(n){ 6 if(!vis[n%

Codeforces Round #589 (Div. 2) A. Distinct Digits

链接: https://codeforces.com/contest/1228/problem/A 题意: You have two integers l and r. Find an integer x which satisfies the conditions below: l≤x≤r. All digits of x are different. If there are multiple answers, print any of them. 思路: 水题. 代码: #include

Codeforces Round #589 (Div. 2) - A

题目大意:给定一个闭区间,问这个区间内有没有满足各数位数字不相等的数,有的话输出任意一个,没有的话输出 -1. #include <bits/stdc++.h> #include <bitset> using namespace std; #define mp(x, y) make_pair(x,y) #define mset(a, n) memset(a, n, sizeof(a)) #define forn(i, n) for (int i = 0; i < (n); i

Codeforces Round #589 (Div. 2) - C

题目大意:$prime(x)$ 代表 $x$ 的质因数的集合. $g(x, p)$ 代表 $p^k$ 的最大值, $k$ 为整数,并且 $x$ 可以被 $p^k$ 整除. $f(x, p)$ 代表 对于 $prime(x)$ 中的每一个 $x$ 的 $g(x, p)$ 值. 现在给定 $x, n$ 求 $f(x, 1) * f(x, 2) * ... *f(x, n) mod (10^9 + 7)$ 的值. 思路:对于 $x$ 进行质因数分解,分别考虑每一个 $prime(x)$ 对答案做出的贡

Codeforces Round #589 (Div. 2)

目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Complete Tripartite E. Another Filling the Grid Contest Info Practice Link Solved A B C D E F 5/6 O O O O ? - O 在比赛中通过 ? 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solutions

Codeforces Round #589 div.2 C,D

感觉这一场的复杂度非常的玄学... 也可能是我偷懒太长时间变菜了QAQ. C 题意: 给出\(x,n\),求x质因子的从1到n的g(i,p)的连乘 思路: 求出x的每个质因子,直接连乘到n计算即可. #include<bits/stdc++.h> #define ll long long using namespace std; typedef pair<int,int> pii; typedef vector<int> VI; vector<int> pr