【规律】Gym 100739L Many recursions】的更多相关文章

给出a,求递归式g(k)的初始条件g(0); 可以看出来g(a) = 1,从后往前推.写个模拟程序可以看出来其实g(0) = 2^a,那么就是一个简单地快速幂取模问题了. #include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstring> #include <cstdlib> #include <string&g…
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description Sonny uses a very peculiar pattern when it comes to playing rock-paper-scissors. He likes to vary his moves so that his opponent can't beat him with hi…
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description you the conditions of this task. There are 3 pivots: A, B, C. Initially, n disks of different diameter are placed on the pivot A: the smallest dis…
题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices seems to be very important as it represents the unholytrinity (Satan, the Antichrist and the False Prophet bringing mankind to the New World Order with…
Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white balls on a table in two rows, making a nice 2-by-N rectangle. Jon has a big paint bucket full of black paint. (Don't ask why.) He wants to paint all the b…
B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Description The swamp looks like a narrow lane with length n covered by floating leaves sized 1, numbered from 1 to n with a fly sitting on the top of ea…
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/D Description You invented a new chess figure and called it BOPC. Suppose it stands at the square grid at the point with coordinates …
题目: Description standard input/outputStatements Little Liesbeth likes to play with strings. Initially she got a string of length n, consisting of letters 'a' only. Then Liesbeth performs next operations with the string: If the first letter of the str…
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5919 题意: 给出正整数 $N(1 \le N \le 10^5)$,询问对于正整数 $k$,有多少个小于 $2^N$ 的 $2^k-1$ 是 $7$ 的整数倍. 题解: $…
https://vjudge.net/problem/Gym-101147A 题意:给出G组数,每组数包括两个数B,N,两玩家轮流取数,使得N-num,num<=N并且num是N的整次幂.判断谁赢. 思路:这道题目数据量很大,直接打表是不行的. 我们可以打一些数据出来观察一下,找一下规律. 规律是这样的: 如果B为奇数,那么SG函数0,1间隔出现. 如果B为偶数,你可以每B+1个数观察一下规律. 具体可以自己打个数据看一下. #include<iostream> #include<…
题目链接:https://cn.vjudge.net/contest/273377#problem/C 给你 n,m,k. 这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列的长度至少为n-1的排列组合的个数. 具体方法:打表找规律. 打表代码: #include<bits/stdc++.h> #include<string> #include<cstring> #include<stdio.h> using namespace s…
题意:给你一个经典的汉诺塔递归程序,问你最少几步使得三个柱子上的盘子数量相同.(保证最开始盘子数量可以被3整除) 规律:ans(n)=2^(2*n/3-1)+t(n/3). t(1)=0. t(n)= t(n-1)+1,n为偶数 t(n-1)*4+2,n为奇数. Java文件读写主要有以下两种方法,第二种,输出格式更随心所欲,更实用: import java.util.*; import java.io.*; import java.math.*; public class Main{ publ…
二维下,如果把杨辉三角按照题目里要求的那样摆放,容易发现,第i行第j列的数(从0开始标号)是C(i+j,i)*C(j,j). 高维下也有类似规律,比如三维下,最后一层的数其实是C(i+j+k,i)*C(j+k,j)*C(k,k). 题目提示你了,坐标组合相同的位置,其值一定相同. 于是dfs最后一层的序号组合,统计答案即可.我只加了一个可行性剪枝,应该还能加一个的. #include<cstdio> #include<set> using namespace std; typede…
以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; int T,N,B,n; int main() { freopen("powers.in","r",stdin); scanf("%d",&T); for(;T;--T) { int ans=0; scanf("%d",&a…
题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,,最后十分钟没辙了,队友站在一起,猜,猜一个规律出来,emmm,比赛半路中不经意听到旁边打过这场EC-final现场赛的学长说这题打表找规律,还在对面A题后讨论中听到16和偶数,嘿嘿,于是迫不得已猜规律,比赛还剩三十秒时交上去第三个规律,就,,,就A了,,,和另一位队友逗比的叫了起来,emmm,感觉r…
乍一看很唬人,草稿纸上多写几个发现规律:两个元音算一层,像剥洋葱一样,外面的其实都动不了,能变顺序的只有最里层的辅音. inline bool ok(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'; } int main() { cin >> str; for (int i = 0; i < str.length(); i++) { if (ok(str[i])) v.push…
题意:你用k 个生成树构成一个完全图. 析:n 个点的完全图有n(n-1)/2个边,一个生成树有n-1个边,你有k 个生成树 即边数等于 K(n-1) ,即  n(n-1)/2 == k(n-1)   n = 2*k 所以2k 个边足够,你会发现在每个结点只能做一次开头或者结尾.然后找找规律就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include…
题目:链接 思路: 多画出几个情况就可以找出规律来了 Knight (当大于2的时候只要两种颜色相间出现就可以了) King(当大于等于3的时候,总可以用四种形式来补色,具体如下)  Bishop(斜率为一的斜着的一行要不能相同,那只能是一列一个颜色了) Rook(要想水平竖直的颜色不一样,那只能是斜着的一行的颜色是一样的) 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f using namespace std; typedef long…
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0),(6,0),(1,sqrt(3)),(3,sqrt(3)),(5,sqrt(3)),(2,2*sqrt(3))...)这样 然后枚举三点算 打出来1,5,15,70,126,210,330,495,715,1001,1365,1820,2380,3060,3876 队友是插值法找的,我是纯找规律的,因为看…
题意:n个点,给定起点和终点,可以每次可以走一格或两格,走一格则需要一个代价,每个格子只能走一次,问从起点到终点并经过每一个点的最小代价 思路:这题我没看出什么道理,先打了个暴力,结果发现了个相当坑的规律,,然后就过了. #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque&…
D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/D Description Exactly N years ago, a new highway between two major cities was built. The highway runs from west to east. It…
这个题目的做法不止一种,solve1:每个数字使用的火柴棒都在2~7之间,而且是连续的,就是2-7之前没有空着的数.这样就有一个结论,在下界为l,上界为r的情况下,假设有n个数,那么火柴棒总数一定在n*l 与n*r之间,首先容易想到这个问题肯定是只关心火柴棒的总数,然后就是一个重新组合的问题,假设第一个重组后的数消耗了x个火柴棒,那么剩下的sum-x如果在(n-1)*l 与 (n-1)*r之间,那么一定可以组合成n-1个数,且最后正好用光,条件是数字必须连续,为什么读者可以自己举样例. 这样从9…
传送门:点我 Time limit2000 ms Memory limit262144 kB Recently Monocarp has created his own mini-laboratory! The laboratory contains nn bacteria. Monocarp knows that he can merge any two bacteria having equal sizes, and the resulting bacterium will have the…
题意:问你n*n的国际象棋棋盘上放3个互不攻击皇后的方案数. oeis……公式见代码内 //a(n) = 5a(n - 1) - 8a(n - 2) + 14a(n - 4) - 14a(n - 5) + 8a(n - 7) - 5a(n - 8) + a(n - 9) //0, 0, 0, 0, 24, 204, 1024, 3628, 10320, 25096, 54400, 107880 //package acm; import java.util.*; import java.io.*…
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from the Petrozaporksk training camp. There, he learned a lot of things: how to boil a cob, how to scratch his belly using his keyboard, etc... He almost r…
题意: 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + - + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5=0+1+0+3+3=7 分析: K对根号k之后的值取模会有相同的商出现,且具有相同的商的余数呈等差数列. #include <bits/stdc++.h> using namespace std; typede…
比赛链接:http://codeforces.com/gym/100861 A模拟,注意两个特殊的缩写. #include <bits/stdc++.h> using namespace std; typedef pair<string, string> pss; const string MSU = "MSU"; const string SCH = "SCH"; ; map<string, int> school; int n…
C. Sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit…
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds memory limit per test 256 megabytes input army.in output standard output Bakkar is now a senior college student studying computer science. And as many…
http://codeforces.com/gym/101257/problem/B 题意:给出两棵叶子数一样的树,在将叶子合并之后,对这个图进行染色,相邻的结点颜色不能相同,问最少需要染的颜色数,并输出合并叶子的方案. 思路:画了好几个图找了下规律,发现对于任意一个这样的图,最多只需要染三种颜色,最少是染两种颜色. 如果合并后的图,每一条从一棵树的根节点走到另一棵树的根节点的路径长度的奇偶性相同,那么这个时候就是只需要染两种颜色. 剩下的情况就是染三种颜色了. 对于每棵树,随便找一个不是叶子结…