上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 18 下一页
摘要: 网络流 首先算出每行每列的数的和。 每行的值减去c,每列的值减去R 然后每行和每列之间连边,容量为19. 这样一来,(i,j)的流量相当于(i,j)的值-1. 这样就避免了流量为0不对应答案的尴尬情况。 #include #include #include using namespace std; const int maxn = 1000 + 10; const int max... 阅读全文
posted @ 2016-06-08 09:40 invoid 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 最大流。 流可以对应一种分配方式。 显然最大流就可以表示最多匹配数 #include #include #include using namespace std; const int maxn = 500 + 10; const int maxm = 100000 + 10; const int maxl = 30; const int inf = 0x3f3f3f3f; char ... 阅读全文
posted @ 2016-06-08 09:32 invoid 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 斜率优化dp。 不想写表达式。。。。 s[i]维护前缀p,sx[i]维护前缀p*x。 这样将原dp转移方程转化为了 f[i]=f[j]+(s[i-1]-s[j])x[i]-(sx[i-1]-sx[j])+c[i]。 斜率优化,当i决策时,j>k且j优于k则 x[i]>(f[j]-f[k]+sx[j]-sx[k])/(s[j]-s[k]). 这样就要维护一个下凸包。 #inclu... 阅读全文
posted @ 2016-06-02 14:40 invoid 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 莫队算法+树状数组+离散化。 一定要注意莫队转移时增加或减少的逆序对数,比较容易写挂。 离散化那部分虽然效率很低,但是很好写,正确性也很容易保证,虽然会拖慢程序运行速度,但编码的复杂度却大大降低了。 我觉得是一种不错的选择。//反正是抄的黄学长的。。 #include #include #include #include using namespace std; const int ... 阅读全文
posted @ 2016-06-01 19:47 invoid 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 莫队算法。 说白了就是乱搞。。。。。 这道题必须离线。 正解是树状数组,首先计算每个颜色第一个点构成的序列的答案。(每个颜色只有一个点,直接维护前缀和就可以了)。 然后询问按左端点排序,每回扫到一个点x,就在x的颜色的下一点的位置上+1。 这样俩个前缀和相减时,当且仅当(我一直觉得这四个字很newbee)区间里有某种颜色,答案+1。当然很多种颜色就很多个+1. 我直接莫队乱搞。第一次都... 阅读全文
posted @ 2016-06-01 16:12 invoid 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(124) 评论(0) 推荐(0) 编辑
摘要: hash 加上 平衡树(名次树)。 这道题麻烦的地方就在于输入的是一个名字,所以需要hash。 这个hash用的是向后探查避免冲突,如果用类似前向星的方式避免冲突,比较难写,容易挂掉,但也速度快些。 mod一定要取得大一些。 hash时要减去@,否则A和B的hash值会相同导致tle。 比较难写?//蒟蒻本性。。。 #include #include #include using ... 阅读全文
posted @ 2016-05-30 10:39 invoid 阅读(142) 评论(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 阅读(326) 评论(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 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 启发式合并。 启发式合并就是每次将小的合并进大的里面。每次合并复杂度为O(n),因为每回大小都会翻倍,所以总复杂度就是O(nlogn)。 首先用链表维护每一种颜色。 询问直接输出答案。 否则合并(要记住,如果俩个其中一个是空的,直接特判,否则会浪费时间导致tle)。 #include #include #include using namespace std; const int ... 阅读全文
posted @ 2016-05-28 19:03 invoid 阅读(209) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 18 下一页