思路:很容易发现规律,数列和Fib数列一样的. 记开始的时候啊a的个数为Y,b的个数为X.建立矩阵. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define M 105 #define eps 1e-6 #define ll long long #define mod 1000000007 usi…
1052 - String Growth    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Zibon just started his courses in Computer science. After having some lectures on programming courses he fell in love with strings. He started to play…
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r++; printf("Case %d: %d\n",++kas,r); } ; } LA 3602 DNA Consensus String 贪心构造,每一位上选出现次数最多的. #include<bits/stdc++.h> using namespace std; ,ma…
UVA 1386 - Cellular Automaton option=com_onlinejudge&Itemid=8&page=show_problem&category=489&problem=4132&mosmsg=Submission+received+with+ID+13911770" target="_blank" style="">题目链接 题意:给定一个n格的环,如今有个距离d.每次变化把环…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1620 ProblemG ILove Strings!!! Input:Standard Input Output:Standard Output TimeLimit: 4 Seconds Hmmmmmm----strings again :) Then it must be an easy…
给你一个 n * n 的 01 矩阵,现在你的任务是将这个矩阵中尽量少的 0 转化为 1 ,使得每个数的上下左右四个相邻的数加起来是偶数.求最少的转化个数. 首先,n 的规模并不大,最大只有15.但是完全枚举整个矩阵显然是不可能的(2225 ≈ 5 * 1067).但是我们可以枚举第一行,然后用第一行来算出后面的所有行. 但是,怎么算呢? 先来说下算法.对于每一行,我们通过他上面的两行来决定他的值.如果上面两行得到值为奇数,那么这一行就赋值为 1 ,否则赋值为 0 . 然后与原始矩阵比较,如果是…
UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: #include <cstdio> #include <cstring> const int N = 45; int n, k; struct mat { int v[N][N]; mat() {memset(v, 0, sizeof(v));} mat operator * (ma…
https://vjudge.net/problem/UVA-1626 题意: 输入一个由 "(" . ")" . "[" . "]" 构成的序列,添加尽量少的括号,得到一个规则序列. 思路: d[i][j]表示 i~j 需要添加的最少个数,具体看代码吧,我也只是看着刘汝佳的代码写的 . #include<iostream> #include<algorithm> #include<string&…
题意:求A + A^2 + A^3 + ... + A^m. 析:主要是两种方式,第一种是倍增法,把A + A^2 + A^3 + ... + A^m,拆成两部分,一部分是(E + A^(m/2))(A + A^2 + A^3 + ... + A^(m/2)),然后依次计算下去,就可以分解,logn的复杂度分解,注意要分奇偶. 另一种是直接构造矩阵,,然后就可以用辞阵快速幂计算了,注意要用分块矩阵的乘法. 代码如下: 倍增法: #pragma comment(linker, "/STACK:10…
题目连接:uva 11885 - Number of Battlefields 题目大意:给出周长p,问多少种形状的周长为p的,而且该图形的最小包围矩阵的周长也是p,不包含矩形. 解题思路:矩阵高速幂.假设包括矩形的话,相应的则是斐波那契数列的偶数项,所以相应减去矩形的个数就可以. #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const ll MOD = 987654…