UVA 12520 Square Garden】的更多相关文章

https://vjudge.net/problem/UVA-12520 题意:n*n网格中染色m个格子,染色格子的最长轮廓线 贪心 将格子分为4类 1.隔一个选一个,互不相邻的格子 2.4个角上的格子 3.边界除角的格子 4.内部的格子 4类从上到下依次选 1对答案有4的贡献 2对答案无贡献 3对答案有-2的贡献 4对答案有-4的贡献 对n奇偶分类讨论 当n为奇数时,在分左上角的格子在第1类还是第2类讨论 #include<cstdio> #include<algorithm>…
UVA 11542 - Square 题目链接 题意:给定一些数字.保证这些数字质因子不会超过500,求这些数字中选出几个,乘积为全然平方数,问有几种选法 思路:对每一个数字分解成质因子后.发现假设要是全然平方数,选出来的数字的每一个质因子个数都必定要是偶数,这样每一个质因子能够列出一个异或的方程,假设数字包括质因子,就是有这个未知数,然后进行高斯消元,求出自由变量的个数,每一个自由变量能够选或不选.这种情况就是(2^个数),然后在扣掉什么都不选的1种就是答案了 代码: #include <cs…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题意 输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数.直到输入0 0时程序结束 分析: 如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6. 下面给出AC代码: #include <bits/stdc++.h&…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题目大意: 给出两个数a,b(a<=b<=100000),求在a和b之间有多少个完全平方数(包括a和b) 思路: 打表啊打表. #include<cstdio> #include<cstring> #include<cmath> cons…
题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数,那么每个质因数上的指数为偶数,x1系数为2已经是偶数不考虑.可以转换为异或为0判断偶数,即奇数置为1,偶数置为0,然后n个数字m个质因数的增广矩阵消元看有几个自由变量(取0或1无所谓),答案是2^r - 1(全部都不取方案不算) #include <bits/stdc++.h> const in…
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std; #define LL long long #define MOD 1000000007 ]; int judge(in…
题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, b, t; memset(on,,sizeof(on)); ;i<=;i++) on[i*i] = ; while(~scanf("%d%d", &a, &b)) { t=; &&b==) break; for(i=a;i<=b;i++) {…
题意: 给定一个火柴棒拼成的方格阵,然后去掉一些火柴棒,问至少再去掉几根火柴棒能够让图中一个正方形都没有. 思路: 1. 由于题目中给定了 n 的范围,2 * n * (n + 1) <= 60 -> 所以能够保证所有的火柴用 long long的位运算表示; 2. 启发式函数 h 的计算需要考量:如果删除了某个方阵的一个边,则能够保证 h(s1) <= h(s2) + C(s1, s2),其中 C(s1, s2) = 1,h(s1) - h(s2) <= 1; 3. 各种位运算的…
[题目分析] 每个数没有超过500的因子.很容易想到把每一个数表示成一个二进制的数. (0代表该质数的次数为偶数,1代表是奇数) 然后问题转化成了选取一些二进制数,使他们的异或和为0. 高斯消元,2^(自由元)即为答案,需要把空集的情况减去,所以减一. 然而发现并不需要知道哪些是自由元,所以只需要用线性基去维护即可. 然后代码就呼之欲出了. [代码] #include <cstdio> #include <cstring> #include <cmath> #inclu…
题意:给定 n 个数,从中选出一个,或者是多个,使得选出的整数的乘积是完全平方数,求一共有多少种选法,整数的素因子不大于 500. 析:从题目素因子不超过 500,就知道要把每个数进行分解.因为结果要是完全平方数,也就是说每个素因子都得出现偶数次,对于每个数我们用一个 01 向量来表示,对于这个数相应的素因子,如果出现奇数就是 1,否则就是 0,这样就可以得到一些方程,比如举个例子. 4 个整数, 4 6 10 15 ,素因子只有 2 3 5,4 = 2 ^ 2 * 3^0 * 5^0,对于每个…
题目链接 给你一个n*n的由火柴组成的正方形网格,从中预先拿掉一些火柴,问至少还需要拿掉多少火柴才能破坏掉所有的正方形. 看到这道题,我第一反应就是——把每根火柴和它能破坏掉的正方形连边,不就是个裸的DLX了吗?二话不说直接把我以前写过的DLX板子拿了过来.不过这个问题是可重复覆盖而不是精确覆盖,其实只需要在精确覆盖的基础上稍作修改就行了. 建图方法:枚举出网格完整时所有的火柴和正方形,给它们编上号,除了被拿掉的火柴和已经被破坏掉的正方形,其余的所有火柴和它能破坏掉的正方形连边. 注意跑DLX前…
题目中说数组中的数的最大质因子不超过500,我们筛出≤500的质数,然后考虑对每个质数列一个方程组.. 然后这几乎就是高斯消元求解异或方程组的模板题了.... 注意答案是 2^(自由元数量)-1,因为空集不是答案的一部分.. #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring>…
题目链接:点击打开链接 白书的例题练练手. . . P161 #include <cstdio> #include <iostream> #include <algorithm> #include <math.h> #include <string.h> #include <algorithm> using namespace std; #define ll int #define LL long long const int mod…
题目:在一个2n*2n的网格中间画一个直径为2n-1的圆,问圆内部的格子以及和圆相交的格子个数. 思路:只要考虑1 / 4圆的点就行,用点到原点距离与半径比较,当格子左下方和右上方都在格子里时,格子在圆内部. AC代码: #include<bits/stdc++.h> using namespace std; int sqr(int n, int m) { return m * m + n * n; } int main() { int n; ; while(cin >> n) {…
Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. The field is divided into square garden beds, each bed takes up one square meter. Old McDonald knows that the Colorado potato beetle is about to invade…
这次突然打算写点dimension reduction的东西, 虽然可以从PCA, manifold learning之类的东西开始, 但很难用那些东西说出好玩的东西. 这次选择的是一个不太出名但很有趣的方法, 随机映射. 但某些地方它一直是被当成LSH方法来介绍的, 关于这点我不想过多追究, 这里我认为他是一个降维. Problem Statement 首先我们来看一个问题, 如果你手头有一组数据$X \in R^n$, 它的维数太高, 从而不得不进行降维至$R^k$, 你会怎么办? 相信不少…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515 11520 - Fill the Square Time limit: 1.000 seconds In this problem, you have to draw a square using uppercase English Alphabets. To be more prec…
UVA 1426 - Discrete Square Roots 题目链接 题意:给定X, N. R.要求r2≡x (mod n) (1 <= r < n)的全部解.R为一个已知解 思路: r2≡x (mod n)=>r2+k1n=x 已知一个r!,带入两式相减得 r2−r12=kn => (r+r1)(r−r1)=kn 枚举A,B,使得 A * B = n (r + r1)为A倍数 (r - r1)为B倍数 这样就能够推出 Aka−r1=Bkb+r1=r => Aka=Bk…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515 题意 n*n矩阵中填入大写字母,n <= 10,要求从上到下从左到右字母序最小,相邻格子字母不同 思路 如刘书思路,状态比较小,不会导致矛盾. 感想 1. 状态较小 代码 #include <algorithm> #include <cassert>…
在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小. 直接暴力走起就OK.因为,需要填的格子最多就是 A.B.C.D.E 这五个字母.所以直接暴力也就 O(n2) 因为要保证字符串的字典序最小,所以就从第一行第一列开始,一行一行的暴就搞定了.其他的就不说了,简单的水题. 附AC代码: 1: #include <s…
书上分析的太清楚,我都懒得写题解了.=_=|| #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; ; ; ]; ; void Init() { int m = sqrt(maxn + 0.5); ; i <= m; i++) if(!vis[i]) for(int j = i*i; j <= maxn; j…
题意:给定 x,n,r,满足 r2 ≡ x mod(n) ,求在 0 ~ n 内满足 rr2 ≡ x mod(n) 的所有的 rr. 析:很明显直接是肯定不行了,复杂度太高了. r2 ≡ x mod(n)  (1) rr2 ≡ x mod(n)  (2)用 (2)- (1)得到 rr2 - r2 ≡ 0 mod (n) (rr + r)*(rr - r) ≡ 0 mod (n), 可以得到 (rr + r)*(rr - r) = k * n. 假设  n = a * b, 那么 可以知道 (rr…
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cma…
题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <ios…
题意:给出 n*n的格子,把剩下的格子填上大写字母,使得任意两个相邻的格子的字母不同,且从上到下,从左到右的字典序最小 从A到Z枚举每个格子填哪一个字母,再判断是否合法 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include&l…
题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也就是$O(26\times n^2)$. 注意此题中的输入输出有点bug,可以把每一行看成一个字符串进行输入输出(因为其中并没有空格). AC代码: #include<cstdio> #include<iostream> using namespace std; int n; ][];…
10798 - Be wary of Roses You've always been proud of your prize rose garden. However, some jealous fellow gardeners will stop at nothing to gain an edge over you. They have kidnapped, blindfolded, and handcuffed you, and dumped you right in the middl…
Cellular automata are mathematical idealizations of physical systems in which both space and time are discrete, and the physical quantities take on a nite set of discrete values. A cellular automaton consists of a lattice (or array), usually in nite,…
Pashmak and Garden Codeforces Round #261 (Div. 2) A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak has fallen in love with an attractive girl called Parmida sin…
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes…