2012年7月30日

Expression 栈 + 搜索

摘要: ExpressionTime Limit : 6000/2000ms (Java/Other)Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 10Accepted Submission(s) : 7Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem DescriptionYou shoule remove valid pairs of parentheses from a valid arithmetic expression,and you will get 阅读全文

posted @ 2012-07-30 22:43 more think, more gains 阅读(189) 评论(0) 推荐(0) 编辑

Binary Operation

摘要: 题意:a1⊙a2⊙a3= a1⊙a2+ a1⊙a3+ a2⊙a3a1⊙a2⊙a3⊙a4= a1⊙a2+ a1⊙a3+ a1⊙a4+ a2⊙a3+ a2⊙a4+ a3⊙a4算法:1.朴素算法O(n ^2),肯定不行,百万级别数据2.考虑二进制性质,统计所有位1的个数,由异或可知,0,1为1分别统计每位的和。比如第1位sum += (N - bit[1]) * bit[1] * (1<<i)View Code #include<stdio.h>#include<string.h>#include<stdlib.h>int d[40];int main 阅读全文

posted @ 2012-07-30 16:48 more think, more gains 阅读(211) 评论(0) 推荐(0) 编辑

Pattern and Text

摘要: 又是一道优化时间复杂度的算法。朴素O(N * N) ( N <= 2000000)可以优化成O(N)的时间复杂度View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>using namespace std;char word[2001000], str[2000100];int num[2001000];int main( ){ int N; scanf("%d",&N); while( N-- ) { s 阅读全文

posted @ 2012-07-30 16:41 more think, more gains 阅读(176) 评论(0) 推荐(0) 编辑

Square Submatrix

摘要: 题意:给你个N*N矩阵,(N《=400),找出其子矩阵中左对角线和(左上角到右下角),减右对角线和(左下角到右上角)最大差值。算法:普素算法是 O( N * N * N * N )超时,关键是优化求对角线和算法。以空间换时间。用两个二维数组保存好对角线和。O( N * N * N ) acView Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int mp1[410][410];int mp2[410 阅读全文

posted @ 2012-07-30 16:34 more think, more gains 阅读(230) 评论(0) 推荐(0) 编辑

非诚勿扰 贪心

摘要: 贪心策略: 分成两组求解: 男生要求女生比它工资低时。。。 用高工资男生把 先把高工资的女生匹配掉 男生要求女生比他高时。。 用女生高工资匹配高工资男生的。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<vector>using namespace std;vector<int>girl[2];vector<int>boy[2];int M = 0;/* 贪心策略: 男生要求女生 阅读全文

posted @ 2012-07-30 16:29 more think, more gains 阅读(156) 评论(0) 推荐(0) 编辑

ZZY的爱好 比赛题 搜索

摘要: 算法:1.只有16种爱好,枚举所有可能,每种爱好要或不要,总共有65536种状态。2.dfs直接枚举每种状态,并保持最优解,刚开始写搓了,dfs超时,原因是搜索没有控制好,搜索的状态变成16!View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>using namespace std;int dt[50][50];int val[50];int hash[100];int visit[100];int sum[100];int tx[20] 阅读全文

posted @ 2012-07-30 16:21 more think, more gains 阅读(127) 评论(0) 推荐(0) 编辑

poj 1691 搜索

摘要: 1.题意:给你个一平板由N个矩阵组成,先Y后X,给出的点是矩阵左上角和右下角。每个矩阵可以用一种颜色刷子粉刷,求把这平板按指定颜色全部涂色,并且该平板是竖的,当前粉刷的矩阵要保证其上面没有未粉刷的矩阵,求最少的换刷子次数?算法:1.根据规则建好图。2.根据N比较少,可以用dp状态压缩或直接DFS回溯,我写的是回溯,还可以用记忆化搜索。dp[i][j] = c 表示最后粉刷的是第i个矩阵,已经粉刷的矩阵状态为j, 换粉刷次数为c3. DFS 回溯View Code #include<stdio.h>#include<stdlib.h>#include<string. 阅读全文

posted @ 2012-07-30 16:16 more think, more gains 阅读(139) 评论(0) 推荐(0) 编辑

导航