
数学-规律题
文章平均质量分 56
JeraKrs
本人目前就职于百度商业研发部,有需要内推的朋友简历可发我邮箱 jerakrs@qq.com
展开
-
hdu 5601 N*M bulbs(规律)
题目链接:hdu 5601 N*M bulbs代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main () { int n, m, s, cas; scanf("%d", &cas); while (cas--) { scanf("%d%d"原创 2015-12-26 22:05:35 · 1091 阅读 · 0 评论 -
uva 306 - Cipher(周期)
题目链接:uva 306 - Cipher题目大意:给出n,以及a1 ~ an, 然后给出k,若k不为0的话,会有一个字符串,按照给出的a方式编码k次,输出所得字符串。解题思路:这题和我刚做的一题有点像,uva 10205 - Stack 'em Up,不过那道题是用模拟的方式,这题刚开始用了模拟,结果超时了,后来想到说,因为a1 ~ an为不等的1~n,所以一定存在一个周原创 2013-11-10 16:38:19 · 2233 阅读 · 0 评论 -
uva 10900 - So you want to be a 2n-aire?(期望)
题目链接;uva 10900 - So you want to be a 2n-aire?题目大意:一个答题赢奖金的问题,玩家初始的金额为1,给出n,表示有n道题目,t表示说答对一道题目的概率在t到1之间,每次面对一道题,可以选择结束游戏,获得当前奖金;回答下一道问题,答对的概率p在t到1之间,答对的话奖金翻倍,答错的话结束游戏,没有奖金,求玩家赢的奖金的期望值的最大值。解原创 2013-11-04 21:06:12 · 2164 阅读 · 0 评论 -
uva 12009 - Avaricious Maryanna(暴力)
题目连接:uva 12009 - Avaricious Maryanna题目大意;给定n,求x,x为n位数,并且x*x的后n位还是x。解题思路:打个表会发现其实有规律,除了n=1的时候多了0和1,其他都是n-1位的基础上再新增一位数,1位的时候是5,6.#include #include #include using namespace std;const int m原创 2014-07-08 20:18:31 · 1178 阅读 · 0 评论 -
uva 10623 - Thinking Backward(数学)
题目链接:uva 10623 - Thinking Backward题目大意:就是给出N,表示要将平面分解成N份,问有哪些可选则的方案,m表示椭圆、n表示圆形、p表示三角形的个数,m、n、p分别给定范围。解题思路:本来这题一点思路都没有,但是在论坛上看到一个公式N=2+2m(m−1)+n(n−1)+4mn+3p(p−1)+6mp+6np这样只要枚举m和p,求解n,判断n原创 2014-06-29 10:57:22 · 1250 阅读 · 0 评论 -
uva 10844 - Bloques(数论+高精度)
题目链接:uva 10844 - Bloques题目大意:给出一个n,表示有1~n这n个数,问有多少种划分子集的方法。解题思路:递推+高精度。11 22 3 55 7 10 1515 20 27 37 52dp[i][j]=dp[i−1][j−1]+dp[i][j−1]dp[i][0]=dp[i−1][i−1]ans[i]=dp[i][i]原创 2014-06-27 14:13:55 · 1233 阅读 · 0 评论 -
hdu 4828 Grids(拓展欧几里得+卡特兰数)
题目链接:hdu 4828 Grids题目大意:略。解题思路:将上一行看成是入栈,下一行看成是出栈,那么执着的方案就是卡特兰数,用递推的方式求解。#include #include typedef long long ll;const int N = 1000005;const ll MOD = 1e9+7;ll dp[N];ll extendGcd(ll a原创 2014-06-25 23:06:19 · 1057 阅读 · 0 评论 -
uva 10312 - Expression Bracketing(Catalan+SuperCatalan)
题目链接:uva 10312 - Expression Bracketing题目大意:给出一个序列,长度为n,表示有n个x(节点),可以添加任意括号,问说形成的串为非二叉表达式的有多少个。解题思路:直接求非二叉表达式是比较困难,所以换求总数减去二叉表达式的数量。二叉表达式的很容易发现是Catalan数,而总数时一种叫SuperCatalan数的一种序列,第一次接触。或者可以用dp做原创 2014-05-22 21:09:37 · 1390 阅读 · 0 评论 -
Codeforces 396B On Sum of Fractions(数论)
题目链接:Codeforces 396B On Sum of Fractions题目大意:给出一个n,ans = ∑(2≤i≤n)1/(v(i)*u(i)), v(i)为不大于i的最大素数,u(i)为大于i的最小素数, 求ans,输出以分式形式。解题思路:一开始看到这道题1e9,暴力是不可能了,没什么思路,后来在纸上列了几项,突然想到高中时候求等差数列时候用到的方法,具体叫原创 2014-02-27 22:12:27 · 1885 阅读 · 0 评论 -
uva 517 - Word(暴力+周期)
题目链接:uva 517 - Word题目大意:给出一个字符串,以及8种变换方式,问说该字符串变换s次后的结果,注意字符串为环形,输出字典序最小的情况。解题思路:因为字符串最长为15, 2^15#include #include #include using namespace std;const int N = 20;struct state原创 2014-01-27 23:56:23 · 1481 阅读 · 0 评论 -
uva 11549 - Calculator Conundrum(模拟)
题目链接:uva 11549 - Calculator Conundrum题目大意:给出n和k,表示有一个n为的计算器,现在要计算k一直平方中的最大值(在计算器中出现的),超过n位取前n位。解题思路:看队友题解上有一个判断说形成循环的条件a^2== b^4。然后模拟一下就可以了。#include #include #include using names原创 2014-01-23 18:08:58 · 1301 阅读 · 0 评论 -
Codeforces 493E Vasya and Polynomial(数学)
题目链接:Codeforces 493E Vasya and Polynomial#include #include #include using namespace std;typedef long long ll;ll t, a, b;int main () { scanf("%lld%lld%lld", &t, &a, &b); if (t == a) { if原创 2015-04-12 19:24:19 · 864 阅读 · 0 评论 -
Codeforces 493D Vasya and Chess(规律)
题目链接:Codeforces 493D Vasya and Chess#include #include #include using namespace std;int main () { int n; scanf("%d", &n); if (n&1) printf("black\n"); else printf("white\n1 2\n"); retur原创 2015-04-12 19:21:53 · 911 阅读 · 0 评论 -
hdu 5312 Sequence(数学)
题目链接:hdu 5312 Sequence#include #include #include #include using namespace std;const int maxn = 1e5 + 5;const int inf = 1e9;int N, nth[maxn];bool judge (int m) { for (int i = 1; i < N原创 2015-07-31 23:01:43 · 581 阅读 · 0 评论 -
hdu 5584 LCM Walk(规律)
题目链接:hdu 5584 LCM Walk代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }int main () { int cas; scanf("%d原创 2015-12-03 21:02:50 · 1305 阅读 · 0 评论 -
Codeforces 585C Alice, Bob, Oranges and Apples(规律)
题目链接:Codeforces 585C Alice, Bob, Oranges and Apples解题思路次数其实就是gcd过程,最后一次要减1。代码#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;typedef long long ll;ll x, y原创 2015-11-02 10:56:45 · 804 阅读 · 0 评论 -
hdu 4651 Partition(公式)
题目链接:hdu 4651 Partition解题思路本质上其实是一个完全背包,但是物品有1e5,所以复杂度太大。有一个五边形数的公式可以优化。代码#include <cstdio>#include <cstring>#include <algorithm>/* * 五边形数:f(n) = sum( (-1)^(k+1) [ P(n-k(3k-1)/2) + P(n-k(3k+1)/2)]原创 2015-10-30 23:29:38 · 724 阅读 · 0 评论 -
hdu 4696 Answers(规律)
题目链接:hdu 4696 Answers解题思路只要存在一个c为1的即所有m大于0的都可以构成,如果不存在c为1,则m为大于0的偶数可以构成代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main () { int n, m; while (scanf("%d%d"原创 2015-11-12 14:38:47 · 752 阅读 · 0 评论 -
hdu 5430 Reflect(数论)
题目链接:hdu 5430 Reflect解题思路反射m次,相当于形成一个n=m+1边形。对于每个n,考虑顺时针和逆时针绕圆心转了整数圈,并且每次反射角不能大于180度。假设饶了k圈,因为每个内角要小于180度,所以k肯定小于n/2,并且在发射m次之前不能回到起始点,所以k与n一定互质。那么问题就变成求小于n/2的数中有多少个数与n互质。代码#include <cstdio>#include <c原创 2015-10-11 21:33:20 · 639 阅读 · 0 评论 -
hdu 4611 Balls Rearrangement(规律)
题目链接:hdu 4611 Balls Rearrangement代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;int N, A, B;ll get(ll p) { int a = p % A; int b = p % B;原创 2015-10-26 21:34:02 · 664 阅读 · 0 评论 -
hdu 4658 Integer Partition(公式)
题目链接:hdu 4658 Integer Partition代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5 + 5;const int mod = 1e9 + 7;int f[maxn];void init () { f[0] = 1;原创 2015-11-06 21:30:33 · 659 阅读 · 0 评论 -
hdu 4664 Triangulation(博弈)
题目链接:hdu 4664 Triangulation解题思路根据SG定理打个表,SG值最多为9,前几项在SG值不全的时候没有规律,但是当SG值为9的出现后,以34为一循环。代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int sg[] = {0, 0, 1, 1, 2,原创 2015-11-06 21:37:26 · 703 阅读 · 0 评论 -
hdu 5439 Aggregated Counting(规律)
题目链接:hdu 5439 Aggregated Counting1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 .... 按照每个数出现的次数1出现了1次,2,3出现两次,以此类推,将次数取出作为序列,会发现对应的序列仍是 1 2 2 3 3 4 4 4 5 5 5 ....即原序列。第一次last我们可以根据前缀和求出,但是对于第二次la原创 2015-09-13 21:47:29 · 1017 阅读 · 0 评论 -
hdu 5292 Pocket Cube
题目链接:hdu 5292 Pocket Cube本来想用暴力,从还原的魔方出发,遍历出所有的可能。但是看了下官方题解,挺牛逼的。考虑每个颜色对(黄,白),对于顺时为+1,逆时位-1,原位置0。总和为3的倍数就是可以还原的,否则就是不能还原。连接#include #include #include using namespace std;const int bw[原创 2015-07-31 21:30:21 · 835 阅读 · 0 评论 -
uva 11986 - Save from Radiation(规律)
题目链接:uva 11986 - Save from Radiation题目大意:给出n,表示有n个无辐射的药,外加1个有辐射的药,小白 鼠若吃了有辐射的药,5分钟内会死亡,问说最少用几只小白鼠在5分钟内找出有毒的药。解题思路:2^m = n + 1。#include typedef long long ll;int main() { int cas;原创 2014-01-13 23:37:03 · 1211 阅读 · 0 评论 -
uva 11714 - Blind Sorting(推理)
题目链接:uva 11714 - Blind Sorting题目大意:给出n个数,每次可以比较两个数的大小,问,最坏请款需要需要几次比较可以得出最大的两个值。解题思路:首先类似淘汰赛的方式选出最大值,然后用非胜出方的子树根位置的值和胜出方所有各层败给最大值的数进行比较。ans = n - ceil(log2(n)) - 2.#include #include原创 2014-01-12 17:47:00 · 1905 阅读 · 0 评论 -
uva 1418 - WonderTeam(推理)
题目链接:uva 1418 - WonderTeam题目大意:你支球队进行比赛,每两支队伍之间进行2场比赛,胜得3分,平得1分,输得0分,比赛后挑选出一个梦之队,要求进球总数最多,胜利场数最多,失球总数最多,并且三种都不能与其它对比列第一。问说梦之队的最低可能排名。解题思路:n ≤ 3时ans = 1;n == 4时,ans = 2;n>4时,ans = n.n ≤2的原创 2013-12-20 13:55:25 · 2326 阅读 · 0 评论 -
uva 10519 - !! Really Strange !!(规律)
题目链接:uva 10519 - !! Really Strange !!题目大意:给出n,问用n个圆最多能将平面分割成几份。解题思路:公式c[i] = i * i - i + 2,首先可以分析出c[i] = c[i - 1] + 2 * i - 2, 然后带入c[i - 1] = c[i - 2] + 2 * (i - 1) - 2,重复带入可得c[i] = c[1]原创 2013-11-02 17:26:56 · 1352 阅读 · 0 评论 -
uva 10918 - Tri Tiling(规律)
题目链接:uva 10918 - Tri Tiling题目大意:给出n,计算用1*2的瓷砖有多少种方法铺满3*n的地方。解题思路:和uva 10359 - Tiling有点相似,不过难度会比较大,公式c[i] = 4 * c[i - 2] - c[i - 4].推导过程:c[0] = 1, c[2] = 3, c[4] = c[2] * 3 + c[1] * 2, c[原创 2013-11-01 17:02:57 · 1960 阅读 · 0 评论 -
uva 10359 - Tiling(规律)
题目链接:uva 10359 - Tiling题目大意:有两种瓷砖1*2和2*2的若干个(无限),给出n,问有多少种方法将2*n的面积铺满。解题思路:cnt[i] = cnt[i - 1] + 2 * cnt[i - 2], 大数。#include #include #define ll long long#define max(a, b) (a)>(原创 2013-11-01 16:54:43 · 1791 阅读 · 0 评论 -
uva 696 - How Many Knights
题目链接:uva 696 - How Many Knights题目大意:给出一个n * m的网格,计算最多可以放置几个国际象棋中的骑士。解题思路:分成三类来讨论:1)min(n, m) == 1, 也就是无论怎么摆也不会影响到其他的骑士。2)min(n, m) == 2, 这是将网格将网格分成2*4的若干部分,每个部分的前半部分放置骑士,主要注意模4后剩余部分的处理原创 2013-10-31 08:32:37 · 2425 阅读 · 0 评论 -
uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有。解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~9划分(只会有这几种情况)。#include #define ll long longll ans;ll f(ll x) { if (x == 0) re原创 2013-10-31 00:23:21 · 1897 阅读 · 0 评论 -
uva 10940 - Throwing cards away II
题目链接:uva 10940 - Throwing cards away题目大意:给出n,表示有n张牌,按照1~n的顺序排列,每次取出顶部的两张牌,第一张丢掉,第二张放到牌堆的最底部,问最后剩下的那张牌是多少。解题思路:可能我的思路有点难理解,我不是通过打表找规律去推公式, 而是模拟了人的思维去处理这个牌的问题,首先第一次为n张牌,第一遍丢牌肯定是奇数牌,所以可以将所有的偶原创 2013-10-30 15:11:03 · 1454 阅读 · 0 评论 -
uva 571 - Jugs
题目链接:uva 571 - Jugs题目大意:给出A,B和aid,A表示小杯的容量,B表示大杯的容量,aid表示要求大杯中剩余的水量,有无限的水,给出方案,(A和B互质)解题思路:A和B互质就说明了一定有解,因为它们的最大公约数为1。然后方案无非就是有四步组成,考虑清楚四总移动的条件就可以了。#include #define max(a,b) (a)<(原创 2013-10-25 09:14:53 · 1325 阅读 · 0 评论 -
hdu 4706 Children's Day(找规律)
题目大意:4706 Children's Day、题目大意:用a~z写出大小为3~10的N。解题思路:找规律。#include const int N = 26;int solve(int n, int c) { int dist = 2 * (n - 1); for (int i = 0; i < n; i++) { for (int原创 2013-09-08 20:35:26 · 1041 阅读 · 0 评论 -
hdu 4710 Balls Rearrangement
题目连接:4710 Balls Rearrangement题目大意:给出N, A 和B。N 代表有N个球, 原本N个球放在旧的A个箱子里面, 后来又买了B个新的箱子, 求要将N个球转移到新的箱子中需要多少移动距离。 放球的原则是 序号为 x 的球要放在 x mod A(或者B)序号的箱子里, 对于每个球的移动距离为| a - b |。解题思路:因为N的上限是10^9, 所原创 2013-09-08 21:01:04 · 1143 阅读 · 0 评论 -
uva 10706 Number Sequence(数学规律)
题目连接:10706 - Number Sequence题目大意:有一个有0 ~ 9组成的序列,1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 。。。。就是第一位为1. 第二为为1 ,第三为为2, 然后10 的部分注意下, 为1 和0 两个, 100 就是1 , 0和0 三位,以此类推, 要求给出tmp, 输出序列中的tmp位为什么数字。解题原创 2013-08-25 16:07:40 · 1161 阅读 · 0 评论 -
uva 846 Steps(数学规律)
Steps One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the原创 2013-07-31 11:04:51 · 1638 阅读 · 0 评论 -
uva 10025 The ? 1 ? 2 ? ... ? n = k problem(算式规律)
The ? 1 ? 2 ? ... ? n = k problem The problemGiven the following formula, one can set operators '+' or '-' instead of each '?', in order to obtain a given k? 1 ? 2 ? ... ? n原创 2013-07-31 10:20:43 · 1611 阅读 · 0 评论 -
uva 10862 - Connect the Cable Wires(规律)
题目连接:uva 10862 - Connect the Cable Wires递推公式:c[i] = 3 * c[i - 1] - c[i - 2],大数,直接拷模板了。#include #include #include using namespace std;const int N = 1005;const int M = 2005;struct b原创 2013-11-02 17:10:33 · 1494 阅读 · 0 评论