- 博客(25)
- 资源 (2)
- 收藏
- 关注
原创 toj1339
/* 要求两步差最多为1, 那么很容易想到序列应该是先增后减的。 关注以下序列: 1 1 1 1 2 1 1 2 2 1 1 2 3 2 1 1 2 3 3 2 1 ... 和分别为1,2,4,6,9,12... 很容易想象,如果两数之差为10(上述9,12间),只需要判断9和12对应的两个序列即可: 1 2 3 2 1......9 1 2 3 3 2 1....12
2014-08-28 13:08:39 554
原创 [toj1136]Humble Number
题意: 质因数除1外最多只有2,3,5,7的数叫Humble Number,输入n,输出第n个Hunble Number.解法:预处理出2,3,5,7的幂(2,4,6,8...3,9,27,81...等),放在四个数组中,然后滚动分配2,3,5,7的指数即可(0~...),把INT范围内的都处理出来扔进vector中排序即可.复杂度O_O(就是没甚么复杂的...)防溢出,最好用long l
2014-08-13 18:38:12 577
原创 [toj4087]m个不同的箱子放n种不同的球
首先有个三角关系:11 11 3 11 7 5 11 15 17 7 1..递推为f[i][j] = j*f[i-1][j] + f[i-1][j-1]上述是第二类斯特灵数的地推关系第二类斯特灵数描述的问题类似于:m个相同的箱子放n种不同的球,那么分法如上述.如果箱子不同,那么先对箱子排列,所以答案为ans(n,m) = m! * f[n][m]而本题就
2014-08-13 11:08:06 939
原创 [poj3356]字符串dp
/* * dp[i][j]:str1的前i个构成的串变成str2前j个构成的串需要的最少步数 * dp[i][j] = min{ * dp[i-1][j-1]+(str1[i]==str2[j]?0:1) -> 改变 * dp[i-1][j] + 1 -> 删除str1第i个字符 * dp[i][j-1] + 1 -> 添加str2第j个字符到str1的第i个位置 *
2014-08-11 21:41:01 774
原创 [poj3356]字符串dp..2014.8.11
/* * dp[i][j]:str1的前i个构成的串变成str2前j个构成的串需要的最少步数 * dp[i][j] = min{ * dp[i-1][j-1]+(str1[i]==str2[j]?0:1) -> 改变 * dp[i-1][j] + 1 -> 删除str1第i个字符 * dp[i][j-1] + 1 -> 添加str2第j个字符到str1的第i个位置 *
2014-08-11 21:40:02 663
原创 [zoj3314]CAPTCHA炒鸡大模拟
/* * 炒鸡大模拟.整体思想是读入数据后从上往下,从左往右扫描一遍,同时vis数组标记是否访问过,对于没有访问过且为'M'的点,就可以认为 * 它是某个字母的组成部分了,因为组成每个字母的'M'间都是"邻居",所以从发现的这个'M'开始一次BFS/DFS就可以得到和这个'M'相连的 * 所有'M',他们的个数也就是组成这个字母的'M'的个数喽.所以我们需要预处理每个字母对应由几个'M'组成
2014-08-09 21:42:35 691
原创 [zoj3314]CAPTCHA超级大模拟2014.8.9
#include #include #include #include using namespace std;const int MAX = 400;char str[MAX][MAX];int n, m;bool vis[MAX][MAX];int eight[8][2] = {-1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1};
2014-08-09 21:07:44 612
原创 慎用mmap[key]!!!
#include #include #include using namespace std;#include int main() { map mmap; cout << "Before test: "; for (map::iterator it = mmap.begin(); it != mmap.end(); ++it) cout first << " "; co
2014-08-08 16:04:02 706
原创 [toj2858]Puzzle Game全排列枚举
题目大意:给一个`4*4`的方格,内有4种字母:A,B,C,D.每种字母有且仅有4个,所以一共是16个字母.每次操作可以交换相邻的两个格子,问至少要操作多少次可以使其中某个2*2的小格子中字母相同.刚开始没有理解清楚题目"每种字母有且仅有4个",所以感觉是一个状态压缩的搜索题.然后...TLE,内存耗了40+MB才发现自己没有去重...然后算了一下状态数量,我的妈呀,1000多万呐...后来想
2014-08-07 21:50:38 680
原创 toj3259[Mysterious Numbers]埃式筛法
3259. Mysterious NumberTime Limit: 1.0 Seconds Memory Limit:65536KTotal Runs: 1267 Accepted Runs:400Mysterious Number refers to a number which can be divisible by the numbe
2014-08-05 09:10:11 832
原创 [DFS][toj1009Sticks]
不坑爹,更坑爹.详见http://blog.csdn.net/bit_line/article/details/38374445这里修改的部分是处理poj1011
2014-08-04 21:07:39 681
原创 [代码备份]poj1755
/* * 半成品,但是今天快xie#include #include #include #include #include #include #include using namespace std;const int INF = 0xfffffff;const int MAX = 32;char Map[MAX][MAX];int Move[4][2] = {-1
2014-08-04 19:35:42 710
原创 51416/D辛苦屎了,骗纸呐o o
#include #include #include #include #include #include using namespace std;const int INF = 0xfffffff;const int MAX = 64;int a[MAX][MAX];int n, m, ans;int forwd[4][3][2] = {-3,0, -2,0, -1,0,
2014-08-04 16:03:02 650
原创 位运算技巧
由于位运算是在二进制下进行的,所以他要比普通的加减乘除更快左移一位相当于乘2右移一位相当于整除2和1相与相当于模2 (判奇偶)小技巧:遍历用2进制数s表示的集合的所有子集时,for (i=s; i!=0; i=(i-1&s))即可
2014-08-04 09:36:44 852
原创 toj1205 Compound Words
1205. Compound WordsTime Limit: 3.0 Seconds Memory Limit:65536KTotal Runs: 1108 Accepted Runs:344You are to find all the two-word compound words in a dictionary. A two-word
2014-08-02 09:30:08 722
原创 toj1263 Substrings
1263. SubstringsTime Limit: 1.0 Seconds Memory Limit:65536KTotal Runs: 3276 Accepted Runs:914You are given a number of case-sensitive strings of alphabetic characters, fi
2014-08-01 19:17:44 681
原创 toj1050二分匹配
#include #include #include #include #include #include using namespace std;const int INF = INT_MAX>>1;const int MAX_V = 512;struct edge {int to, cap, rev;};vector G[MAX_V];int level[MAX_V]
2014-08-01 11:43:54 609
原创 toj1050Courses
1050. CoursesTime Limit: 5.0 Seconds Memory Limit:65536KTotal Runs: 1339 Accepted Runs:623Consider a group of N students and P courses. Each student visits zero, one or m
2014-08-01 09:08:16 596
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人