随笔 - 250  文章 - 3  评论 - 66  阅读 - 21万
08 2013 档案
code_analyzer(代码分析助手)
摘要:软件名: code_analyzer使用c语言 pcre正则库分析源码文件,包括文件中的头文件、宏定义、函数。用途:无聊时,可以用来打发下时间。演示:对于本源程序的分析结果如下:##########################头文件########################1.头文件: stdio.h2.头文件: stdlib.h3.头文件: string.h4.头文件: pcre.h##########################宏#######################... 阅读全文
posted @ 2013-08-27 11:37 Still_Raining 阅读(2860) 评论(4) 推荐(2) 编辑
CodeAssistant
摘要:软件名:CodeAssistant很霸气的名字,不过目前仅有的功能是代码格式化。用途:在向大神请教时,不妨用这小软件把自己的代码格一下。我们的口号就是让大神看得舒心,让BUG无处遁形。演示:一个很混乱的代码:#include#define N 200 /*这里是注释%s%Ssdfkjsldfj*/struct child{ char name[10];char sex[3]; int age;int height;float weight; struct { int year;int month; int day; }bdate;}ch[N];void input(){int... 阅读全文
posted @ 2013-08-24 16:58 Still_Raining 阅读(576) 评论(1) 推荐(1) 编辑
我的小软件
摘要:我的小软件作为一个程序猿,要有能力用代码解决自己身边的问题。所以,我会写一些小小的软件,一方面作为练习,一方面为了方便自己。1.CodeAssistant(2013-08-24 16:58)很霸气的名字,不过目前仅有的功能是代码格式化。2.mines(扫雷)实训时写的一个控制台小游戏,完全用C写的。... 阅读全文
posted @ 2013-08-24 16:12 Still_Raining 阅读(434) 评论(0) 推荐(4) 编辑
POJ1416 Shredding Company(dfs)
摘要:题目链接。分析:这题从早上调到现在。也不算太麻烦,细节吧。每个数字都只有两种状态,加入前一序列和不加入前一序列。DFS枚举。#include #include #include #include #include #include #include #include using namespace std;int ord[10], len, ans_a[10], tar, max_ans, cnt;char s[10];bool flag;void dfs(int cur_s, int cur_t, int cur) { if(cur_s+cur_t > tar) { //... 阅读全文
posted @ 2013-08-23 15:05 Still_Raining 阅读(203) 评论(0) 推荐(0) 编辑
共享内存实例
摘要:源码书上关于进程间通过共享内存实现通信的例子。遇到了问题操作过程中,一直提示 shmat error, 很纳闷。解决调试了很长时间,突然想起shmat会将错误原因存于error中,所以在源代码中加了一句 printf("%s\n", sys_errlist[errno]); 运行结果显示 Permission denied. 原来是没有权限,运行时 加上 sudo , OK。解决.代码如下m1.c#include #include #include #include #include #include #include #define BUF_SIZE 1024#defin 阅读全文
posted @ 2013-08-22 15:17 Still_Raining 阅读(323) 评论(2) 推荐(0) 编辑
POJ2002 Squares(枚举)
摘要:题目链接。分析:普遍的做法是:先枚举两个点,通过数学公式得到另外2个点,使得这四个点能够成正方形。然后检查散点集中是否存在计算出来的那两个点,若存在,说明有一个正方形。但这种做法会使同一个正方形按照不同的顺序被枚举了四次,因此最后的结果要除以4.已知: (x1,y1) (x2,y2)则: x3=x1+(y1-y2) y3= y1-(x1-x2)x4=x2+(y1-y2) y4= y2-(x1-x2)或x3=x1-(y1-y2) y3= y1+(x1-x2)x4=x2-(y1-y2) y4= y2+(x1-x2)直接hash太麻烦,使用set简单些.AC代码如下:#include #includ 阅读全文
posted @ 2013-08-21 17:06 Still_Raining 阅读(381) 评论(0) 推荐(0) 编辑
POJ3087 Shuffle'm Up(模拟)
摘要:题目链接。AC代码如下;#include #include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 1000+10;int main() { int T, n, cn; bool flag; char s1[maxn], s2[maxn], s3[maxn], s[maxn]; scanf("%d", &T); for(int kase=1; kase st; cn... 阅读全文
posted @ 2013-08-21 10:05 Still_Raining 阅读(215) 评论(0) 推荐(0) 编辑
POJ3126 Prime Path(BFS)
摘要:题目链接。AC代码如下:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 10000;struct node { int x, s;};int end;bool vis[maxn], prime[maxn];int BFS(int s) { if(s == end) return 0; queue Q; memset(vis, 0, sizeof(vis)); vi... 阅读全文
posted @ 2013-08-20 21:10 Still_Raining 阅读(1012) 评论(0) 推荐(0) 编辑
POJ2442 Sequence
摘要:题目链接。#include #include #include #include #include #include #include using namespace std;const int maxn = 2000+10;int a[maxn], b[maxn];int main() { int T, n, m; scanf("%d", &T); while(T--) { priority_queue que; scanf("%d %d", &n, &m); for(int i=0; i que.top()... 阅读全文
posted @ 2013-08-20 10:36 Still_Raining 阅读(221) 评论(0) 推荐(0) 编辑
HDU4681 String(dp)
摘要:题目链接。#include #include #include #include #include using namespace std;const int maxn = 1000+10;char s1[maxn], s2[maxn], s3[maxn];int dp1[maxn][maxn], dp2[maxn][maxn];int que1[maxn][2], que2[maxn][2];void max_dp(char *s1, char *s2, int (*dp)[maxn]) { int len1 = strlen(s1), len2 = strlen(s2); fo... 阅读全文
posted @ 2013-08-19 17:07 Still_Raining 阅读(219) 评论(0) 推荐(0) 编辑
HDU4666 Hyperspace(曼哈顿)
摘要:题目链接。分析:这是多校的一个题,当时没做出来。学长说让用multiset。用multiset将每一个数的1#include #include #include #include #include #include using namespace std;const int maxn = 60000+10;const int dem = 5; //维数const int INF = (1 ms[40]; multiset::iterator it; for(int i=1; i>= 1; } ... 阅读全文
posted @ 2013-08-15 10:46 Still_Raining 阅读(270) 评论(0) 推荐(0) 编辑
POJ3436 ACM Computer Factory(最大流)
摘要:题目链接。分析:题意很难懂。大体是这样的:给每个点的具体情况,1.容量 2。进入状态 3.出去状态。求最大流。因为有很多点,所以如果一个点的出去状态满足另一个点的进入状态,则这两个点可以连一条边。容量为两者容量的较小值。再建立一个超源、一个超汇。让超源与所有进入状态全为0或者不全为0但只包含0和2的点连边,同时让所有出去状态全部为1的与超汇连边。然后求最大流.#include #include #include #include using namespace std;const int maxn = 60;const int INF = (1 q; int p[maxn], a[max... 阅读全文
posted @ 2013-08-14 11:28 Still_Raining 阅读(737) 评论(0) 推荐(0) 编辑
再思考
摘要:再思考这是第一次想把感想发到博客上来,所以,请再赐我两斤压力。不谈别人,只说自己:自从上学期以后,就好久没有没有做计划了,总是走到哪算哪。对于自己算法的进步速度是真的一点都不满意,各种知识的局限性让我挣扎在不断的痛苦中。但另一方面,我毕竟是长大了,各种程度上远非一年前能比。上学期是让自己在专业入门,而下学期就是彻底的改变自己。这里的改变并非知识的全面武装,而是由内到外、脱胎换骨的改变。我变成大人了,不是年龄,是内心想要改变自己,所以总是在强迫自己。总是让自己做些与自己内心不相符的事, 内心不断的适应、不断改变,所以现在的我与一年前的我相比,是传承着相同记忆的不同的人。作出这种改变,没有对与错, 阅读全文
posted @ 2013-08-13 23:57 Still_Raining 阅读(269) 评论(3) 推荐(1) 编辑
POJPower Network (最大流)
摘要:题目链接。分析:这题描述的可不是一般的复杂.其时就是很多源点、很多汇点,使尽量多流量的到达汇点。因为有很多源点,就再设一个源点(0号),使得0号到其它源点的容量为其它源点的初始量,同样设一汇点(n+1),使得其它汇点到该汇点的容量为其它汇点的初始量,如此就把很多的源点和汇点看成普通的点,单源单汇最大流。最大流用的是白书上的增广路算法。AC代码如下:#include #include #include #include #include using namespace std;const int maxn = 110;const int INF = (1 q; memset(flow, 0... 阅读全文
posted @ 2013-08-13 16:05 Still_Raining 阅读(414) 评论(0) 推荐(0) 编辑
POJSorting It All Out (拓扑)
摘要:题目链接。题目大意:给定一定的数量的小于关系:1.如果发现环,输出从前几次就可以确定出现环2.如果能够确定唯一序列,输出。3.如果通过全部关系,还不能确定序列,则输出不能确定.分析:个人感觉难点在于判环上。1.如果每次都只能找到1个入度为0的点,并能确定序列,则该序列即为答案。2.如果每次查找时,发现两个及其以上的入度为0的点,则表明一定不能确定唯一序列(即存在环或者是不能确定)。如果可以确定一个任意序列,即表明还需要更多关系。如果继续查找下去,找不到入度为0的点,则存在环。 AC代码如下:#include #include #include #include #include using n 阅读全文
posted @ 2013-08-12 23:38 Still_Raining 阅读(304) 评论(0) 推荐(0) 编辑
POJ3026 Borg Maze(最小生成树)
摘要:题目链接。题目大意:任意两点(点表示字母)可以连线,求使所有点连通,且权值和最小。分析:第一感觉使3维的BFS。但写着写着,发现不对。应当用最小生成树解法。把每个字母(即A,或S)看成一个结点,如果求出来任意两个结点间的权值,则求解即为求最小生成树。通过暴力,对每一个字母进行BFS,求出任意两个结点的距离。然后prim.AC代码如下:#include #include #include #include #include using namespace std;const int maxn = 52;const int INF = (1 Q; memset(vis, 0, sizeof(... 阅读全文
posted @ 2013-08-12 16:49 Still_Raining 阅读(1248) 评论(0) 推荐(0) 编辑
POJ1789 Truck History(prim)
摘要:题目链接。分析:最大的敌人果然不是别人,就是她(英语)。每种代表车型的串,他们的distance就是串中不同字符的个数,要求算出所有串的distance's 最小 sum。AC代码如下:#include #include #include #include using namespace std;const int maxn = 2200;const int INF = (1= d[y]) m = d[x=y]; ans += m; vis[x] = true; for(int y=0; y G[x][y]) d[y] = G[x][y]; } ... 阅读全文
posted @ 2013-08-12 10:31 Still_Raining 阅读(197) 评论(0) 推荐(0) 编辑
POJ3267 The Cow Lexicon(dp)
摘要:题目链接。分析:dp[i]表示母串从第i位起始的后缀所对应的最少去掉字母数。dp[i] = min(dp[i+res]+res-strlen(pa[j]));其中res 为从第 i 位开始匹配 pa[j] 所需要的长度。以下代码当做指针的练习,研究了几天C,发现C语言功底到底是提升了(虽说算法功底至今还木有)。#include #include #include #include using namespace std;const int maxn = 500;char s[maxn], pa[610][30];int dp[maxn];int match(char *s1, char *s2 阅读全文
posted @ 2013-08-12 09:46 Still_Raining 阅读(230) 评论(0) 推荐(0) 编辑
stdout 与 stderr 的区别
摘要:stdout 与 stderr 的区别一直没有注意 stdout 与 stderr 的区别,以为只是不同的描述方式。看来不是这样的。stdout 主要处理的是使用者输出stderr 主要处理的错误信息输出相比stdout, stderr没有缓冲设置将"正常输出"和"错误信息输出"加以分离,可以让程序以不同的方式对待两种不同的输出,例如可以将错误信息显示在控制台上,而正常输出重新定向到某个文件上。Example#include void main(){ fprintf(stdout, "from stdout\n"); fprintf( 阅读全文
posted @ 2013-08-11 11:31 Still_Raining 阅读(1167) 评论(1) 推荐(1) 编辑
printf
摘要:碰到了printf的一个很奇葩的用法。A width or precision may be specified as *, in which case the value is compputed by converting the next argument (which must be an int). For example, to print at most max characters from a string s.#include #include int main() { int max; char *s = "this is a test!\n"... 阅读全文
posted @ 2013-08-10 23:37 Still_Raining 阅读(164) 评论(0) 推荐(0) 编辑
Table Lookup
摘要:做OJ的时候,做过类似的,即hash。算法很简单,关键是书上写的和做OJ,是完全不同的风格。有很多值得学习的地方。 /* * Table Lookup * 详见>(英文版*第二版) P143 * * This code is typical of what might be found in the symbl table * management routines of a macro processor or a compiler. * For example, consider the #define statment. When a line like * #define IN 阅读全文
posted @ 2013-08-09 23:46 Still_Raining 阅读(502) 评论(0) 推荐(0) 编辑
POJ1125 Stockbroker Grapevine(最短路)
摘要:题目链接。分析:手感不错,1A。直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕)。#include #include #include using namespace std;const int maxn = 100+20;const int INF = (1= d[y]) m = d[x=y]; vis[x] = true; for(int y=0; y d[x]+G[x][y]) { d[y] = d[x] + G[x][y]; } } int ans = -1; for(int i=... 阅读全文
posted @ 2013-08-09 17:29 Still_Raining 阅读(797) 评论(0) 推荐(0) 编辑
POJ1860 Currency Exchange(最短路)
摘要:题目链接。分析:以前没做出来,今天看了一遍题竟然直接A了。出乎意料。大意是这样,给定不同的金币的编号,以及他们之间的汇率、手续费,求有没有可能通过不断转换而盈利。直接用Bellman-ford检测负环的方法检测。#include #include #include using namespace std;const int maxn = 300;const int inf = (1d[e.v]) { d[e.v] = (d[e.u]-e.c)*e.r; } } } for(int i=0; id[e.v]) { ... 阅读全文
posted @ 2013-08-09 16:17 Still_Raining 阅读(193) 评论(0) 推荐(0) 编辑
qsort
摘要:qosrt的这种写法,很简单,也很好理解。 一开始没看懂,因为这一句swap(v, left, (left + right)/2); 后来转念一想,不是把left当成分割点,而是把(left+right)/2当分割点,恍然大悟。 代码如下:#include void swap(int v[], int i, int j) { int t = v[i]; v[i] = v[j]; v[j] = t;}void qsort(int v[], int left, int right) { int i, last; if(left >= right) ... 阅读全文
posted @ 2013-08-07 20:58 Still_Raining 阅读(227) 评论(0) 推荐(0) 编辑
POJ1942 Paths on a Grid(组合)
摘要:题目链接。分析:#include #include #include #include using namespace std;typedef unsigned long long LL;int main() { LL n, m; while(cin >> n >> m) { if(n == 0 && m == 0) break; LL s = n+m; if(n > m) swap(n, m); LL ans = 1; for(LL i=s, j=1; j<=n; i--, j++) { ... 阅读全文
posted @ 2013-08-07 16:20 Still_Raining 阅读(176) 评论(0) 推荐(0) 编辑
POJ2676 Sudoku(dfs)
摘要:题目链接。题目大意:就是数独游戏。横竖,每一个9宫方块,必须有1~9,且不重复。分析:直接DFS。一开始在原图上搜,会TLE。把要补全的空格,放入数组,这样就不用遍历整个图寻找要填的空格了。row, col, sq分别标记行,列,3*3方格是否重复。话说,直接做有人说反着搜(正着搜的意思就是从0~cnt-1,反着搜就是从cnt~0),试了试。AC代码如下:#include #include #include #include using namespace std;struct node { int x, y;}q[9*9+10];bool row[10][10], col[10][10... 阅读全文
posted @ 2013-08-07 14:39 Still_Raining 阅读(963) 评论(0) 推荐(0) 编辑
HDU1565 方格取数(1)(状态压缩dp)
摘要:题目链接。分析:说这题是状态压缩dp,其实不是,怎么说呢,题目数据太水了,所以就过了。手动输入n=20的情况,超时。正解是网络流,不太会。A这题时有个细节错了,是dp[i][j]还是dp[i][q[j]]? 答案是dp[i][j],因为q[j]必定会超(感谢CZ学长提示)。AC代码如下:#include #include #include #include #include #include using namespace std;const int maxn = 20000;int q[maxn], dp[21][maxn], G[21][21];int main() { int n;... 阅读全文
posted @ 2013-08-06 22:28 Still_Raining 阅读(568) 评论(0) 推荐(0) 编辑
POJ2513 Colored Sticks(欧拉)
摘要:题目链接。题目大意:给很多木棍,两端被涂了颜色。任意两根木棍的相同颜色处可以拼接在一起,问有没有可能将所有的木棍都连起来,成一条直线?分析:考点,欧拉道路。将一根木棍看成一条边,两端的颜色看成两个点,问题成了,能否从无向图的一个结点出发走出一条道路,每条边恰好经过一次。求法:如果一个无向图是连通的,且最多有两个奇点(奇点指的是度数是奇数的点),则一定存在欧拉道路。是否连通可以通过并查集来求。#include #include #include #include #include #include using namespace std;const int maxn = 500000+10+10 阅读全文
posted @ 2013-08-06 09:53 Still_Raining 阅读(241) 评论(0) 推荐(0) 编辑
Macro Substitution
摘要:看《C程序设计语言》(英文版)学到的两个用法。 两个很简单的宏用法。 #的用法: if, however, a parameter name is preceded by a # in the replacement text, the combination will be expanded into a quoted string with the parameter replaced by the actual argument.#include #define dprint(expr) printf(#expr " = %g\n", expr);int main() 阅读全文
posted @ 2013-08-06 09:20 Still_Raining 阅读(350) 评论(0) 推荐(0) 编辑
POJ2242 The Circumference of the Circle(几何)
摘要:题目链接。题目大意:给定三个点,即一个任意三角形,求外接圆的周长。分析:外接圆的半径可以通过公式求得(2*r = a/sinA = b/sinB = c/sinC),然后直接求周长。注意:C++AC,G++WA。#include #include #include #include #include using namespace std;const double PI = 3.141592653589793;typedef struct Point { double x, y; Point (double x=0, double y=0):x(x),y(y) {};}Vector... 阅读全文
posted @ 2013-08-05 16:41 Still_Raining 阅读(245) 评论(0) 推荐(0) 编辑
POJ2586 Y2K Accounting Bug(贪心)
摘要:题目链接。题目大意:题目相当晦涩难懂啊。一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能。一个月surplus只能是s,deficit只能是d,不能是其它的值。分析:用贪心,先计算1~5,让每个月都盈利,然后从第5个月向前deficit,直到1~5的和为deficit。继续2~6,3~7.。。。,8~12.最后统计全年是否盈利。AC代码如下:#include #include #include #include #include using namespace std;int main(){ i... 阅读全文
posted @ 2013-08-05 10:56 Still_Raining 阅读(252) 评论(0) 推荐(0) 编辑
POJ2996 Help Me with the Game(模拟)
摘要:题目链接。分析:简单模拟。#include #include #include #include #include using namespace std;char White[] = "KQRBNP";char Black[] = "kqrbnp";char G[10][10], s[50];int main(){ memset(G, 0, sizeof(G)); for(int i=0; i=0; i--) { for(int j=0; j<8; j++) { if(G[i][j] == White[k]) { ... 阅读全文
posted @ 2013-08-05 09:43 Still_Raining 阅读(281) 评论(0) 推荐(0) 编辑
POJ2084 Game of Connections(数学,dp)
摘要:题目链接。分析:简单的 Catalan 数将x~y编号,设解为 d(x, y), d(x, y) = {d(x+1,i-1)*d(i+1,y)}, 其中 x+1#include#include#include #include using namespace std;#define MAXN 9999#define DLEN 4class BigNum{private: int a[50]; //可以控制大数的位数 int len; //大数长度public: BigNum(){ len = 1; memset(a,0,sizeof(a)); } //构... 阅读全文
posted @ 2013-08-03 17:14 Still_Raining 阅读(387) 评论(0) 推荐(0) 编辑
HDU3549 Flow Problem(网络流增广路算法)
摘要:题目链接。分析:网络流增广路算法模板题。http://www.cnblogs.com/tanhehe/p/3234248.htmlAC代码:#include #include #include #include using namespace std;const int maxn = 20;const int INF = (1 q; memset(flow, 0, sizeof(flow)); int f = 0; while(true) { memset(a, 0, sizeof(a)); a[s] = INF; q.push(s)... 阅读全文
posted @ 2013-08-03 10:14 Still_Raining 阅读(432) 评论(0) 推荐(0) 编辑
网络流之增广路算法
摘要:这部分内容在《算法竞赛入门经典》——刘汝佳 里面讲的已经很详细了。但里面对于反向流量的作用是没有说明的。这里只说一下反向流量的作用。推荐上http://www.cnblogs.com/g0feng/archive/2012/05/29/2524749.htm看下。反向流量能够让后面的流自我调整。例如当前状态下当前状态下如何寻找?用a表示残量, cap表示容量,很明显,3-4这条路不是最优的.此时BFS, 会得到 a[2] = 2, a[4] = 2, a[3] = 1 (提示:cap[4][3]-flow[4][3]=1),a[5]=1, a[6]=1, a[7]=1更新流量得到可以看到,通过 阅读全文
posted @ 2013-08-03 10:04 Still_Raining 阅读(6527) 评论(0) 推荐(0) 编辑
HDU4536 XCOM Enemy Unknown(dfs)
摘要:题目链接。分析:用dfs枚举每一波攻击的三个国家。很暴力,但没想到0ms。#include #include #include using namespace std;const int maxn = 20;int p[maxn], nervous[maxn], n, m, k, max_cnt;int att[110][3];void dfs(int cn) { //界限 if(max_cnt >= k) return ; if(cn >= k) { max_cnt = k; return ; } int a[3], bak[3]; for(... 阅读全文
posted @ 2013-08-02 14:32 Still_Raining 阅读(354) 评论(0) 推荐(0) 编辑
POJ1008 1013 1207 2105 2499(全部水题)
摘要:做了一天水题,挑几个还算凑合的发上来。POJ1008Maya Calendar分析:#include #include #include #include using namespace std;char Haab[][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "za 阅读全文
posted @ 2013-08-01 20:51 Still_Raining 阅读(347) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示