上一页 1 2 3 4 5 6 7 ··· 13 下一页
  2013年8月15日
摘要: 题目链接。分析:这是多校的一个题,当时没做出来。学长说让用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 阅读(267) 评论(0) 推荐(0) 编辑
  2013年8月14日
摘要: 题目链接。分析:题意很难懂。大体是这样的:给每个点的具体情况,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 阅读(734) 评论(0) 推荐(0) 编辑
  2013年8月13日
摘要: 再思考这是第一次想把感想发到博客上来,所以,请再赐我两斤压力。不谈别人,只说自己:自从上学期以后,就好久没有没有做计划了,总是走到哪算哪。对于自己算法的进步速度是真的一点都不满意,各种知识的局限性让我挣扎在不断的痛苦中。但另一方面,我毕竟是长大了,各种程度上远非一年前能比。上学期是让自己在专业入门,而下学期就是彻底的改变自己。这里的改变并非知识的全面武装,而是由内到外、脱胎换骨的改变。我变成大人了,不是年龄,是内心想要改变自己,所以总是在强迫自己。总是让自己做些与自己内心不相符的事, 内心不断的适应、不断改变,所以现在的我与一年前的我相比,是传承着相同记忆的不同的人。作出这种改变,没有对与错, 阅读全文
posted @ 2013-08-13 23:57 Still_Raining 阅读(267) 评论(3) 推荐(1) 编辑
摘要: 题目链接。分析:这题描述的可不是一般的复杂.其时就是很多源点、很多汇点,使尽量多流量的到达汇点。因为有很多源点,就再设一个源点(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 阅读(410) 评论(0) 推荐(0) 编辑
  2013年8月12日
摘要: 题目链接。题目大意:给定一定的数量的小于关系: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 阅读(302) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:任意两点(点表示字母)可以连线,求使所有点连通,且权值和最小。分析:第一感觉使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 阅读(1241) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:最大的敌人果然不是别人,就是她(英语)。每种代表车型的串,他们的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 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析: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 阅读(227) 评论(0) 推荐(0) 编辑
  2013年8月11日
摘要: 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 阅读(1151) 评论(1) 推荐(1) 编辑
  2013年8月10日
摘要: 碰到了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 阅读(161) 评论(0) 推荐(0) 编辑
  2013年8月9日
摘要: 做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 阅读(495) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:手感不错,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 阅读(794) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:以前没做出来,今天看了一遍题竟然直接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 阅读(192) 评论(0) 推荐(0) 编辑
  2013年8月7日
摘要: 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 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:#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 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:就是数独游戏。横竖,每一个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 阅读(961) 评论(0) 推荐(0) 编辑
  2013年8月6日
摘要: 题目链接。分析:说这题是状态压缩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 阅读(565) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:给很多木棍,两端被涂了颜色。任意两根木棍的相同颜色处可以拼接在一起,问有没有可能将所有的木棍都连起来,成一条直线?分析:考点,欧拉道路。将一根木棍看成一条边,两端的颜色看成两个点,问题成了,能否从无向图的一个结点出发走出一条道路,每条边恰好经过一次。求法:如果一个无向图是连通的,且最多有两个奇点(奇点指的是度数是奇数的点),则一定存在欧拉道路。是否连通可以通过并查集来求。#include #include #include #include #include #include using namespace std;const int maxn = 500000+10+10 阅读全文
posted @ 2013-08-06 09:53 Still_Raining 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 看《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 阅读(348) 评论(0) 推荐(0) 编辑
  2013年8月5日
摘要: 题目链接。题目大意:给定三个点,即一个任意三角形,求外接圆的周长。分析:外接圆的半径可以通过公式求得(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 阅读(244) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 13 下一页