UVA Don't Get Rooked】的更多相关文章

主题如以下:  Don't Get Rooked  In chess, the rook is a piece that can move any number of squaresvertically or horizontally. In this problem we will consider smallchess boards (at most 44) that can also contain walls through whichrooks cannot move. The goa…
题目:跟N皇后问题一样,不考虑对角冲突,但考虑墙的存在,只要中间有墙就不会冲突. N皇后一行只能放一个,而这题不行,所以用全图暴力放棋,回溯dfs即可,题目最多就到4*4,范围很小. 刚开始考虑放一个棋子后就把其他不能放的地方标记下,然后再暴力,后来发现如果一个点重复标记在去标记时就会把点标成合法的,于是改用放棋子是进行检查,由于数据量小,也不会占用多少时间. 之后才想到,在标记时可以用累加的,去标记时再一个一个减下来即可... 代码: #include <cstdio> const int…
Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all…
UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=599&problem=757&mosmsg=Submission+received+with+ID+14332151" target="_blank" style="">题目链接 题意:一个迷宫,每一个点限制了从哪一方向来的.仅仅能往左右前…
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪(没有计算机有该项服务). 思路:(见大白70页,我的方程与大白不同) 把n个集合P1.P2.Pn分成尽量多的组,使得每组中全部集合的并集等于全集,这里的集合Pi是计算机i及其相邻计算机的集合,用cover[i]表示若干Pi的集合S中全部集合的并集,dp[s]表示子集s最多能够分成多少组,则 假设co…
偶数时,中位数之间的数都是能够的(包含中位数) 奇数时,一定是中位数 推导请找初中老师 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; int box[1000000]; int main() { //freopen("in","r"…
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: #include <stdio.h> #include <string.h> long long a, p; long long pow_mod(long long x, long long k, long long mod) { long long ans = 1; while (k…
UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) 分, 而且每一份的长度都为 L / gcd(l,k).因此平方对于奇数长度不变,偶数则会分裂成两份长度同样的循环,因此假设B中偶数长度的循环个数不为偶数必定不存在A了 代码: #include <stdio.h> #include <string.h> const int N = 30…
UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,例如以下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cel…
题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap−12≡1%p #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll pow_mod (ll a, ll n, ll mod) { ll ans = 1; while…
题目例如以下: The Sultan's Successors  The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoever performs best at some test. Itis possible for an…
UVA 12436 - Rip Van Winkle's Code option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=3867&mosmsg=Submission+received+with+ID+14331401" target="_blank" style="">题目链接 题意:区间改动一个加入等差数列,一个把区间设为某个…
UVA 11888 - Abnormal 89's option=com_onlinejudge&Itemid=8&page=show_problem&category=524&problem=2988&mosmsg=Submission+received+with+ID+14075396" target="_blank" style="">题目链接 题意:给定一个字符串.推断类型.一共三种.两个回文拼接成的,…
UVA 1397 - The Teacher's Side of Math 题目链接 题意:给定一个x=a1/m+b1/n.求原方程组 思路:因为m*n最多20,全部最高项仅仅有20.然后能够把每一个此项拆分.之后得到n种不同无理数,每一项为0.就能够设系数为变元.构造方程进行高斯消元 一開始用longlong爆了.换成分数写法也爆了,又不想改高精度.最后是机智的用了double型过的,只是用double精度问题,所以高斯消元的姿势要正确,而且最后输出要注意-0的情况 代码: #include…
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2925" style="color:rgb(0,136,204); text-decoration:none">11825 - Hackers' Crackdown 题意:  有一个由编号0~n-1的n台计算机组成的网络,一共…
题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总和必须在[L,R]之间,求终于这条路径的权值. 思路:树形dp,dp[u]表示在u结点的权值,往下dfs的时候顺带记录下到根节点的权值总和,然后假设dp[v] + w + sum 在[l,r]内,就是能够的,状态转移方程为 dp[u] = max{dp[v] + w }(bob) dp[u] = m…
Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time Limit: 5 seconds Memory Limit: 32 MB You are given a collection of books, which must be shelved in a library bookcase ordered (from top to bottom in t…
这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include <stdlib.h> int vis[100][100];//刚開始wrong的原因就是这里数组开小了,开了[8][8],以为可以.后来看到[cur-i+8]意识到可能数组开小了.改大之后AC. int a[8][8]; int C[10]; int max_,tot; void search_(int…
Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below…
这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 << pos)); 将s中二进制第k位变成1的处理方式: s = s | (1 << pos); 2.二进制运算: [1] & : 1 & 1 = 1 , 1 & 0 = 0 , 0 & 0 = 0; 高速推断奇偶性: if(a & 1);//为奇数…
是典型的bfs,但是,这个问题的目的在于读取条件的困难,而不是简单地推断,需要找到一种方法来读取条件.还需要想办法去推断每一点不能满足条件,继续往下走. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<iostream> #include<algorithm> using namespace std; struct note {…
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his book…
称号:区区女性有父亲和母亲,区区无人机只有一个母亲,我问一个单纯的无人机第一n随着祖先的数量. 分析:递归.Fib序列. 状态定义:建立f(k)和m(k)分别用于第一k雌蜂和雄蜂的数量: 递推关系:f(k)= f(k-1)+ m(k-1)和 m(k)= f(k-1): 递推整理:f(k)= f(k-1)+ f(k-2):f(1) = 1:f(2)= 2: 说明:使用long long防止溢出. #include <algorithm> #include <iostream> #in…
出发dp,用在一些议题的操作非常~  给出s个课程.m个教师.n个求职者,教师必须招聘.然后招聘一些求职者,使得每一门课都至少有两个老师能教.问题就转换成了招聘哪些求职者使得花费最少.由于s范围小于8.则能够用二进制表示,用集合s1表示恰好有一个人教的课的集合,用集合s2表示有两个人教的课的集合,则每次状态转移即为选择这名求职者还是不选(教师必须选)详细看代码. d(i,s1,s2) = min{ d(i+1,s1',s2')+c[i],d(i+1,s1,s2)} 第一项表示聘用,第二项表示不聘…
称号:给你一个行长度的建设和高度,我们祈求最长的和下降的高度. 分析:dp,最大上升子. 说明:具有长度,不能直接优化队列单调. #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int h[2000],w[2000],u[2000],l[2000]; int main() { int T,n; while (~scanf("%d",&T…
Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequired to perform three types of update operations (A, B, C), and one query operation S over an arraydata[]. Initially all elements of data are equal to 0…
Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ith job, it is known the integer Ti (1<=Ti<=1000), the time in days it takes the shoemaker to finish the jo…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAncAAAN5CAYAAABqtx2mAAAgAElEQVR4nOy9sY4jydKezVuoayhH0r…
题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的高度去匹配側视求最大 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAXN = 1000…
n!=x*b^y, 当x为正整数时,最大的y就是n!末尾0的个数了, 把n,b分别拆成素因子相乘的形式: 比如, n=5,b=16 n=5,b=2^4, 非常明显,末尾0的个数为0 10进制时,n!=a*10^x b进制时,n!=c*b^y 非常明显,n!的位数就是最大的x+1 这里计算我用了log,精度设置为1e-9 #include<iostream> #include<cstdio> #include<vector> #include<cstring>…