摘要: 筛法。 枚举每个数,它会对它的倍数的答案有贡献。 数大了以后,倍数相应少了很多。比枚举每个数的约数要好的多。 自己yy了一种分步做法。小于sqrt(m)被当作约数枚举,大于sqrt(m)的枚举倍数。 #include #include #include using namespace std; const int maxn = 1000000 + 10; int a[maxn],... 阅读全文
posted @ 2016-05-20 19:36 invoid 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 最小生成树+dfs。 首先可知某一特定权值的边的数量在不同的最小生成树是确定的。(可以用反证法yy一下) 这样先用kruskal算法求最小生成树,一边统计某种边用的数量。 然后dfs一下(就是枚举每条边有没有,因为相同权值的边最多只有10条,所以是O(2^n)的枚举可以胜任)。 同时要注意图是否联通,不联通输出0. #include #include #include using ... 阅读全文
posted @ 2016-05-20 16:49 invoid 阅读(297) 评论(0) 推荐(0) 编辑
摘要: tarjan缩点。网上的代码都没有缩点是把vis变成另外一个值,我也不知道是为什么。 #include #include #include using namespace std; const int maxn = 200000 + 10; const int maxm = 1000000 + 10; int g[maxn],v[maxm],next[maxm],eid; int n,m... 阅读全文
posted @ 2016-05-20 09:55 invoid 阅读(155) 评论(0) 推荐(0) 编辑
摘要: dp. #include #include #include using namespace std; const int maxn = 100 + 10; const int maxm = 2000 + 10; const int maxv = 20 + 10; const int INF = 0x3f3f3f3f; int g[maxn],v[maxm],next[maxm],d[m... 阅读全文
posted @ 2016-05-17 00:24 invoid 阅读(175) 评论(0) 推荐(0) 编辑
摘要: dp.以上次染色时用的颜色的数量和每种数量所含有的颜色作状态。 #include #include #include using namespace std; const int mod = 1000000007; long long f[6][16][16][16][16][16]; int c[6]; int k; long long dfs(int x,int a,int b,... 阅读全文
posted @ 2016-05-16 18:10 invoid 阅读(126) 评论(0) 推荐(0) 编辑
摘要: tatjan缩强连通分量,单源最长路。 #include #include #include using namespace std; const int maxn = 500000 + 10; const int maxm = 1000000 + 10; int G[maxn],V[maxm],Next[maxm],Eid; int g[maxn],v[maxm],next[maxm]... 阅读全文
posted @ 2016-05-16 15:40 invoid 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 最小费用最大流。 拆点法建模。 #include #include #include using namespace std; const int maxn = 500 + 10; const int maxm = 100000 + 10; const int INF = 0x3f3f3f3f; int g[maxn],v[maxm],next[maxm],f[maxm],c[maxm... 阅读全文
posted @ 2016-05-16 14:03 invoid 阅读(155) 评论(0) 推荐(0) 编辑
摘要: kruskal算法。 #include #include #include #include using namespace std; const int maxn = 1000 + 10; const int maxm = 2000000 + 10; struct Point { int x,y; } a[maxn]; struct Edge { int u,v,w;... 阅读全文
posted @ 2016-05-16 11:41 invoid 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 网络流拆点建模。 注意二分查找的边界 #include #include #include using namespace std; const int maxn = 500 + 10; const int maxm = 40000 + 10; const int INF = 0x3f3f3f3f; int g[maxn],v[maxm],next[maxm],f[maxm],eid;... 阅读全文
posted @ 2016-05-16 10:53 invoid 阅读(139) 评论(0) 推荐(0) 编辑
摘要: lazy-tag线段树。 #include #include #include using namespace std; const int maxn = 800000 + 10; struct Segtree { #define lc(x) ((x)r[x]) return; if(Lr[x]) return; if(Lr[x]) return;... 阅读全文
posted @ 2016-05-15 20:07 invoid 阅读(120) 评论(0) 推荐(0) 编辑