随笔分类 -  hdu

摘要:桥的应用!虽然以前做过强联通分量的题,但刷的很水,所以比赛的时候一直想不起来是桥的应用;反省一下~~~学习一下!思路,找到权值最小的桥;用tarjin算法!代码: 1 #include 2 #include 3 #include 4 #define maxn 1003 5 using namespace std; 6 7 struct edge 8 { 9 int st,ed,w,next;10 }e[maxn*maxn*2];11 12 int head[maxn],dfn[maxn],low[maxn],nncount,best,num,dan;13 14 void addedg... 阅读全文
posted @ 2013-09-16 20:20 Yours1103 阅读(327) 评论(0) 推荐(0)
摘要:一个树形dp的题,又是一个涉及不深的领域 = =;不过在网上看到了大神用很巧的思路解决了这个题;大神的思路就是:从树的底部往上看:如果一棵子树拥有两个及以上的叶子节点,可以将这棵子树与大树分离,并且将子树化成一条直线;为什么这样子是最优呢?我不会证明,但我觉得这种情况可以保留最多不被删除的边;代码: 1 #pragma comment(linker,"/STACK:1024000000,1024000000") 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1000005 7 using namespa 阅读全文
posted @ 2013-09-16 15:02 Yours1103 阅读(228) 评论(0) 推荐(0)
摘要:数位dp题;也是我做的第一个数位dp的题目;感觉数位dp的模板性很强啊,思想都差不太多!有几个写的很好的参考资料:推荐一下:数位计数问题解法研究浅谈数位类统计问题我的代码: 1 #include 2 #include 3 #define maxn 16 4 #define ll long long 5 using namespace std; 6 7 int dp[maxn][5000]; 8 int d[maxn],sum; 9 10 ll dfs(int w,int he,bool flag)11 {12 if(he<0)return 0;13 if(!w)return ... 阅读全文
posted @ 2013-09-16 14:00 Yours1103 阅读(219) 评论(0) 推荐(0)
摘要:今天的比赛前面四个多小时没有出题,智商真是拙计;其实前面都是水题,就是想不到思路!知道最后40分钟,和小珺同志把这个计算几何的题给A了;然后小琪也马上把第3题干掉了;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 struct point3 6 { 7 double x,y,z; 8 }; 9 10 //向量大小 11 double vlen(point3 p) 12 { 13 return sqrt(p.x*p.x+p.y*p.y+p.z*p.z); 14 } 15 16 //计... 阅读全文
posted @ 2013-09-15 18:35 Yours1103 阅读(365) 评论(0) 推荐(0)
摘要:一道找规律的题,但今天的智商捉急,一直都想不到点子上;比赛之后和别人讨论的时候,在n=2的情况下,前面两个是aa,后面就接着很多个aababb,然后最后再判断下就行了~~~以后对于这种题还是不要太相信自己的主观了,打个表靠谱点!代码: 1 #include 2 #include 3 char pre[][10] = {"a", "ab", "aab", "aabb", "aaaba", "aaabab", "aaababb", "aaababbb 阅读全文
posted @ 2013-09-14 22:59 Yours1103 阅读(245) 评论(0) 推荐(0)
摘要:一道很水很水的题,比赛的时候没想清楚就乱下结论,导致我们本来可以出这题的没出;我认错,我保证以后不再出现这种情况!^ ^当初我一直没想清楚怎么处理前端0的,直到看到小珺的程序~~~看来我的逻辑能力还得加强!代码: 1 #include 2 #include 3 #define maxn 1000005 4 using namespace std; 5 int a[10],b[10],c[10][10]; 6 char s1[maxn],s2[maxn]; 7 8 int first() 9 {10 for(int k=9; k>=0; k--)11 for(int i... 阅读全文
posted @ 2013-09-12 19:34 Yours1103 阅读(179) 评论(0) 推荐(0)
摘要:最小覆盖圆的模板; 1 #include 2 #include 3 #include 4 struct Point 5 { 6 double x; 7 double y; 8 } pt[1005]; 9 struct Traingle 10 { 11 struct Point p[3]; 12 }; 13 struct Circle 14 { 15 struct Point center; 16 double r; 17 } ans; 18 //计算两点距离 19 double Dis(struct Point p, struct Po... 阅读全文
posted @ 2013-09-12 19:29 Yours1103 阅读(172) 评论(0) 推荐(0)
摘要:比赛的时候这道题一直都没出来,承启提醒我之后还是一直WA;其实规律早就找到了````其实这题还可以用数位dp来做,不过从来没写过,以后再贴;代码: 1 #include 2 #define ll long long 3 using namespace std; 4 5 ll get(ll n) 6 { 7 int s=0; 8 ll i=n/10*10; 9 ll m=n,ans=0;10 for(;i>t;36 while(t--)37 {38 cin>>a>>b;39 a--;40 cout<... 阅读全文
posted @ 2013-09-11 21:34 Yours1103 阅读(235) 评论(0) 推荐(0)
摘要:二分图,简单的模板题,不过题目比较难懂;其中important chess就是删掉它不能够完美匹配,所以就枚举每一个可能删的棋子;代码: 1 #include 2 #include 3 int map[101][101],v[101]; 4 int match[101],n,m; 5 int dfs(int k) 6 { 7 int i; 8 for(i=0; i<m; i++) 9 {10 if(map[k][i]&&!v[i])11 {12 v[i]=1;13 if(match[i]... 阅读全文
posted @ 2013-09-11 20:05 Yours1103 阅读(141) 评论(0) 推荐(0)
摘要:二分图的水题,第一次写;基本上是参考的 = = !代码: 1 #include 2 #include 3 #include 4 #define maxn 2005 5 using namespace std; 6 7 vectorve[maxn]; 8 int match[maxn]; 9 bool v[maxn];10 11 int dfs(int x)12 {13 int l=ve[x].size();14 for(int i=0; i<l; i++)15 {16 int k=ve[x][i];17 if(!v[k])18 ... 阅读全文
posted @ 2013-09-10 17:34 Yours1103 阅读(132) 评论(0) 推荐(0)
摘要:刚刚看到这个题感觉挺复杂的~~~因为它还要输出字典序;很容易知道对于任意的k,第一个输出总是1 2 #include 3 using namespace std; 4 int a[1=n;i--) printf("%d",a[i]);33 puts("");34 }35 return 0;36 }View Code 阅读全文
posted @ 2013-09-10 16:10 Yours1103 阅读(290) 评论(0) 推荐(0)
摘要:欧拉回路,利用并查集来实现;代码:#include#include#includeusing namespace std;int a[30],f[30],b[30];bool vis[30];int find(int x){ return f[x]==-1?x:f[x]=find(f[x]);}void combine(int x,int y){ int n=find(x); int m=find(y); if(n!=m) f[n]=m;}bool oula(){ int st=-1; for(int i=0; iv; for(int i=0; i<2... 阅读全文
posted @ 2013-09-09 20:16 Yours1103 阅读(222) 评论(0) 推荐(0)
摘要:欧拉回路的题;主要利用的是并查集,为了节省时间,压缩了它的路径;代码: 1 #include 2 #include 3 #define maxn 100009 4 using namespace std; 5 6 int f[maxn],rank[maxn],du[maxn]; 7 bool vis[maxn],mark[maxn]; 8 9 void make_set(int x)10 {11 f[x]=x;12 rank[x]=0;13 }14 15 int find(int x)16 {17 int p=x,k;18 while(p!=f[p])19 ... 阅读全文
posted @ 2013-09-09 18:48 Yours1103 阅读(163) 评论(0) 推荐(0)
摘要:题目很简单,我却WA了几十次,找错误找了我一个小时;蛋都碎了!后来发现错误的地方竟然是memset;用一个循环来替代它就A了;╮(╯▽╰)╭今晚回去好好的看看memset!!!发个代码纪念下,已经被我改的面目全非; 1 #include 2 #include 3 #define maxn 105 4 using namespace std; 5 double map[maxn][maxn]; 6 int x[maxn],y[maxn]; 7 bool v[maxn]; 8 9 double prim(int n)10 {11 int i,j,flag;12 v[1]=1;13... 阅读全文
posted @ 2013-09-06 17:51 Yours1103 阅读(219) 评论(0) 推荐(0)
摘要:也是一道2-sat的入门题;不过题目描述的不清楚,看了别人的题解才知道题意;和上面的那题差不多,一个模板;代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 20010 7 using namespace std; 8 9 vectorve[maxn];10 stacks;11 int low[maxn],dfn[maxn],b[maxn],nncount,cnt;12 bool instack[maxn];13 14 void tarjin(int u)15 {16 low[u]=dfn... 阅读全文
posted @ 2013-09-05 16:38 Yours1103 阅读(284) 评论(0) 推荐(0)
摘要:2-SAT的入门题;网上说这个算法最好的入门教材是:伍昱的《由对称性解2-SAT问题》的ppt和赵爽的论文《2-SAT 解法浅析》;看了一下伍昱的ppt,很好理解!而这道题相对ppt里面的例子来说更加简单;代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 2010 7 using namespace std; 8 9 vectorve[maxn];10 stacks;11 int low[maxn],dfn[maxn],b[maxn],nncount,cnt;12 bool instack[ma. 阅读全文
posted @ 2013-09-05 15:37 Yours1103 阅读(192) 评论(0) 推荐(0)
摘要:这是一道用tarjin求双连通分量的题;其中,不需要修的道路就是桥的数目;在图的每个极大环中,如果点的数目小于边的数目,显然这个环中含有子环,并且这个环的边数就是这个环中有冲突的边的数目;如果点的数模等于边的数目,那就没有冲突;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 #define maxn 10005 6 7 vectorg[maxn]; 8 int block[maxn],top,stack[maxn],dfn[maxn],low[maxn],index,res1,res2; 9 bool instack. 阅读全文
posted @ 2013-09-05 13:56 Yours1103 阅读(183) 评论(0) 推荐(0)
摘要:这是一道双联通分量的题,要用到LCA算法;听说这个算法有两种实现方式:一个是dfs+线段树或着RMQ;一个是用tarjin;我用的是tarjin;题目比较简单,就是每次加了一条边之后剩下的桥的个数;代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define MAXN 100009 7 #pragma comment(linker,"/STACk:10240000,10240000") 8 9 int n,m,cnt,NE,BridgeNum; 10 int parent[M 阅读全文
posted @ 2013-09-05 11:04 Yours1103 阅读(211) 评论(0) 推荐(0)
摘要:强连通分量——tarjin 算法这道题和前面那道hdu 2767唯一不同就是,2767需要找出最小数量的边使图成为连通分量,而这个题需要一点点贪心的思想在里面,它需要求出代价最小的边使图成为连通分量;代码: 1 #include 2 #include 3 #include 4 #include 5 #define N 50006 6 using namespace std; 7 8 struct Edge 9 {10 int u, val, next;11 Edge() {}12 Edge(int a, int b, int c)13 {14 ... 阅读全文
posted @ 2013-09-04 20:12 Yours1103 阅读(366) 评论(0) 推荐(0)
摘要:强连通分量——tarjin算法;这题的思路就是找出多少个出度为0的连通分量,结果就是这些连通分量的元素的最小值相加;一道很简单的题,改了我好久,= =!~贴代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1005 7 using namespace std; 8 9 int dfn[maxn],low[maxn],pen[maxn],b[maxn];10 int nncount,ans,cc[maxn],cnt,in[maxn];11 bool instack[maxn];12 vectorv. 阅读全文
posted @ 2013-09-04 20:08 Yours1103 阅读(155) 评论(0) 推荐(0)