
洛谷题库
文章平均质量分 74
ice_word
喜欢算法,喜欢自己独自一个人。
展开
-
C++ P1101 单词方阵
题目:https://www.luogu.org/problem/show?pid=1101直接上代码,解释在代码里-0.0# include using namespace std;int n, dx[10] = {0,0,0,1,-1,1,1,-1,-1}, dy[10] = {0,1,-1,0,0,1,-1,1,-1};// dx,dy 分别是八个方向的增量,其下标表示方向 1原创 2016-11-05 19:12:56 · 971 阅读 · 0 评论 -
C++ P1576 最小花费
题目:https://www.luogu.org/problem/show?pid=1576呃,用最短路dijkstra算法,求一下。。。求。。求。。求一下 -0.0:x = 100 / dis 其中,x是我们要求的最小费用,然后。。。有脑袋的人已经想到了,求出dis最大就好了(别问我为什么),直接上代码。# include # include using namespace s原创 2016-11-05 19:42:21 · 2033 阅读 · 0 评论 -
C++ P1137 旅行计划
题目:https://www.luogu.org/problem/show?pid=1137一开始做法是从入度为0的点开始DFS找最长路,但不知道哪错了(还有超时),然后用了一下拓扑排序。因为它走的路径遵循一个规律:只往东边走,所以可以用拓扑排序,给出代码。# include # include # include using namespace std;int n, m, d原创 2016-11-17 15:24:54 · 1412 阅读 · 0 评论 -
C++ P3383 【模板】线性筛素数
题目:https://www.luogu.org/problem/show?pid=3383#sub哎,个人觉得看别人代码总是好的(我也是看书的),人外有人,天外有天嘛!# include using namespace std;int n, w, ans[1000010], tot, s; // 1…n 的数中 tot 个素数从小到大放在 ans 数组里(多清楚-_-||)bool原创 2016-11-11 21:03:12 · 1219 阅读 · 0 评论 -
C++ P1379 八数码难题
题目:https://www.luogu.org/problem/show?pid=1379经典算法教材题目,然后我决定用 hash + BFS 搞一下,解释代码附上:# include # include using namespace std;string strat, end = "123804765", que[1000000]; //strat输入和取队列头,end终点,q原创 2016-11-11 21:29:41 · 642 阅读 · 0 评论 -
C++ P1082 同余方程
题目:https://www.luogu.org/problem/show?pid=1082#sub哎,搞了半天的欧几里得扩展,写了两页的草稿,终于。。。弄懂了大半。(就是烧脑-.-)做了一下欧几里得扩展裸题,NOIP2012 day2求:关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解。下面证明中“→”表示等价于,“≡”表示同余,“/”表示向下取整。∵ Ax原创 2016-11-12 17:45:51 · 5034 阅读 · 1 评论 -
C++ P1144 最短路计数
题目:P1144 最短路计数他们居然说是水题,看来我还是太low了。用spfa求最短路,然后记录有多少个相同的到该点的最短路。你忽略了重边了吗?# include # include # include using namespace std;const int maxn = 0x7fffffff / 3;int n, m, dis[1000010], a原创 2016-11-17 16:55:55 · 777 阅读 · 0 评论 -
C++ P1726 上白泽慧音
题目:P1726 上白泽慧音学习了强联通分量(scc),找了个裸题,用tarjan算法AC了,Dalao勿喷啊! -_-||# include # include # include # include using namespace std;int n, m, scctot, scc[5010], low[5010], dfn[5010], dfntot, maxn, num;原创 2016-12-07 17:02:18 · 638 阅读 · 0 评论