暴力求解
文章平均质量分 54
HelloWorld10086
追随大神的脚步
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
UVA 11464 Even Parity(状态压缩)
题意: 给你一个 n * n 的 01 矩阵,现在你的任务是将这个矩阵中尽量少的 0 转化为 1 ,使得每个数的上下左右四个相邻的数加起来是偶数。求最少的转化个数。解析: 首先,n 的规模并不大,最大只有15。但是完全枚举整个矩阵显然是不可能的。但是我们可以枚举第一行,然后用第一行来算出后面的所有行。 先来说下算法。对于每一行,我们通过他上面的两行来决定他的值。如果上面两行得到值原创 2015-02-08 11:34:10 · 673 阅读 · 0 评论 -
hdu 5374 Tetris(模拟俄罗斯方块)
题意: 俄罗斯方块想必大家都玩过,现在题目给出了3种俄罗斯方块。 O形,I形,L形 以及5种操作,w选择,a左移一位,d右移以为,w下移一位,p什么都不做。然后又给出了方块出现的序列,要求按所给出的操作能消除多少行。解析: DRAW数组表示已(x,y)(x,y)为左下角,能在图上画出的形状。 然后模拟每个每个方块,直到当前方块不能动位置,在二维数组中标记方块,然后接下来选原创 2015-08-13 19:24:13 · 1194 阅读 · 0 评论 -
hdu 5277 YJC counts stars(邻接表+构造)
题意: 给出n个点和m条边,题目保证任意两条边如果相交那么交点一定是两条线段的端点。定义dujiao点集为点集中任意两点均连成线段。求所有的dujiao点集中点的个数最大是多少个,并输出有多少个点数个数最大的dujiao点集解析: 根据题意,不难想到dujiao点集最多只有4个点,那么有4种情况需要考虑: 1. 如果最大为4,先构造4个点的图形,枚举一条边bc和一个顶点a构造出一个三原创 2015-07-05 15:42:26 · 594 阅读 · 0 评论 -
UVa 1523 Helicopter(全排列)
题意 给出一个公式,求这个公式的最小值。 公式的计算方法是sqrt(每个座位到中心的横向距离的和)^2 +(到中心的纵向距离的和)^2。解析: 由于数据量只有8,直接暴力全排列8个位置计算,取最小的。AC代码#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespa原创 2015-05-06 08:56:26 · 554 阅读 · 0 评论 -
UVa 585 Triangles(暴力)
题意:给出一个倒三角,由若干个小三角形组成,有些三角形上涂有颜色,问说最大能找出最大的三角形面积。解析:枚举每个没有上色的三角形,作为顶点,向一个方向逐层搜索。 注意:坐标和为奇数的只能往下,偶数只能往上。AC代码#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>原创 2015-05-06 09:14:15 · 587 阅读 · 0 评论 -
uva 1419 Ugly Windows(暴力求解)
题意: 给出一张图,模仿windows窗口程序,问有哪些窗口未被其他窗口覆盖。解路: 暴力枚举,先找到窗口的左上角,然后枚举出长宽,再判断边框是否等于左上角字母,再判断边框里面,是否只有’.’。AC代码#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>#include <cctype>原创 2015-05-13 07:54:31 · 783 阅读 · 0 评论 -
UVA 654 Ratio(水题)
题意: 给出a和b,找出一个序列,要求分母i由1到b,分子u是所有可能的分子中u/i最接近a/b的,然后将中的一些项删除,保证所u/i是越来越接近a/b的。解析: 暴力枚举分母i,分子u = i * a /b(四舍五入),然后维护一个标准,保证是接近的。AC代码#include <cstdio>#include <cstring>#include <algorithm>#inclu原创 2015-05-13 07:38:23 · 658 阅读 · 0 评论 -
UVA 471 Magic Numbers(枚举)
题意: s1/s2=Ns1/s2=N,s1、s2、N都是各个位数上数字不相同的整数。 给定N,求有多少个这样的式子并输出。思路: 其实最大的数只能是9876543210,所以我们只要暴力枚举s2,枚举过程中判断s1、s2是否符合题目要求即可。AC代码#include <cstdio>#include <cstring>#include <algorithm>#include原创 2015-04-22 16:47:53 · 615 阅读 · 0 评论 -
fzu 2183 简单题
解析: 直接暴力求解,将两个cstring中的字符提取出来存在结构体中 结构体中保存当前位置的字符ch,接下来连续字符的个数num。 再把nstring压缩,存于结构题中,将nstring的结构体掐头去尾,头部和尾部的字符要相同,头部和尾部的要小于等于目标串的个数,中间的部分要相同,由于数据量比较小,中间部分直接用O(n^2)暴力比较。AC代码#include <cstdio>#原创 2015-03-22 19:28:33 · 758 阅读 · 0 评论 -
ZOJ 3818 Pretty Poem(暴力求解)
题意: 给定一个字符串,问这个字符串能否组成 ABABA 或者 ABABCAB的形式。注意: A,B,C互不相同。解析: 由于字符串的长度只有50,所以可以直接暴力枚举,A和B的长度肯定不能超过len/2, 对于 ABABA的情况可以直接枚举 A和B,判断是否满足条件。 对于 ABABCAB的情况可以通过枚举A和B求出C,然后判断是否满足条件。AC代码#include <io原创 2015-03-11 19:31:02 · 683 阅读 · 0 评论 -
CSU 1553 Good subsequence(暴力求解)
题意 求一个子序列满足 最大值 - 最小值 <= k的最大长度。解析 假设之前最大的是a[4],最小的是a[5] 连续子串已经是 a[0] ~ a[10] 这时候判断a[11]是否符合, 两种情况 一种a[11]比a[4]大 这时候判断他 a[11] - min <= k 是否符合 假如不符合 就向前查找,第一个a[j] >= (a[11] - k原创 2015-03-28 22:36:05 · 627 阅读 · 0 评论 -
HDU 5175 Misaki's Kiss again(暴力枚举+异或运算)
题意 找到满足gcd(N,M)==NxorM的M值(1<=M<=N)解析: 令M = N xor K,原式:gcd(N,N xor K) == N xor (N xor K) == K 由此我们可以发现K是N的约数,找到所有N的约数,判断是不是满足那个等式即可,因为是异或运算,结果可能比约数本身大,如1xor2==3,还有异或出来结果等于0的舍掉,gcd(n,n) != n xor原创 2015-02-26 16:31:44 · 1122 阅读 · 0 评论 -
UVA 10317 Equating Equations (状态压缩)
题意: 给一个等式,但是这个等式不一定是正确的,要你对等式中的数字重新排序,使得等式成立。等式只有+和-,数字个数小于16。分析: 由于数字只有16,总共有2^16种可能,所以可以用状态压缩求解。 以a + b - c = d - e为例子。 1. 我们把等式右边的各项都换到左边,a + b - c - d + e = 0 2. 把+项和-项放一起,就变成(a + b原创 2015-02-26 16:57:58 · 847 阅读 · 0 评论 -
CodeChef WPROB(数组辅助+暴力求解)
这边有中文的题目: https://codechef_shared.s3.amazonaws.com/download/translated/LTIME21/mandarin/WPROB.pdf解析: 因为每次移动木块,只有该木块移动其他的木块的相应位置不会发生改变,利用贪心的思想,移动的次数为当前位置前面不同颜色木块的次数。 因为最终的情况只可能有6种。所以枚举这6种情况,计算出最小的原创 2015-02-22 22:16:13 · 566 阅读 · 0 评论 -
UVA - 11218 KTV(暴力求解)
Problem KKTVOne song is extremely popular recently, so you and your friends decided to sing it in KTV. The song has 3 characters, so exactly 3 people should sing together each time (yes, there原创 2014-09-02 18:58:57 · 1237 阅读 · 0 评论 -
UVA - 11059 Maximum Product (简单枚举)
Problem D - Maximum ProductTime Limit: 1 secondGiven a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecutive term原创 2014-08-10 20:59:48 · 1526 阅读 · 0 评论 -
POJ 1731 Orders(全排列)
DescriptionThe stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the kinds having labels starting with the same letter are stored in the same warehouse (原创 2014-08-06 21:36:18 · 820 阅读 · 0 评论 -
UVA - 729 The Hamming Distance Problem (全排列)
The Hamming Distance Problem The Hamming distance between two strings of bits (binary integers) is the number of corresponding bit positions that differ. This can be found by using XOR on原创 2014-08-10 19:46:38 · 813 阅读 · 0 评论 -
子集生成的两种方法 (增量构造法 和 位向量法)
该算法来自--刘汝佳的算法竞赛入门经典。书中介绍了两种算法的核心代码,但却没有逐过程详细解说,另初学者看文字时很难看懂,遇到问题,是先要直接研究问题的细节呢还是先把问题搞清楚?我认为绝对应该先学习如何去解决问题,构造方法的框架,而不是先去研究细节。方法一:思路:一次选出一个元素放到集合中方法二:思路:构造一个位向量b[],而不是直接构造子集A本身转载 2014-08-09 09:06:48 · 3288 阅读 · 0 评论 -
UVA - 131 The Psychic Poker Player (暴力枚举+模拟)
The Psychic Poker Player In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and ha原创 2014-08-09 18:02:08 · 1081 阅读 · 0 评论 -
UVA - 146 ID Codes (枚举排列)
ID Codes It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakd原创 2014-08-09 18:47:17 · 907 阅读 · 0 评论 -
Uva 10167 - Birthday Cake
题意:给你一系列的点,让你找出一条直线AX+BY=0,使直线把这一系列的点分为两个部分。由于A,B的范围在-500~500之间,所以直接枚举就可以了。原创 2014-07-21 19:10:42 · 973 阅读 · 0 评论 -
UVA - 11205 The broken pedometer(子集枚举+增量构造法)
The Broken Pedometer The ProblemA marathon runner uses a pedometer with which he is having problems. In the pedometer the symbols are represented by seven segments (or LEDs):原创 2014-08-08 22:16:17 · 1073 阅读 · 0 评论 -
UVA - 725 Division (暴力枚举)
Division Write a program that finds and displays all pairs of 5-digit numbers thatbetween them use the digits0 through 9 once each, such that thefirst number divided by the second is equ原创 2014-08-10 13:48:12 · 951 阅读 · 0 评论 -
UVA - 10098 Generating Fast (全排列)
Generating Fast, Sorted PermutationInput: Standard Input Output: Standard Output Generating permutation has always been an important problem in computer science. In this problem you will hav原创 2014-08-10 19:42:25 · 940 阅读 · 1 评论 -
HDU - 2474 Process scheduling (模拟银行家算法)
题目大意:给你两个数字n和m,n代表进程的个数,m代表资源的个数。现在题目要求你输入4个部分:1.n和m2.当前每个进程所含有的资源数,注意这里行为资源,列为进程3.每个进程每次执行所需要的资源数4.当前操作系统所拥有的资源现在要你模拟银行家算法,分析是否能把所有的进程跑完,如果能就Yes,否则No解析:银行家算法的步骤:每次查找所需要没有用过的进程,并原创 2014-11-18 20:12:21 · 1084 阅读 · 0 评论 -
CodeForces - 63C Bulls and Cows(暴力求解)
Bulls and CowsTime Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64uDescriptionThe "Bulls and Cows" game needs two people to play. The thinker thi原创 2014-09-25 18:43:42 · 1343 阅读 · 0 评论
分享