03 2012 档案
摘要:http://poj.org/problem?id=1840题意:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,给出a1,a2,a3,a4,a5,且xi在-50到50(除零外),有多少种满足条件的组合;思路:用hash,这里有两种,一种用map建立,不过我刚开始超时了,后来发现 for (i = -50; i <= 50; i++) x[m++] = i * i * i; 先这样处理下就行了,不过时间还是挺长的,另一种就是普通的hash了,这里我用的静态加挂链的方式;代码:View Code #include <cstdio>#include &l
阅读全文
摘要:http://poj.org/problem?id=2442题意:给出m个序列,每个序列有n个数,从每个序列中选择一个数相加,总共有n^m个数,输出这些数中最小的n个数;思路:用的是stl中的heap(堆)从上到下层层维护堆,堆的复杂度为nlogn;代码:View Code #include <cstdio>#include <iostream>#include <algorithm>using namespace std;int a[2010] = {0};int b[2010] = {0};int heap[2010] = {0};int main(){
阅读全文
摘要:http://poj.org/problem?id=1035题意:给出一些字典单词,然后给出查询的单词temp,若字典单词中有temp就直接输出,如果没有就输出1:一个字母拼写错误;2:多添加了 一个字母;3:少了一个字母;思路:用vector存的string序列,然后用string的一些特性来判断的;代码:View Code #include <cstdio>#include <string>#include <cstring>#include <iostream>#include <cstdlib>#include <vec
阅读全文
摘要:http://poj.org/problem?id=2939题意:但某个人点到两次时这个人自杀,当某个人点到三次时,循环结束,求结束时剩余的人数;思路:用哈希写,经典的题啊;(代码是参考其他队友的)代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#define inf 1000009using namespace std;struct node{ long long data; int num; int next;}node[inf];int link[inf];lon
阅读全文
摘要:http://poj.org/problem?id=2418题意:给定一些树,按字典序输出数名和树出现的频率;思路:这个题用二叉搜索树可以做,同时在网上看到了一个简单的方法,用map来做,这里map真是太好用了;map做法:View Code #include <iostream>#include <map>#include <cstdio>#include <string>using namespace std;int main(){ string a; map<string,int>tree; double n = 0; char
阅读全文
摘要:http://poj.org/problem?id=2513题意:有一些棒子,每一根的两头都有两个颜色,将这些棒子相连并且被两根棒子接头处是相同的颜色,求一些这样的棒子是否都可以全部连起来;思路:首先用tree树给每一种颜色编号,然后用并查集+欧拉路(只有两个或零个奇数结点);代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int f[500010] = {0};int n = 0;in
阅读全文
摘要:http://poj.org/problem?id=1094感觉还是挺好的一个题的,虽说是看的小媛的思路;题意:判断给出的一些字母的先后顺序,进行拓扑排序,看看是否有序;思路:用flord判断环还是挺好的,然后拓扑排序判断序列的排序关系;代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;int n = 0;int m = 0;int ma
阅读全文
摘要:http://poj.org/problem?id=3026题意:在一个y行 x列的迷宫中,有可行走的通路空格’ ‘,不可行走的墙’#’,还有两种英文字母A和S,现在从S出发,要求用最短的路径L连接所有字母,输出这条路径L的总长度;思路:用bfs找出每两个点之间的距离,然后用prim求出最小生成树;思路是参考网上的;代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>using name
阅读全文
摘要:http://poj.org/problem?id=3041View Code #include <iostream>#include <cstdio>#include <cstring>using namespace std;int map[510][510] = {0};int match[510] = {0};int value[510] = {0};int n = 0;int m = 0;int x = 0;int y = 0;int find(int q){ for(int i = 1;i <= n; ++i) { if(value[i] =
阅读全文
摘要:http://poj.org/problem?id=1273题意:有一些流水的水沟,求从起点1到达终点的最大水量,每条水沟都有一个最大流水量;思路:基础的网络流问题(EK算法),注意边的重复;View Code #include <iostream>#include <cstdio>#include <cstring>#include <queue>#define max 205using namespace std;int s[max][max] = {0};int n = 0;int m = 0;int a = 0;int b = 0;int
阅读全文
摘要:http://poj.org/problem?id=1062题意:一个人想娶酋长的女儿,酋长有个条件,就是用金币或者是用物品和少量的金币来交换,其他拥有物品的人亦可以用同样方法来交换;思路:dijkstra+枚举,思路是从网上看的,题目中的“地位较高的的人不会再和他交易”其实挺干扰人的,没有用到这个;代码:View Code #include <cstdio>#include <iostream>#include <cstdlib>#include <algorithm>#include <cstring>using namespac
阅读全文
摘要:http://acm.tju.edu.cn/toj/showp3017.htmlhttp://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=2384思路:dp题,自己脑子太笨了,代码如下,提醒一下自己;View Code #include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;int s[110] = {0};int n = 0;int m
阅读全文

浙公网安备 33010602011771号