• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Siriuslzx

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理
上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页

2012年8月24日

poj - 2777 Count Color
摘要: 用线段树统计染色问题。题意是每次把一个区间的一段区域染上某个色,统计任意区间内有多少种颜色。这题我借鉴了罗前辈的思路,用int型按位记录一个区间内的颜色,修改和查询都是从结点开始,递归操作子区间。不过我最自豪的是,我略加修改了一下,使得我这个线段树不需要建树也能运行,当成功A了以后我特别爽。为什么不建树也行呢?建树本质上就是初始化,而我的代码里tree[1] = 1和向下传递这两个部分已经完成了初始化的任务,也就是说build()被内嵌到change()里面去了。所以即使没有表面上的建树,依然能正确运行。 1 #include <stdio.h> 2 #include <st 阅读全文
posted @ 2012-08-24 19:01 Siriuslzx 阅读(215) 评论(0) 推荐(0)
 

2012年8月20日

poj - 2513 Colored Sticks
摘要: Tire + 并查集 + Eular回路,花了老长时间呢。 1 #include <stdio.h> 2 #include <string.h> 3 const int N = 500050; 4 int next[5*N][26],d[5*N],cnt=0; 5 int fa[N],col[N],D[N],color=0; 6 int inst(char *t) 7 { 8 int u = 0,idx; 9 while(*t)10 {11 idx = *t -'a';12 if(!next[u][idx])13 {14 ... 阅读全文
posted @ 2012-08-20 17:02 Siriuslzx 阅读(133) 评论(0) 推荐(0)
 
poj - 2418 Hardwood Species
摘要: 二叉排序树,第一次做的时候状态不好,就放弃了,现在一看,怎么这么简单? 1 #include <stdio.h> 2 #include <string.h> 3 struct Node 4 { 5 char name[40]; 6 int d,lc,rc; 7 void init(char *t) 8 { 9 strcpy(name,t);10 lc = rc = 0;11 d = 1;12 }13 }a[10050];14 int cnt = 1,num=0;15 void inst(char *s, i... 阅读全文
posted @ 2012-08-20 16:58 Siriuslzx 阅读(158) 评论(0) 推荐(0)
 
poj - 1521 Entropy
摘要: Huffman的题,基本都是用pq水过。今天我才知道,计算压缩后编码总长度,只要用加的方法就行了。 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 using namespace std; 5 int main() 6 { 7 char ss[1000]; 8 int i,l,n,a,b; 9 int d[40];10 while(scanf("%s",ss),strcmp(ss,"END"))11 {12 memset(d,0,sizeo 阅读全文
posted @ 2012-08-20 16:55 Siriuslzx 阅读(162) 评论(0) 推荐(0)
 

2012年7月24日

poj - 2253 Frogger
摘要: 这题要说是最短路吧,其实更像DP,因为不需要把路径相加,而是更新为最小值。做这题最大的收获就是我才知道原来优先队列也能间接排序,自己写个cmp就行了,而且原理和sort的cmp一样。真的要感谢che学长。 1 #include <stdio.h> 2 #include <string.h> 3 #include <cmath> 4 #include <queue> 5 #include <vector> 6 using namespace std; 7 int n,m=1; 8 double d[205]; 9 bool used[2 阅读全文
posted @ 2012-07-24 22:56 Siriuslzx 阅读(134) 评论(0) 推荐(0)
 
poj - 3259 Wormholes
摘要: 这题和poj 1860很像,不过那个是求上升回路,这题是求下降回路。 1 #include <stdio.h> 2 #include <string.h> 3 int u[5400],v[5400],w[5400]; 4 int d[505]; 5 int n,m1,m2; 6 bool Bellman() 7 { 8 int i,j; 9 memset(d,0x3f,sizeof(d));10 d[1] = 0;11 for(j = 1; j < n; j++)12 {13 bool ok = 1;14 for(i = ... 阅读全文
posted @ 2012-07-24 22:53 Siriuslzx 阅读(153) 评论(0) 推荐(0)
 
poj - 2240 Arbitrage
摘要: 同样是套汇问题,这题要简单些,我为了多练,换成Floyd算法了。Floyd最大的优点就是写起来简单。 1 #include <stdio.h> 2 #include <string.h> 3 int m,n,cas=1; 4 char name[35][40]; 5 double rate[30][30]; 6 int find(char *s) 7 { 8 for(int i = 0; i < n; i++) 9 if(!strcmp(s,name[i]))10 return i;11 return -1;12 }13 bool Flo... 阅读全文
posted @ 2012-07-24 22:50 Siriuslzx 阅读(163) 评论(0) 推荐(0)
 
poj - 1860 Currency Exchange
摘要: 最短路问题,用Bellman算法判断有无正向环。 1 #include <stdio.h> 2 double M[105],orig; 3 int m,n,s; 4 typedef struct 5 { 6 int u,v; 7 double r,c; 8 void init(int a,int b,double q,double p) 9 {u = a; v = b; r = q; c = p;}10 }Edge;11 Edge ed[205];12 void read_graph()13 {14 int a,b,i;15 double q,w... 阅读全文
posted @ 2012-07-24 22:46 Siriuslzx 阅读(178) 评论(0) 推荐(0)
 
poj - 1258 Agri-Net
摘要: 就是简单的最小生成树,本来用卡尔(Kruskal)算法写也没什么难的,可是偏偏要求用Prim写,搞得我很纠结,总算明白为什么白书里不说它了,因为写起来真的很麻烦,效率也不见得高多少。 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 using namespace std; 5 int a[105][105]; 6 bool vis[105]; 7 typedef struct 8 { 9 int a,b,w;10 void init(int x,int y,int z)11 {a 阅读全文
posted @ 2012-07-24 08:26 Siriuslzx 阅读(167) 评论(0) 推荐(0)
 
poj - 2367 Genealogical tree
摘要: 简单的拓扑排序,就是每次寻找入度为0的点,高级一些的BFS算法本质上和这个也是一样的。 1 #include <stdio.h> 2 #include <string.h> 3 #include <vector> 4 using namespace std; 5 vector <int > a[105]; 6 int in[105],ans[105]; 7 int main() 8 { 9 int n,m,i,j,t,l;10 while(~scanf("%d",&n))11 {12 memset(in,0,sizeo 阅读全文
posted @ 2012-07-24 08:22 Siriuslzx 阅读(182) 评论(0) 推荐(0)
 
上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页