CodeForces 303B Rectangle Puzzle II】的更多相关文章

题意: 给定一个靠着坐标轴长为n,宽为m的矩形和 矩形中的一个点A,求在这个矩形内部一个 长宽比为a/b的小矩形,使这个小矩形的长宽尽量大使点A在小矩形内部,并且点A尽量靠近小矩形的中心 CF的思维题确实牛,让点A尽量靠近小矩形的中心其实是比较障眼法的,让你觉得这个问题又需要考虑 小矩形最大又需要考虑点A的问题,然是考虑这样一个问题,小矩形的大小和点A在小矩形内部,两个问题是否矛盾. 这是解决问题的关键,所以这不仅是思维的难度,也是心理的考验,在思考这个问题之初就默认这两个问题是矛盾的, 为之后…
C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/problem/C Description You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the cen…
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side…
We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the ith rectangle. Find the total area…
http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个样例,1包围2,2包围3,所以1包围2和3,2包围3. 思路:昨晚tmk大佬给我们讲了一下这题.对于一个国家,将和它相邻的国家连边,最后形成一个图. 可以发现,如果从随便一个点出发DFS,如果失去了某个点之后,导致整个图不连通了,那么这个点就一定包围了一些国家. 例如下面这个样例: 1 1 1 1…
Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x[i] -1 ]这段区间的的数都会走到 k * x[i]上. 所以对于每个位置都先计算出他到右边最远的覆盖位置. 然后在反着求出每个位置能往左走走到的最远的位置. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freo…
We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the ith rectangle. Find the total area…
https://codeforces.com/contest/1198/problem/D 原来是dp的思路,而且是每次切成两半向下递归.好像在哪里见过类似的,貌似是紫书的样子. 再想想好像就很显然的样子,并不会出现奇奇怪怪的合并的样子. #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int dp[51][51][51][51]; char g[51][51]; int main() { #if…
B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple c…
题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace std; #define N 100010 #define L(x) (x<<1) #define R(x) (x<<…
题意:给你m条边,每条边有一个权值,每次询问只保留编号l到r的边,让你把这个图分成两部分 一个方案的耗费是当前符合条件的边的最大权值(符合条件的边指两段点都在一个部分),问你如何分,可以让耗费最小 分析:把当前l到r的边进行排序,从大到小,从大的开始不断加边,判断当前能否形成二分图,如果能形成二分图,继续加边 如果不能形成二分图,那当前边的权值就是最小耗费(是不是很眼熟) 思路很清晰,现在我们要解决的是如何判断可以形成二分图,有两种,一个是2染色当前图(肯定超时) 所以只剩一种方法,带权并查集…
Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials. Fibonacci-ish potential of an array ai is computed as follows: Remove all elements j i…
Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves. The great kingdom consisted…
原题链接 大意 n*n正方形 有黑有白 每次可以选择一个 矩形把它全变成白色,代价是max(长,宽) 求吧 整个正方形 全变白 的最小代价 数据范围 n <= 50 题解 首先如果 我们刷了两个有相邻边或重叠的 白色矩形 那么 假设他们的代价分别为 x和y 那么 一定有 一个 边长为x+y的正方形 完全覆盖了这两个白色矩形 dis|row| <= rowX+roxY <= costX+costY = x+y dis|col| <= colX+roxY <= costX+cos…
题意:有一个n * n的棋盘,每个棋盘有某些矩形区域被染成了黑色(这些矩形区域有可能相交),问把所有黑色区域染成白色的最小花费是多少?你每次可以选择把一个矩形区域染成白色,花费是染色的矩形区域长和宽的最小值. 思路:容易发现,假设一个矩形的坐标是(l1, r1, l2, r2),假设(l2 - l1 < r2 - r1), 那么我们把r1和r2变成1和n对答案不会有影响.那么,我们发现问题转化为了选最少的行和列使得所有的黑色区域被覆盖,换句话说,就是所有的点至少被一个行货列所覆盖.我们把行看成左…
题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据:一种是全是2,那么去重后实际上只有一个数.这样是O(n)的.另一种是所有的数都不一样,那么为了让最大的那个最小,数分别为2, 3 ...1e5, 1e5 + 1, 但是a和b之差最多只有1e6,这种情况甚至比刚才那种耗时更少.故复杂度均摊是O(n)的. 代码: #include <bits/stdc…
题目传送门 题意: 有一个$n∗n$的网格,网格中有一些矩形是黑的,其他点都是白的. 你每次可以花费$ min (h,w)$的代价把一个$h*w$的矩形区域变白.求把所有黑格变白的最小代价. 思路: 对于一列来说,如果我们要把这一列涂白,那必定会一涂到底,这样对结果只会有好处.行也是这样. 明白了这个之后,这道题就变成了一道需要离散化的最小点覆盖问题,离散化时注意这个是网格,所以$x2,y2$都需要加1处理,然后跑一边网络流即可. #pragma GCC optimize (2) #pragma…
给定一些矩形2 求覆盖面积 矩形不超过200个 1 算法1 朴素思想 虽然朴素但是代码却有意思 利用容斥原理 复杂度高达 N*2^N class Solution: def intersect(rec1,rec2): return [max(rec1[1],rec2[1]), max(rec1[2],rec2[2]), min(rec1[3],rec2[3]), min(rec1[4],rec2[4] ] #这里是两个矩形的两点式求 矩形的相交子矩形 *非常值得思考 def area(rec):…
题目链接: https://vjudge.net/problem/UVA-519 思路: 剪枝+回溯 这个题巧妙的是他按照表格的位置开始搜索,也就是说表格是定的,他不断用已有的图片从(0,0)开始拼到(n-1,m-1) 剪枝的地方: 1.由于含'F'的面只能拼到边上,所以'F'的个数就是矩形的周长 2.含'O'的数目应该和含'I'的数目相等 3.可能会有很多重复的碎片,如果前面的碎片不能拼上去,那么后面重复的碎片也不能拼上去 坑点: 题目中明明说了只有15块碎片,但是将数组大小开到20却WA!!…
A. Pythagorean Theorem II 暴力,\(O(n^2)\). B. Calendar 每个日期计算到0年1月1日的天数,相当于转化成前缀和形式. 闰年数计算\[\lfloor\frac{year}{4}\rfloor-\lfloor\frac{year}{100}\rfloor+\lfloor\frac{year}{400}\rfloor\] C. Lucky Permutation Triple 打表找规律. 当\(n\)是偶数时,无解. 否则,序列a.b为\(....0.…
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. Cre…
A. Word Capitalization 模拟. B. Nearest Fraction 枚举. C. Rectangle Puzzle 求出两个矩形的点,套简单多边形的面积交板子. D. Maximum Xor Secondary 枚举位置做为次大值,那么分别向左右两个方向找到第一个比当前值大的值即可. E. Game on Tree…
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Example: Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2 Output:…
A. Word Capitalization 模拟. B. Nearest Fraction 枚举. C. Rectangle Puzzle 求出两个矩形的点,套简单多边形的面积交板子. D. Maximum Xor Secondary 枚举位置做为次大值,那么分别向左右两个方向找到第一个比当前值大的值即可. E. Game on Tree D. k-Maximum Subsequence Sum 做法一: 对于线段树上的每个区间,维护4个值: \(ms[i]\)表示取了\(i\)个区间的最大值…
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1019 Grandpa's Other Estate 1034 Simple Arithmetics 1036 Complete the sequence! 1043 Maya Calendar 1054 Game Prediction 1057 Mileage Bank 1067 Rails 10…
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如:[Swift]LeetCode156.二叉树的上下颠倒 $ Binary Tree Upside Down 请下拉滚动条查看最新 Weekly Contest!!! Swift LeetCode 目录 | Catalog 序        号 题名Title 难度     Difficulty  两数之…
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems classified by company 题目按公司分类(Last updated: October 2, 2017) .   Top Interview Questions # Title Difficulty Acceptance 1 Two Sum Medium 17.70% 2 Add Two N…
# Title Solution Acceptance Difficulty Frequency     4 Median of Two Sorted Arrays       27.2% Hard     10 Regular Expression Matching       25.6% Hard     23 Merge k Sorted Lists       35.8% Hard     25 Reverse Nodes in k-Group       37.7% Hard    …
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a pr…
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #include<iostream> int main() { char str[82]; int num; std::cin >> num; while (num--) { std::cin>>str; char *ps = str; while (*++ps != '\0') {…