05 2016 档案

摘要:bfs最短路。 写的真丑。。。 #include #include #include #include #include using namespace std; const int maxn = 50; const int INF = 0x3f3f3f3f; const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; int n,m,T... 阅读全文
posted @ 2016-05-30 17:49 invoid 阅读(133) 评论(0) 推荐(0)
摘要:hash 加上 平衡树(名次树)。 这道题麻烦的地方就在于输入的是一个名字,所以需要hash。 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些。 mod一定要取得大一些。 hash时要减去@,否则A和B的hash值会相同导致tle。 比较难写?//蒟蒻本性。。。 #include #include #include using ... 阅读全文
posted @ 2016-05-30 10:39 invoid 阅读(153) 评论(0) 推荐(0)
摘要:hash。 怎么感觉叫状态压缩bfs比较合适呢? #include #include #include using namespace std; const int maxn = 10 + 5; const int maxm = 100 + 10; const int maxg = 1024 + 10; bool st[maxn],h[maxg]; int mp[maxm][maxn]... 阅读全文
posted @ 2016-05-29 11:26 invoid 阅读(349) 评论(0) 推荐(0)
摘要:单调队列 用一个堆维护目前每个颜色在里面的点,每回取出队首点,并更新答案。一旦哪个颜色的点都被用完,跳出循环。 #include #include #include #include using namespace std; const int maxn = 1000000 + 10; const int maxk = 60+10; struct data { int a,c;... 阅读全文
posted @ 2016-05-29 00:50 invoid 阅读(248) 评论(0) 推荐(0)
摘要:启发式合并。 启发式合并就是每次将小的合并进大的里面。每次合并复杂度为O(n),因为每回大小都会翻倍,所以总复杂度就是O(nlogn)。 首先用链表维护每一种颜色。 询问直接输出答案。 否则合并(要记住,如果俩个其中一个是空的,直接特判,否则会浪费时间导致tle)。 #include #include #include using namespace std; const int ... 阅读全文
posted @ 2016-05-28 19:03 invoid 阅读(221) 评论(0) 推荐(0)
摘要:堆。 一道模拟,不过不同的人模拟出来的效果差距很大,比方说我抄的这个就太劲了。。 #include #include #include #include using namespace std; struct data { int n,s,t,p; data() {} data(int n,int s,int t,int p):n(n),s(s),t(t),p(p... 阅读全文
posted @ 2016-05-27 23:12 invoid 阅读(134) 评论(0) 推荐(0)
摘要:题目大意: 在n个点中,选出k对相邻的互不相同的点,使k段距离的总和最小。 贪心,双向链表。 首先,点之间的距离是动态的,所以要用堆来维护。 每次都选择最近的点。但因为其他情况,可能最终不会选择这对点连在一起 所以把俩个点旁边的路径的和减去俩个点之间距离再加进去,表示连旁边的俩条边,不连现在的边。 要维护许多信息。 #include #include #include us... 阅读全文
posted @ 2016-05-27 20:39 invoid 阅读(571) 评论(0) 推荐(0)
摘要:二分图匹配。 补充,感觉之前说的不够详细,如果有完美匹配的话,每行都有一个对应的列,那么换来换去以后,对角线就全黑了。。。 #include #include #include using namespace std; const int maxn = 400 + 10; bool vis[maxn]; int p[maxn],map[maxn][maxn]; int n,T; ... 阅读全文
posted @ 2016-05-25 19:30 invoid 阅读(161) 评论(0) 推荐(0)
摘要:斜率优化。 大水题。。。 #include #include #include using namespace std; const int maxn = 1000000 + 10; int q[maxn],l,r; long long f[maxn],s[maxn],a,b,c,x; int n,m; inline long long sqr(long long x) { ... 阅读全文
posted @ 2016-05-25 18:01 invoid 阅读(143) 评论(0) 推荐(0)
摘要:不知道什么算法。 首先求一颗植物(i,j)与能量采集器的连线上有几颗植物。 答案是(gcd(i,j)-1),设i’= i/gcd(i,j),j’=j/gcd(i,j). 则这几颗植物是(i’k,j’k) 1 #include #include using namespace std; const int maxn = 100000 + 10; long long ans[maxn],... 阅读全文
posted @ 2016-05-25 17:11 invoid 阅读(125) 评论(0) 推荐(0)
摘要:矩阵乘法. 10^k,0,0 (f[i+1],i+1,1) = (f[i],i,1) ( 1, 1,0 ) 1. 1,0) k为(i+1)的位数。这点很重要,所以每回都是算到999…9,然后k就会+1。所以题目中的l和... 阅读全文
posted @ 2016-05-25 10:20 invoid 阅读(137) 评论(0) 推荐(0)
摘要:KMP。 一直没有一个裸kmp,根本看不懂kmp。。。//蒟蒻本性。 kmp的部分匹配值next[j],在这个实现中的意思是,如果b[j+1]和a[i]失配,j=next[j]。 就是不断返回直到b[j+1]==a[i]。 计算的话,就用自己匹配自己吧。 阅读全文
posted @ 2016-05-24 16:38 invoid 阅读(257) 评论(0) 推荐(0)
摘要:矩阵乘法的通俗的我自己用的理解方式 C=AB. 则Cij=∑aikbkj (k属于那个范围),所以首先矩阵相乘的必须是A矩阵的列数等于b矩阵的行数。 第二就是C的意义了,cij表示A的第i行与B的第j列每个数对应相乘,因为上面的条件,所以A的第i行的数的数目恰好等于B的第j列数的数目。 c也正好是i行j列。 下面是我看懂矩阵乘法的网址,讲的确实不错。 http://www.ruanyif... 阅读全文
posted @ 2016-05-24 16:15 invoid 阅读(212) 评论(0) 推荐(0)
摘要:二分。 #include #include #include using namespace std; const int maxn = 50000 + 10; int n,k,l,r,mid,ans,d; int a[maxn]; bool check(int dist) { dist=2*dist; int d=0,sum=1; for(int i=2;id... 阅读全文
posted @ 2016-05-20 21:32 invoid 阅读(155) 评论(0) 推荐(0)
摘要:前缀和. 设f[i]为前缀和%7=i的第一个点。那么答案就是max(i-f[s[i]%7])了。 #include #include #include using namespace std; const int maxn = 50000 + 10; int a[maxn],s[maxn]; int f[10],n,ans; int main() { for(int i... 阅读全文
posted @ 2016-05-20 21:31 invoid 阅读(350) 评论(0) 推荐(0)
摘要:筛法。 枚举每个数,它会对它的倍数的答案有贡献。 数大了以后,倍数相应少了很多。比枚举每个数的约数要好的多。 自己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 阅读(156) 评论(0) 推荐(0)
摘要:最小生成树+dfs。 首先可知某一特定权值的边的数量在不同的最小生成树是确定的。(可以用反证法yy一下) 这样先用kruskal算法求最小生成树,一边统计某种边用的数量。 然后dfs一下(就是枚举每条边有没有,因为相同权值的边最多只有10条,所以是O(2^n)的枚举可以胜任)。 同时要注意图是否联通,不联通输出0. #include #include #include using ... 阅读全文
posted @ 2016-05-20 16:49 invoid 阅读(309) 评论(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 阅读(168) 评论(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 阅读(188) 评论(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 阅读(137) 评论(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 阅读(129) 评论(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 阅读(165) 评论(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 阅读(139) 评论(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 阅读(148) 评论(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 阅读(133) 评论(0) 推荐(0)
摘要:斜率优化dp。 #include #include #include using namespace std; const int maxn = 50000 + 10; struct Field { long long x,y; } t[maxn]; long long f[maxn],x[maxn],y[maxn]; int q[maxn],l,r; int ... 阅读全文
posted @ 2016-05-15 17:41 invoid 阅读(153) 评论(0) 推荐(0)
摘要:数位dp。 #include #include #include using namespace std; long long pow[15],f[15][10][10],resa[10],resb[10]; long long a,b; void add(long long a[],long long b[]) { for(int i=0;in) len--; for... 阅读全文
posted @ 2016-05-15 15:43 invoid 阅读(163) 评论(0) 推荐(0)
摘要:匈牙利匹配。 在邻接表中每条边以终点升序排序。从x最后一个点往前进行增广,这样每个点首先都能匹配到字典序最小的位置,如果前面的点找不到匹配点时,后面的点就匹配到稍大一点的y匹配点上。 建图说明:每个点有且只会有俩个点符合距离的要求,可以想想为什么。 y点要+n与x点区分开来。 #include #include #include #include using namespace st... 阅读全文
posted @ 2016-05-15 09:47 invoid 阅读(137) 评论(0) 推荐(0)
摘要:二分水题。为什么要写这道题呢,因为要辨明long long的读入与输出。 经过俩天的调试(我还以为我代码写错了)。。。 发现codeVS,tyvj输入输出用lld,vijos用I64d 这篇题解除了我应该也不会有人看见。。所以肯定还会有大量人入坑。 呜呼哀哉。 #include #include #include #include #include using namespa... 阅读全文
posted @ 2016-05-12 19:18 invoid 阅读(145) 评论(0) 推荐(0)
摘要:枚举。 为什么要写这道题的题解呢,因为这道题有小技巧。 1.首先由题意知b1%x==0,这个条件如何用呢,就是x从1到sqrt(b1)枚举,其他符合条件的数肯定是b1/x中的一部分。 2.枚举条件不要直接写sqrt(b1)否则每回都会计算一遍,会tle。应该用i^2 #include #include using namespace std; inline int gcd(int a,in... 阅读全文
posted @ 2016-05-12 13:30 invoid 阅读(148) 评论(0) 推荐(0)
摘要:斜率优化dp。 #include #include #include using namespace std; const int maxn = 50000 + 10; int n; long long L; int c[maxn],q[maxn]; long long s[maxn],f[maxn]; double slop(int j,int k) { return (f[... 阅读全文
posted @ 2016-05-11 17:55 invoid 阅读(251) 评论(0) 推荐(0)
摘要:dfs序。 用l[u]和r[u]表示进入u和出去u的时间。用树状数组维护前缀和,l[u]处加1,r[u]处减1。 询问的是树根到自己u的距离,就相当于l[u]处的前缀和。为什么呢? 如果一个节点v在树根到u的路径上,就会在l[v]处加1。如果不在,如果编号小于u,l[v]和r[v]处相消。 如果大于u则l[v]大于l[u]。W u操作则是将l[u]处减1,将r[u]处加1。这样u就不会影响... 阅读全文
posted @ 2016-05-10 17:56 invoid 阅读(143) 评论(0) 推荐(0)
摘要:状态空间搜索?用map判重。 #include #include #include #include #include using namespace std; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; struct Status { int a[4][4]; Status move(int x,int y,int dir) {... 阅读全文
posted @ 2016-05-10 17:20 invoid 阅读(179) 评论(0) 推荐(0)
摘要:%%%。设f(x)=a0+a1x+a2x^2+ … + anx^n.求f(x)=0的x。 数据范围很大,高精度只能骗分。 运用类似hash的思想。 如果这个等式mod p 还成立(p为质数)那它很可能就是成立。 多取几个质数(大质数更优)就可以几乎确定了。(70分) 100分时m很大,不能都算出来。 仔细分析,如果在模p时f(x)!=0,则f(x+p)肯定也不是解。这样一来只需枚举从1到... 阅读全文
posted @ 2016-05-10 15:32 invoid 阅读(174) 评论(0) 推荐(0)
摘要:方向dfs判定是否可行,spfa跑最短路。 noip水题,wa好几次。 #include #include #include using namespace std; const int maxn = 10000 + 10; const int maxm = 200000 + 10; int g[maxn],v[maxm],next[maxm],eid; int g1[maxn]... 阅读全文
posted @ 2016-05-10 08:24 invoid 阅读(175) 评论(0) 推荐(0)
摘要:二维树状数组优化dp,复杂度又O(n maxa k) 变成 O(n log(maxa k)) #include #include #include using namespace std; int maxn,n,k,a[10010],ans,tmp; struct BIT { int c[6060][550]; inline int lowbit(int x) ... 阅读全文
posted @ 2016-05-08 18:41 invoid 阅读(208) 评论(0) 推荐(0)
摘要:树形dp,bfs。 dfs爆栈。 #include #include #include using namespace std; const int maxn = 1000000 + 10; const int maxm = 2000000 + 10; int g[maxn],v[maxm],next[maxm],c[maxm],eid; int q[maxn],f[maxn],t[max... 阅读全文
posted @ 2016-05-06 16:04 invoid 阅读(133) 评论(0) 推荐(0)
摘要:二分答案。 阅读全文
posted @ 2016-05-05 14:55 invoid 阅读(96) 评论(0) 推荐(0)
摘要:dp。状态转移方程在代码里 #include #include #include using namespace std; const int maxn = 100 + 10; int a[maxn][3]; int f[maxn][maxn][maxn]; int s[maxn],s2[maxn][3]; int n,m,k; int main() { scanf("%d%d... 阅读全文
posted @ 2016-05-01 21:22 invoid 阅读(129) 评论(0) 推荐(0)
摘要:dp。转移方程在代码里。。 阅读全文
posted @ 2016-05-01 21:21 invoid 阅读(101) 评论(0) 推荐(0)
摘要:dp。 状态转移方程题解稳。 #include #include #include using namespace std; const int maxn = 100 + 10; int a[maxn][3]; int f[maxn][maxn][maxn]; int s[maxn],s2[maxn][3]; int n,m,k; int main() { scanf("%d... 阅读全文
posted @ 2016-05-01 21:19 invoid 阅读(169) 评论(0) 推荐(0)
摘要:块状链表。维护一个点f[i]次能到达下一个块,和到哪个位置。 #include #include using namespace std; const int maxn = 400000 + 100; int k[maxn],jump[maxn],st[maxn],belong[maxn],f[maxn]; int n,m,tot=1; void build() { scanf("... 阅读全文
posted @ 2016-05-01 21:16 invoid 阅读(195) 评论(0) 推荐(0)
摘要:动态规划. 首先,如果一个强连通分量的一个点在子图里,这个强连通分量所有点都在子图。所以先用tarjan算法求出强连通分量,缩点,当成一个点来处理。然后进行俩次动态规划就行了,注意判重边。 #include #include #include #include using namespace std; set > edge; const int maxn = 100000 + 10; c... 阅读全文
posted @ 2016-05-01 15:05 invoid 阅读(189) 评论(0) 推荐(0)