@codeforces - 1214H@ Tiles Placement】的更多相关文章

目录 @description@ @solution@ @part - 1@ @part - 2@ @accepted code@ @details@ @description@ 给定一个 n 点的树,一条简单路径的长度为这条路径所含点的个数. 现给每个点涂色,颜色编号为 1~k.要求每一条长度恰为 k 的简单路径上点的颜色互不相同. 请构造一个方案,或者判定无解. Input 第一行两个整数 n,k (2≤k≤n≤200000),表示点的个数与颜色个数. 接下来 n-1 行,每行两个整数 vi…
Codeforces 题面传送门 & 洛谷题面传送门 首先先讲一发我的 \(n^2q\log n\) 的做法,虽然没有付诸实现并且我也深知它常数巨大过不去,但是我还是决定讲一讲(大雾 考虑设 \(f(i,j)\) 表示以 \(i,j\) 为左上角,满足其中不同颜色个数 \(\le q\) 的子正方形中大小最大的那个的边长,那么显然求出 \(f(i,j)\) 后一遍后缀和即可求出答案.于是问题转化为如何求 \(f(i,j)\).注意到一个显然的结论:\(f(i,j)\ge f(i,j-1)-1\)…
传送门 考虑一块块填,首先 $(1,1)$ 有 $4$ 种方案 然后根据 $(1,1)$ 的右边颜色,$(1,2)$ 有两种方案,$(1,3)$ 根据 $(1,2)$ 也有两种方案... 考虑 $(2,1)$ 根据 $(1,1)$ 有两种方案,$(3,1)$ 也有两种.... 然后发现,如果我们确定了 $(1,1)$ 到 $(1,m)$ ,确定了 $(1,1)$ 到 $(n,1)$ ,那么之后所有位置都可以根据它们的左边颜色和上面颜色确定 那么方案数即为填左边一列和上边一行的方案数 那么答案整理…
目录 0 引言 0.1 所谓构造题 0.2 重点是动机 (motivation) 1 实践出真知 1.1 「CSP-S 2021」「洛谷 P7915」回文 1.1.1 题目大意 1.1.2 解题过程 1.2 「ARC 110F」Esoswap 1.2.1 题目大意 1.2.2 解题过程 1.3 「多校联训」子集 1.3.1 题目大意 1.3.2 解题过程 1.4 小结 2 拼盘得正解 2.1 「CF 1450C2」Errich-Tac-Toe (Hard Version) 2.1.1 题目大意…
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You s…
https://vjudge.net/problem/CodeForces-516B 题意 在一个n*m图中放1*2或者2*1的长方形,问是否存在唯一的方法填满图中的‘.’ 分析 如果要有唯一的方案,那么必定存在度为一的点,因为只有这样,把这一格以及它相邻的涂掉的方案才唯一,然后可能产生新的度为一的可行点,不断更新,bfs寻找这样的点.最后检测一遍是否还有‘.'存在即可. #include<iostream> #include<cmath> #include<cstring&…
题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似topsort,'.'与上下左右的'.',的相连.从度为1的点作为突破口. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream>…
B. Drazil and Tiles   Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two ti…
题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联通无唯一解. 同时观察可知,只有一条边的点只有唯一一种连法,所以我们可以直接将其与其相连点从图中删除,再考虑剩下图中是否还有只有一条边的点,直到所有的结点都被删除,或剩下双联通分量以及存在没有边的结点为止. 正确性……显然吧.时间复杂度$O(n^{2})$. 代码: #include<cstdio>…
原文链接http://www.cnblogs.com/zhouzhendong/p/8990658.html 题目传送门 - CodeForces 516B 题意 给出一个$n\times m$的矩形.其中有些位置已经被覆盖. 现在让你用$1\times 2$的小矩形来覆盖其他地方,小矩形不能重叠. 如果有多种覆盖方案,或者无法把没被覆盖的地方全部覆盖,那么输出特殊信息.否则输出唯一的方案. $n,m\leq 2000$ 题解 乍一看,我还以为是经典的二分图匹配题目.但是由于$n,m$都很大,所…
Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each…
传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupie…
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案是唯一的; 则输出那个方案,否则,输出不唯一; [题解] 记录每个点的度; 每个点的度,为这个点4个方向上空格的个数; 优先处理度数为1的点; 这些点的摆放方式肯定是唯一的; 摆完这些点(两个之后),与之相连的点的度数都减1: 看看有没有新的度数为1的点; 很像拓扑排序对吧. 最后看看占据的点是不是…
\(\\\) \(Description\) 给出一个\(N\times M\) 的网格,一些位置是障碍,其他位置是空地,求是否存在一个用 \(1\times 2\)的骨牌铺满空地的方案,以及方案是否唯一. 骨牌不能放到网格以外,不能重叠,不能覆盖在障碍物上. \(N,M\le 2000\) \(\\\) \(Solution\) 巧妙的思路题. 注意到有一些位置的方案是唯一的.如果一个空格的周围四联通部分只有一个空格,那么必定有一个骨牌要放在这两个格子上.同时,这一次放置可能会影响另一个格子的…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard input output: standard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships…
C. Chain Reaction 题目连接: http://www.codeforces.com/contest/608/problem/C Description There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys…
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/A Description You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square r…
Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should c…
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an eleva…
A题: A题题目链接 题目描写叙述: 位运算 TimeLimit:1000MS  MemoryLimit:65536KB 64-bit integer IO format:%I64d Problem Description 已知一个包括 n 个元素的正整数集合S.设 f(S) 为集合S中全部元素的异或(XOR)的结果. 如:S={1,2,3}, 则 f(S) = 0. 给出集合S,你须要计算 将全部f(s)进行异或后的值, 这里 s⊆S. Input 多组測试数据.第一行包括一个整数T(T≤20…
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted R…
链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ways to fill all 3×n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. This pict…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecu…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is…
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概率是在正面,各个卡牌独立.求把所有卡牌来玩Nim游戏,先手必胜的概率. (⊙o⊙)-由于本人只会在word文档里写公式,所以本博客是图片格式的. Code #include <cstdio> #include <cstring> #include <algorithm> u…
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连通图)且这颗树中必须包含节点1 然后将这颗子树中的所有点的点权+1或-1 求把所有点权全部变为0的最小次数(n<=10^5) 题解: 因为每一次的子树中都必须有1,所以我们得知每一次变换的话1的权值都会变化 所以我们以1为根 现在,我们发现,如果一个节点的权值发生变化,那么他的父节点的权值一定发生变…