- 博客(49)
- 收藏
- 关注
原创 UVA 1078 Password Suspects(AC自动机+dp)
状态方程d[u][len][st],代表最后一个节点是u,长度为len,已经有st个串所能构成的密码数,记忆化搜索就行了。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>typedef long lo...
2016-11-09 21:55:35 1404 1
原创 zstu 4243 牛吃草(浮点数二分)
#include#include#include#include#includeusing namespace std;const double eps=1e-6;const double PI=acos(-1.0);struct Circle{ double x,y; double r;};double calArea(Circle c1, Circle c2
2016-11-26 13:46:31 302
转载 求两圆相交的面积
转自博客:http://blog.sina.com.cn/s/blog_850498e20100w6fq.html假设半径小的圆为c1,半径大的圆为c2。c1的半径r1,圆心坐标(x1,y1)。c2的半径r2,圆心坐标(x2,y2)。d为两圆圆心连线的长度。相交面积为Sd=sqrt((x1-x2)^2+(y1-y2)^2)(1)如果r1+r2那么两圆相离,相交面积S
2016-11-26 13:02:36 939
原创 POJ 2983 Is the Information Reliable?(差分约束系统+BellmanFord)
=号转化为>=,#include#include#include#include#include#includeusing namespace std;const int maxn=1000+5;struct edge{ int from,to,dist;};struct BellmanFord{ int n,m; vector edges; v
2016-11-26 12:47:33 221
原创 POJ 3169 Layout(差分约束系统+BellmanFord)
没看题目,一直以为这题没负环,TLE了好久。#include#include#include#include#include#includeusing namespace std;const int maxn=1000+5;const int inf=100000000;struct edge{ int from,to,dist;};struct Bellman
2016-11-26 08:57:27 217
原创 POJ 1761 Integer Intervals(差分约束系统+BellmanFord)
#include#include#include#include#include#includeusing namespace std;const int maxn=10000+5;const int inf=100000000;struct edge{ int from,to,dist;};struct BellmanFord{ int n,m; v
2016-11-26 08:02:03 201
原创 POJ 1364 King(差分约束系统+bellmanford)
这题主要n也取得到。#include#include#include#include#include#includeusing namespace std;const int maxn=100+10;struct edge{ int from,to,dist;};struct BellmanFord{ int n,m; vector edges;
2016-11-25 21:26:30 194
原创 Coderforce 380 Div2
只能滑水3题。A#includeusing namespace std;int main(){ char s[105]; int n; scanf("%d%s",&n,s); for(int i=0;i<n;i++){ if(s[i]=='o'){ int j; for(j=2;j<n;j
2016-11-21 07:45:25 189
原创 POJ 3159 Candies(差分约束+dijkstra)
根据B-A#include#include#include#include#include#includeusing namespace std;const int maxn=30000+5;const int maxc=150000+5;const int inf=100000000;struct HeapNode{ int d,u; bool operato
2016-11-20 09:15:48 242
原创 HDU 1529 Cashier Employment(差分约束系统)
论文里已经写的很清楚了。#include#include#include#includeusing namespace std;const int maxn=26;const int maxc=1000+5;const int inf=100000000;struct edge{ int u,v,dist;}edges[maxc];int cnt;int r[maxc
2016-11-19 21:51:29 186
原创 HDU 1384 Intervals(差分约束系统)
f[b]-f[a-1]>=c => f[b]>=f[a-1]+c a-1连边到b然后求最长路,然后再连边i-1到i为0,i到i-1为-1,跑最长路即可。#include#include#include#include#include#includeusing namespace std;const int maxn=50000+5;const int inf=100000000;
2016-11-19 17:05:15 210
原创 HDU 1535 Invitation Cards(BellmanFord)
#include#include#include#include#include#includeusing namespace std;const int maxn=1000000+5;const int inf=100000000;typedef long long LL;struct edge{ int from,to,dist;};struct Bellman
2016-11-19 14:48:49 154
原创 HDU 1535 Invitation Cards(dijkstra)
#include#include#include#include#include#includeusing namespace std;const int maxn=1000000+5;const int inf=100000000;typedef long long LL;struct HeapNode{ LL d; int u; bool opera
2016-11-19 14:27:03 236
原创 UVA 11478 Halum(Bellman-Ford+差分约束系统)
白书题解写的很清楚了。#include#include#include#include#includeusing namespace std;const int maxn=500+5;const int maxc=2700+5;struct edge{ int to,dist;};struct BellmanFord{ int n,m; edge edg
2016-11-19 10:06:50 240
原创 UVA 11090 Going in Cycle!(BellmanFord+二分)
自己想的时候只想到强连通缩点的做法,联系不到bellmanford,看了白书之后发现这方法好巧妙。#include#include#include#include#include#includeusing namespace std;const int maxn=50+5;struct edge{ int from,to; double dist;};struc
2016-11-19 08:35:53 268
原创 UVA 10537 The Toll! Revisited(dijkstra输出字典序最小的路径)
这题就是SB题,思路很好想,但输出字典序最小的路径卡住了,一直跑不出来,最后看了别人的代码,瞬间觉得自己的代码好挫,就把别人的代码码了出来,当作最短路输出路径的模版了。#include#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int
2016-11-18 21:11:14 410
原创 UVA 1416 Warare And Logistics(dijkstra)
思路是先暴力算出每个点的出发的最短路,然后记录下最短路树的边,枚举边,如果是最短路树上的边,那么可以删除,此时再做了一次djikstra。自己想的时候非常贴合这个思路了,感觉只能暴力了,但是感觉这样做时间复杂度太高,最后算了下时间复杂度O(n^2mlogn),大概是刚好1e8,刚好卡着时间范围= = 。以后想到思路还是仔细算一下复杂度,然后再决定写不写,好多次感觉时间爆了不敢写。
2016-11-17 21:50:00 222
原创 UVA 10917 Walk Through the Forest (dijkstra+记忆化搜索)
水题1A。#include#include#include#include#include#includeusing namespace std;const int maxn=1000+5;const int inf=100000000;struct HeapNode{ int d,u; bool operator < (const HeapNode &rhs
2016-11-17 20:30:57 190
原创 UVA 11374 Airport Express(dijkstra+枚举)
一开始想的是加一个flip标记,每条路只能由一个flip标记,但是最后发现这个标记对于记录最短时间的d数组是没有影响的。
2016-11-17 15:06:41 183
原创 POJ 3683 John's Busiest Day(2-SAT)
这题很明显2-SAT,一开始自己写的,事件算成区间去写,然后WA到死。看了下别人的时间处理方式 ,发现好巧妙,先将小时乘60,那么小时和分钟就是同一种单位,可以直接用一个整形变量来表示,输出的时候小时就是除60,分就是模60。#include#include#include#include#includeusing namespace std;const int maxn=1000
2016-11-17 09:11:29 169
原创 UVA 1391 Astronauts(2-SAT)
这题其实算是一题水题,但是一开始想错了,一直把每位宇航员的选择分为A和B了,其实应该分成的是C和!C,这样分,很容易就想出来怎么写了。#include#include#include#include#includeusing namespace std;const int maxn=100000+5;struct TwoSAT{ int n; vector G[max
2016-11-16 21:55:22 271
原创 POJ 3207 Ikki's Story IV(2-SAT)
这题理解,想法都对了,但一直WA,最后发现模版抄错了。#include#include#include#include#includeusing namespace std;const int maxn=1000+5;struct TwoSAT{ int n; vector G[maxn*2]; bool mark[maxn*2]; int s[max
2016-11-16 20:24:27 185
原创 POJ 2296 Map Labeler(二分+2-SAT)
水题吧。#include#include#include#include#includeusing namespace std;const int maxn=100+5;struct TwoSAT{ int n; vector G[maxn*2]; bool mark[maxn*2]; int s[maxn*2],c; bool
2016-11-16 10:32:47 253
原创 HDU 3062 Party(2-SAT)
对2-SAT有了点感觉。#include#include#include#include#includeusing namespace std;const int maxn=1000+5;struct TwoSAT{ int n; vector G[maxn*2]; bool mark[maxn*2]; int s[maxn*2],c;
2016-11-15 16:23:40 207
原创 HDU 3622 Bomb Game(2-SAT)
#include#include#include#include#include#includeusing namespace std;const double eps=1e-5;const int maxn=100+5;struct TwoSAT{ int n; vector G[maxn*2]; bool mark[maxn*2]; int s
2016-11-15 15:09:24 210
原创 HDU 1814 Peaceful Commission(2-SAT)
#include#include#include#include#includeusing namespace std;const int maxn=10000+5;struct TwoSAT{ int n; vector G[maxn*2]; bool mark[maxn*2]; int s[maxn*2],c; bool dfs(
2016-11-14 21:34:44 267
原创 UVA 1146 Now or later(2-SAT)
#include#include#include#include#includeusing namespace std;const int maxn=2000+5;struct TwoSAT{ int n; vector G[maxn*2]; int mark[maxn*2]; int s[maxn*2],c; bool dfs(in
2016-11-14 21:27:37 247
原创 UVA 11324 The Largest Clique(强连通+dp)
#include#include#include#include#include#includeusing namespace std;const int maxn=1000+5;struct edge{int u,v;}e[50000+5];vector G[maxn];int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc
2016-11-13 15:50:56 209
原创 UVA 12167 Proving Equivalences(强连通)
注意最后需要枚举所有不是强连通内部边的边。#include#include#include#include#include#includeusing namespace std;const int maxn=20000+5;vector G[maxn];int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc_cnt;stack
2016-11-13 12:43:15 217
原创 UVA 1108 Mining Your Own Business(双联通分量)
这题不能在割点上放救生装置很容易想到,关键就是如果整个图都是一个双联通的话,那么就需要放两个,因为放一个的话有可能放的那个会坍塌。#include#include#include#include#include#includeusing namespace std;const int maxn=50000+5;struct edge{int u,v;};int pre[maxn]
2016-11-13 10:20:32 287
原创 UVA 1364 Knights of the Round Table(双联通+二分图)
先把所有的双联通找出来,然后对每个双联通进行二分图判断,因为双联通分量是联通的,并且二分图肯定是偶数个点,那么如果一个双联通并且他不是二分图,那么他是不符合条件的,所以减去。#include#include#include#include#include#includeusing namespace std;const int maxn=1000+5;int color[maxn]
2016-11-13 08:42:06 221
原创 UVA 1423 Guess(拓扑排序)
#include#include#include#includeusing namespace std;const int maxn=10+5;int degree[maxn],map[maxn][maxn],b[maxn],ans[maxn];char s[maxn];int n;void topo(){ int vis[maxn]; int count=0,
2016-11-12 19:27:35 281
原创 UVA Binary Search Tree(BST+计数问题)
一颗BST的种类由C(sumson,lson)得出,那么每颗子树的合并都用乘法合并,跑下dfs就行。#include#include#include#includeusing namespace std;typedef long long LL;const int maxn=25,mod=9999991;struct Node{ Node *left,*right;
2016-11-11 12:31:33 194
原创 UVA 1471 Defense Lines(set维护二元组单调队列)
#include#include#include#include#includeusing namespace std;const int maxn=200000+5;int a[maxn],f[maxn],g[maxn];int n;struct Jason{ int a,g; Jason(int a,int g): a(a),g(g) {} bool
2016-11-10 20:23:26 312
原创 UVA 1470 Castting Spells(manacher)
这题很容易看出来是个判断回文,manacher板子直接上了,但是最后被细节卡了= =。细节1:因为回文串ww^r个数肯定是偶数,所以枚举时,只能枚举‘#’的位置。细节2:因为细节1说了,'#'左右两边字符串长度一定是偶数,那么如果当前位置的v=p[i]-1必须为偶数,而且v时整个字符串的长度,所以膜4必须为0,如果不符合条件,那么只能减小回文的长度,增大是肯定不可能的。细节3:当v满足
2016-11-10 09:45:29 244
原创 UVA 10054 The Necklace(欧拉回路)
输出不能顺序输出,如果环中还有一个小环,那么dfs的时候就会回溯,那样的话顺序输出就会错误,但是逆序输出就能保证首位相接。#include#include#include#include#include#includeusing namespace std;const int maxc=50+5;int degree[maxc],vis[maxc][maxc];#define s
2016-11-09 20:06:52 219
原创 UVA 10047 The Monocycle(BFS)
#include#include#include#include#includeusing namespace std;const int maxn=25+5;struct node{ int x,y,d,c,t;};int dx[4]={-1,0,1,0};int dy[4]={0,-1,0,1};char map[maxn][maxn];int vis[maxn
2016-11-09 17:28:48 241
原创 UVA 11624 Fire!(BFS)
预处理一下每个点的着火事件。#include#include#include#include#includeusing namespace std;const int maxn=1000+5;char map[maxn][maxn];int fire[maxn][maxn],vis[maxn][maxn];int r,c;int sx,sy;int dx[4]={-1,0,1
2016-11-09 16:07:03 259
原创 UVA 1455 Kingdom(线段树+并查集)
因为c是小数,那么把c向上取整,区间低加一就可以了,其他的线段树维护。#include#include#include#includeusing namespace std;const int maxn=100000+5;struct Interval{ int sumv[5][maxn*4],addv[5][maxn*4]; void clear() {
2016-11-08 18:01:46 189
原创 UVA 11525 Permutation(树状数组)
一开始忘记康托展开的定义了,看完定义就是水题。#include#include#include#includeusing namespace std;const int maxn=50000+5;int c[maxn],a[maxn],s[maxn],vis[maxn];int n;int lowbit(int x) {return x&(-x);}void add(int x,
2016-11-08 12:43:20 233
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人