摘要: 好题 整理下思路~~ 前面做过一道这样的问题: 1……N里有多少个数X,满足(X,N)=C 一种解法是这样的: X=x*C,N=n*C,则(x,n)=1 即求x的个数 (x,n)=1 && x<=n( x*C<=n*C=N ) 则x的个数即为phi(n)=phi(N/c) 现在这个问题是这样的: X属于1……a,Y属于1……b (不妨设a<=b) 求解数对X,Y的个数,满足(X,Y)=C 我的解法是这样的: X=x*C,Y=y*C,(x,y)=1 枚举x,对于一个特定的x,y满足: (x,y)=1; x<=y; y<=b/C ( y*C=Y< 阅读全文
posted @ 2013-05-25 21:55 kiwi_bird 阅读(121) 评论(0) 推荐(0) 编辑
摘要: hdu2227树状数组的一个经典应用。容易得到dp方程,dp[pos]表示前pos项里以a[pos]结尾的非降子序列的个数。则有dp[pos]=sum( dp[i] , 1<= i <pos && a[i]<=a[pos] ) + 1。复杂度为O(n^2),Time Limit Exceeded!!!观察到a[i]<=a[pos] , 我们对原序列a从小到大排序,得到新的序列d,对d进行dp。此时dp[pos]=sum(dp[i],1<=i<pos && d[i]的原序在d[pos]的原序之前 ) + 1。对于元素d[pos] 阅读全文
posted @ 2013-04-17 00:03 kiwi_bird 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 题意:有n种珠宝,每件珠宝有必须要买的数量ai和单价pi,c种珠宝的单价递增。如果买了某种珠宝,需要额外付一次10*pi的费用(据说是为了防止你只买一件。。。),同时可以买同等数量单价高的珠宝代替单价低的珠宝,这样可能会省一些钱。求买完所需的珠宝需要的最少花费。分析:比如5……n的珠宝中,第6,7,9,11种珠宝被购买,称为A,其余是被替换的,称为B。那么对于第4种珠宝,若选择购买B类珠宝,那么都没有选择自己优。若选择购买A类珠宝,那么选择第6种珠宝最优。原因是一样的,首先是价钱在同类中最低,而且对于1……3种珠宝的替换在同类中最有利。可以发现,6,7,9,11 or 6,8,12,15,or 阅读全文
posted @ 2013-02-07 21:10 kiwi_bird 阅读(535) 评论(0) 推荐(0) 编辑
摘要: 这个题目如果直接暴力枚举的话,复杂度是n*C(n,k),最坏情况约10^37。考察下面这种情况:(n=5,k=3,粗体及加下划线的节点为depot所在地)① ② ③ ④ ⑤① ② ③ ④ ⑤对于④及以后的节点,在④被选中后,距离它们最短的depot一定不会在④之前(因为距离一定比④远)。也就是说④及之后节点的最优情况与④之前的节点无关,图示两种情况对于④及以后节点是等价的。状态基本上就出来了。我从中提取出的状态是[s][num],表示在s号节点被选定后,节点s……n之间还剩num个位置要选时的最优值。预处理出disSum[N][N]数组,表示在节点i和节点j被选定后(j>i),i……j之 阅读全文
posted @ 2013-02-02 21:29 kiwi_bird 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int MAXN = 2000000000; 6 7 bool vis[32][21][15][13]; 8 int f2[32]={1},f3[21]={1},f5[15]={1},f7[13]={1}; 9 int dd[6000],cnt;10 11 void dp(int a,int b,int c,int d,long long x)12 {13 if( vis[a] 阅读全文
posted @ 2013-01-19 22:35 kiwi_bird 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 大部分是风神博客上的题目,我在此基础上增删了些题目。【HDU】1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★1232 畅通工程 基础并查集★1811 Rank of Tetris 并查集+拓扑排序★★3926 Hand in Hand 同构图★3938 Portal 离线+并查集★★2860 并查集★1558 Segment set 计算几何+并查集★2144 LCS(连续)+并查集(重点是处理LCS)★★1829&a 阅读全文
posted @ 2012-12-22 14:24 kiwi_bird 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 样例是这样的:Sample Inputblue redred violetcyan blueblue magentamagenta cyanSample OutputPossible把棍子看做无向边,把端点看做点,且颜色相同的端点视作同一点。画成图后,是这个样子:题目的问题是,是否能把这些棍子排成一条直线,且连接处颜色相同。如图,(v,e1,r,e2,b,e3,c,e4,m,e5,b)即为一种可行解。这样点边交替的序列,包含了图中的每一条边,且每条边只走过一次。这样的序列就是一条欧拉迹。(欧拉迹包括欧拉环游和欧拉通路,欧拉环游的起点和终点相同,而欧拉通路则不同。含有欧拉环游的图称为欧拉图。含有 阅读全文
posted @ 2012-12-21 21:47 kiwi_bird 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 1 #include<cstdio> 2 #include<cstring> 3 const int maxnode = 100005; 4 5 char data[10005][15]; 6 struct Trie 7 { 8 int tree[maxnode][10],sz; 9 int amount[maxnode];10 void init(void)11 {12 sz=0;13 memset(tree[0],0,sizeof(tree[0]));14 memset(amount,0,sizeof(am... 阅读全文
posted @ 2012-12-15 20:06 kiwi_bird 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 6 int tree[205]; 7 struct edge 8 { 9 int s,e,w;10 }data[1005];11 12 bool cmp(const edge&a,const edge&b)13 {14 return a.w<b.w;15 }16 17 int find(int x)18 {19 if( -1==tree[x] ) return x 阅读全文
posted @ 2012-12-12 09:06 kiwi_bird 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<queue> 5 using namespace std; 6 7 const int MAXN = 10005; 8 9 int tree[MAXN],indegree[MAXN],n,m; 10 int first[MAXN],sn[2*MAXN],en[2*MAXN],next[2*MAXN]; 11 struct edge 12 { 13 int s,e,type; 14 }data[2*MA 阅读全文
posted @ 2012-12-08 16:33 kiwi_bird 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1 #include<cstdio> 2 #include<cstring> 3 #include<set> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 8 const int dx[4]={-1,0,1,0}; 9 const int dy[4]={0,-1,0,1}; 10 11 struct node 12 { 13 int x[4],y[4]; 14 }sn,en,tmp; 15 queue<node> Q[2]; 16 set& 阅读全文
posted @ 2012-11-24 17:39 kiwi_bird 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 1 #include<iostream> 2 #include<string.h> 3 #include<queue> 4 #define PROCESS a=min3(next.p1,next.p2,next.p3);c=max3(next.p1,next.p2,next.p3);b=next.p1+next.p2+next.p3-a-c;if( hash[a][b][c] ) continue;hash[a][b][c]=true;next.dist=cur.dist+1;if( a==c ) return next.dist;Q.push(next); 阅读全文
posted @ 2012-11-24 14:02 kiwi_bird 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 #include<algorithm> 5 #define INF 0x7fffffff 6 using namespace std; 7 8 char maze[11][11],dire[4][2]={-1,0,1,0,0,-1,0,1}; 9 bool hash[11][11][2]; 10 typedef struct 11 { 12 int x,y,dist; 13 bool jewel; 14 }node; 15 n 阅读全文
posted @ 2012-11-24 13:59 kiwi_bird 阅读(234) 评论(0) 推荐(0) 编辑
摘要: Dfs:大部分是直接递归枚举,即求满足约束条件下的解,虽不用剪枝,但也需要代码能力。练习递归枚举的题目:1241 Oil Deposits (dfs的连通块个数)1016 Prime Ring Problem1584 蜘蛛牌(简单dfs,简单的剪枝,还有人用DP做(???))1426 Sudoku Killer(练习递归的好题目 or Dancing links(???))2510 符号三角形(打表题,写写打表程序还是不错的)2553 N皇后问题(在n较小时,是经典的练习递归枚举的题目,n较大时状压(???))2677 Dota all stars( 单纯练习递归的题目+串的处理 )3350 阅读全文
posted @ 2012-11-24 13:54 kiwi_bird 阅读(3504) 评论(0) 推荐(1) 编辑
摘要: ①简单bfs+状压(赤果果)View Code 1 #include<stdio.h> 2 #include<queue> 3 using namespace std; 4 5 int n,m,data[10][2]; 6 struct node 7 { 8 int spell,dist,hp; 9 };10 11 int bfs(void)12 {13 node sn={0,0,m};14 queue<node> Q;15 16 Q.push(sn);17 while( !Q.empty() )18 {19 node cur... 阅读全文
posted @ 2012-11-22 21:35 kiwi_bird 阅读(160) 评论(0) 推荐(0) 编辑