05 2013 档案

摘要:http://poj.org/problem?id=1061数论,单变元模线性方程 1 #include <stdio.h> 2 3 long long extend_gcd(long long a, long long b, long long &x, long long &y) 4 { 5 if(b == 0) 6 { 7 x = 1; 8 y = 0; 9 return a;10 }11 else12 {13 long long r = extend_gcd(b, a%b, y, x... 阅读全文
posted @ 2013-05-31 11:31 Yuan1991 阅读(151) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2153二分查找 1 #include <stdio.h> 2 #include <iostream> 3 #include <string> 4 #include <string.h> 5 #include <map> 6 7 using namespace std; 8 9 int n, m;10 map<string, int> map1;11 int count1[10010] = {0};12 int sort1[10010];13 14 string ctos 阅读全文
posted @ 2013-05-29 10:18 Yuan1991 阅读(124) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2007计算几何,凸包,逆时针排序 1 #include <stdio.h> 2 #include <vector> 3 #include <queue> 4 #include <algorithm> 5 #include <math.h> 6 7 using namespace std; 8 9 const double eps = 1e-8; 10 11 int cmp(double x) 12 { 13 if(fabs(x) < eps) return 0; 14 if( 阅读全文
posted @ 2013-05-28 20:43 Yuan1991 阅读(135) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2084组合数学,Catalan数,高精度 1 #include <stdio.h> 2 #include <string> 3 #include <iostream> 4 5 using namespace std; 6 7 const int ten[4] = {1, 10, 100, 1000}; 8 const int max1=1000; 9 10 struct BigNumber{ 11 int d[max1]; 12 BigNumber(string s) 13 { 14 ... 阅读全文
posted @ 2013-05-28 16:48 Yuan1991 阅读(160) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2001数据结构,Trie 1 #include <stdio.h> 2 #include <string.h> 3 4 const int CHARSET = 26, BASE = 'a', MAX_NODE = 20100; 5 6 struct trie 7 { 8 int tot, root, child[MAX_NODE][CHARSET]; 9 bool flag[MAX_NODE];10 int cnt[MAX_NODE];11 trie()12 {13 memset(... 阅读全文
posted @ 2013-05-27 20:51 Yuan1991 阅读(115) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2051数据结构,优先队列 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 5 using namespace std; 6 7 priority_queue<pair<int, int> > q; 8 9 int main()10 {11 char s[12] = "\0";12 int i, n, id, t[3003];13 pair<int, int> pair1; 阅读全文
posted @ 2013-05-27 19:11 Yuan1991 阅读(138) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2992数学,质数,快速求n!中质数p的个数 1 #include <stdio.h> 2 #include <string.h> 3 4 int valid[441] = {0}; 5 int ans[100], tot = 0; 6 7 //O(N)筛质数表 8 void get_prime(int n) 9 {10 int i, j;11 for(i=2; i<=n; i++)12 {13 if(valid[i] == 0)14 {15 tot ++;1... 阅读全文
posted @ 2013-05-27 15:10 Yuan1991 阅读(157) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2965搜索没用搜索,按一个大神的算法做的 1 #include <stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 int i, j, k, a[4][4], sum = 0; 7 char c; 8 memset(a, 0, sizeof(a)); 9 for(i=0; i<4; i++)10 {11 for(j=0; j<4; j++)12 {13 scanf("%c", &c);14 ... 阅读全文
posted @ 2013-05-26 17:12 Yuan1991 阅读(102) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3660图论,最短路,floyd 1 #include <stdio.h> 2 #define N 123 3 4 const int inf = 1<<29; 5 int n, g[N][N]; 6 7 int min(int x, int y) 8 { 9 return x<y? x: y;10 }11 12 void floyd()13 {14 for(int k=1; k<=n; k++)15 {16 for(int i=1; i<=n; i++)17 {18 ... 阅读全文
posted @ 2013-05-26 11:47 Yuan1991 阅读(111) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3615图论,最短路,DP,floyd 1 #include <stdio.h> 2 #define N 321 3 4 const int inf = 1<<29; 5 int n, g[N][N]; 6 7 int min(int x, int y) 8 { 9 return x<y? x: y;10 }11 12 int max(int x, int y)13 {14 return x>y? x: y;15 }16 17 void floyd()18 {19 for(int k=1; k<=n; 阅读全文
posted @ 2013-05-26 11:25 Yuan1991 阅读(106) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3090数论,欧拉函数,递推求欧拉函数 1 #include <stdio.h> 2 3 const int maxn = 1010; 4 5 int minDiv[maxn], phi[maxn], sum[maxn]; 6 7 void genPhi() 8 { 9 for(int i=1; i<maxn; i++)10 {11 minDiv[i] = i;12 }13 for(int i=2; i*i<maxn; i++)14 {15 if(minDiv[i]... 阅读全文
posted @ 2013-05-25 21:15 Yuan1991 阅读(173) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1142数学,分解质因数 1 #include <stdio.h> 2 #include <math.h> 3 #define N 10000000 4 5 int a[N], b[N], tot; 6 7 int f(int x) 8 { 9 int sum = 0;10 while(x)11 {12 sum += x%10;13 x /= 10;14 }15 return sum;16 }17 18 int factor(int n)19 {20 int ... 阅读全文
posted @ 2013-05-25 20:44 Yuan1991 阅读(169) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1006数论,中国剩余定理 1 #include <stdio.h> 2 3 int extend_gcd(int a, int b, int &x, int &y) 4 { 5 if(b == 0) 6 { 7 x = 1; 8 y = 0; 9 return a;10 }11 int r = extend_gcd(b, a%b, y, x);12 y -= x*(a/b);13 return r;14 }15 16 int CRT(int a... 阅读全文
posted @ 2013-05-25 19:27 Yuan1991 阅读(190) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2115数论,模线性方程 1 #include <stdio.h> 2 #include <vector> 3 4 using namespace std; 5 6 long long extend_gcd(long long a, long long b, long long &x, long long &y) 7 { 8 if(b == 0) 9 {10 x = 1;11 y = 0;12 return a;13 }14 long long r = ext... 阅读全文
posted @ 2013-05-25 16:36 Yuan1991 阅读(125) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2502图论,最短路,dijkstra交大模板 1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #define N 234 5 6 float dis[N], g[N][N]; 7 int n, x[N], y[N]; 8 bool v[N]; 9 const float inf = 12345;10 11 float min(float x, float y)12 {13 return x<y? x: y;14 }15 阅读全文
posted @ 2013-05-25 13:26 Yuan1991 阅读(124) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2240图论,最短路,SPFA 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #include <string> 5 #include <map> 6 #include <iostream> 7 8 #define N 123 9 10 using namespace std; 11 12 int n, m, src; 13 int x[N], y[N], len[N]; 14 float 阅读全文
posted @ 2013-05-25 11:25 Yuan1991 阅读(123) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1860图论,SPFA好题 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1000100 5 6 using namespace std; 7 8 int n, m, src; 9 int x[N], y[N], len[N];10 float dist[N];11 bool inQue[N];12 queue<int> que;13 const int inf = 1<<30;14 阅读全文
posted @ 2013-05-24 21:25 Yuan1991 阅读(126) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1511图论,最短路,SPFA求所有点到1 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1000100 5 6 using namespace std; 7 8 int n, m, src; 9 int x[N], y[N], len[N];10 int dist[N];11 bool inQue[N];12 queue<int> que;13 const int inf = 1<< 阅读全文
posted @ 2013-05-24 17:32 Yuan1991 阅读(152) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1125最短路,floyd 1 #include <stdio.h> 2 #include <string.h> 3 #define N 123 4 5 int n, g[N][N]; 6 const int inf = 123456; 7 8 int min(int x, int y) 9 {10 return x<y? x: y; 11 }12 13 void floyd()14 {15 int i, j, k;16 for(k=1; k<=n; k++)17 {18 for(i=1; ... 阅读全文
posted @ 2013-05-24 15:14 Yuan1991 阅读(139) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3169图论,差分约束系统,SPFA 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1234 5 6 using namespace std; 7 8 int n, m, src; 9 vector<pair<int, int> > g[N];10 int dist[N];11 bool inQue[N];12 queue<int> que;13 int count[N] 阅读全文
posted @ 2013-05-24 14:30 Yuan1991 阅读(146) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2387图论,最短路单源最短路,Dijkstra O(N^2) 1 #include <stdio.h> 2 #include <string.h> 3 #define N 1234 4 5 const int inf = 1<<25; 6 int n; 7 int path[N], vis[N]; 8 int cost[N][N], lowcost[N]; 9 10 void dijkstra(int beg)11 {12 int i, j, min1;13 memset(vis, 0, sizeof(v 阅读全文
posted @ 2013-05-24 07:55 Yuan1991 阅读(120) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1463DP,树状DP,或二分图匹配 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <vector> 5 using namespace std; 6 7 const int N = 1505; 8 9 int pre[N];10 bool flag[N];11 vector<int> map[N];12 int n;13 14 int find(int x)15 {16 int 阅读全文
posted @ 2013-05-23 19:52 Yuan1991 阅读(155) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1947DP,树状DP一棵节点为N的树,去掉最少的边,满足剩下树中,有一棵树的节点数为P还要用分组背包优化,分组背包自己想的思路,写的比较难看。。。dp[i][j]:表示以节点i为根的树,如果想要保证有j个节点,至少要去掉的边数对于每组dp[i],只能选一种j,如果不选这一组,也要多消耗1的费用叶子节点初始化:dp[i] = {0, 1, 正无穷, 正无穷.......};之后看了一下背包九讲:还可以把每个节点看成一个物品,那就成了背包九讲中的“泛化物品”背包,之前没理解泛化的意思,现在有了一个大概的理解了安背包九讲的定义,这题可以简述成:有 阅读全文
posted @ 2013-05-23 17:55 Yuan1991 阅读(147) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1848DP, 树状DP一个节点形成环的过程中只有3种状态,0:有0条边连着这个点1:有1条边连着这个点2:有2条边连着这个点转移还可以再优化,不过不太好写,直接上3层循环。。。代码中inf的定义:至少要添无穷多个边,才可以满足要求 ---等价于---> 添多少都没用 1 #include <stdio.h> 2 #include <vector> 3 #define N 123 4 5 using namespace std; 6 7 vector<int> a[N]; 8 int mark[N], 阅读全文
posted @ 2013-05-22 16:58 Yuan1991 阅读(144) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1056Trie有一些字符串,判断是否:这些字符串之间都不是彼此的前缀 1 #include <stdio.h> 2 #include <string.h> 3 4 const int CHARSET = 2, BASE = '1', MAX_NODE = 1001; 5 6 int tot, root, child[MAX_NODE][CHARSET]; 7 bool flag[MAX_NODE]; 8 9 void init()10 {11 memset(child, 0, sizeof(child 阅读全文
posted @ 2013-05-18 20:56 Yuan1991 阅读(169) 评论(0) 推荐(0)