|
|
|
|
|
|
09 2012 档案
hdu 1248 寒冰王座(动态)
摘要:题意:最多能买多少东西。完全背包。连接:http://acm.hdu.edu.cn/search.php?action=listproblemView Code #include <iostream>using namespace std;const int MAX=10000+10;int w[5];int dp[MAX];int cmp(int a,int b){ return a>b?a:b;}int main(){ int n,m; w[1]=150,w[2]=200,w[3]=350; while(~scanf("%d",&m)) { w
阅读全文
hdu 1203 I NEED A OFFER!(动态0-1背包)
摘要:题意:求被录取的概率连接:http://acm.hdu.edu.cn/showproblem.php?pid=1203View Code #include <iostream>using namespace std;const int MAX=10000+10;int v[MAX];double w[MAX];double dp[MAX];double cmp(double a,double b){ return a>b?a:b;}int main(){ int n,m; while(scanf("%d%d",&n,&m),n+m) { m
阅读全文
hdu 2602 Bone Collector(动态)
摘要:题意:给出一组价值的数据,再给出一组体积的数据。求在m体积下所放的物品价值最大价值。连接:http://acm.hdu.edu.cn/showproblem.php?pid=2602View Code #include <iostream>using namespace std;const int MAX=1000+10;int v[MAX];int w[MAX];int dp[MAX];int cmp(int a,int b){ return a>b?a:b;}int main(){ int k; while(~scanf("%d",&k)) {
阅读全文
hdu 1426 Sudoku Killer(数独)(深搜)
摘要:题意:数独注意:小方格内的数判断,先将整个数组按照3*3的方格划分成9个区域。123456789View Code #include <iostream>using namespace std;int map[12][12];int used[12][12];//判断9个格子中是否存在要填得数int used1[12][12];//判断这一行中是否存在要填的数int used2[12][12];//判断这一列中是否存在要填的数char ch;int sum;int temp=0;int flag;struct node{ int i,j;}step[90];int panduan(
阅读全文
hdu 1258 Sum It Up(深搜)
摘要:题意:找到不重复的,加起来等于给定的数。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1258View Code #include <iostream>#include <algorithm>using namespace std;int used[15];//标记的数int save[15];//保存更新的数int step[15];//输入的数int n,m;int sum,type;int cmp(int a,int b){ return a>b;}void dfs(int k,int x){ if(k==n) {
阅读全文
hdu 2616 Kill the monster(深搜)
摘要:题意:找到最小步骤杀死monster连接:http://acm.hdu.edu.cn/showproblem.php?pid=2616View Code #include <iostream>using namespace std;int map[15][3];int used[15];int n;int sum,temp,type;int Min=100000000;void dfs(int k,int m){ if(k==n+1)//当到达第K层的时候就不在递归下去了 { if(m>0) { return; ...
阅读全文
hdu 1180 诡异的楼梯(广搜)
摘要:题意:给定起点和终点,算时间。注意:判断扩展的点为'|'或者'-'时,到达此点楼梯的状态。本来能有优先队列做的,我犯贱咯!等一天补上优先队列的代码;连接:http://acm.hdu.edu.cn/showproblem.php?pid=1180View Code #include <iostream>using namespace std;#include <queue>const int MAX = 20+10;char map[MAX][MAX];//bool used[MAX][MAX];int starti,startj,n,m
阅读全文
HDU 2647Reward(拓扑图)
摘要:题意:过年发奖金,起始奖金为888.越后者比前者多1元。问一共发了多少奖金。注意:数据中2 1 表示有两个员工,一组数据。接下来一组数据1 2 表示先给2发奖金,再给1发奖金。也就是1的奖金为889,2的奖金为888.连接:http://acm.hdu.edu.cn/showproblem.php?pid=2647View Code #include <iostream>using namespace std;#include <vector>const int MAX=10000+10;vector<int >map[MAX];int used[MAX];
阅读全文
HDU 3342 Legal or Not(深搜+拓扑)
摘要:解题思路:没有环的拓扑图、连接:http://acm.hdu.edu.cn/showproblem.php?pid=3342View Code #include <iostream>using namespace std;const int MAX=100+10;int c[MAX];int topo[MAX][MAX];int map[MAX][MAX];int m;int n;int t;bool dfs(int k){ c[k]=-1; for(int i=0;i<n;i++) { if(map[k][i]) { if(...
阅读全文
hdu 1087 Super Jumping! Jumping! Jumping!(简单动态)
摘要:题意:求出最大子序列和解题思路:i12345map[i]14235sum[i]153611定义一个map数组保存所输入的数据,sum数组保存到达此点的最大值(采用松弛操作),在用max找最大值。注意:可能全为负数。我坑了3次。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1087View Code #include <iostream>using namespace std;int main(){ int n; while(scanf("%d",&n),n) { int sum[1100]; in...
阅读全文
hdu 1285 确定名次排名(拓扑排序)
摘要:题意:确定名次排名,符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排。注意事项:判重连接:http://acm.hdu.edu.cn/showproblem.php?pid=1285View Code #include <iostream>using namespace std;const int MAX=500+10;int map[MAX][MAX];int indegree[MAX];int main(){ int n; int m; while(~scanf("%d%d",&
阅读全文
HDU 3371 Connect the Cities (Prim算法)
摘要:题意:n总共有多少个城市;m:有多少条路;k:相连的城市有多少组。对于K:输入2是表示有两组城市有已建好的路再输入一个T 表示 这T个城市相连。几map值 为0;连接:http://acm.hdu.edu.cn/showproblem.php?pid=3371View Code #include <iostream>using namespace std;#define INF 0x7ffffff#define MAX 500+10int n,m,k;int map[MAX][MAX];int used[MAX];int dis[MAX];int sum;int step[MAX]
阅读全文
hdu 1875畅通工程再续(Prim算法)
摘要:题意:找出一条路是所有岛都联通,如果找不到就输出oh!。解题思路:本体用的是Prim算法,模板里面加一个for判断是否存在一条路能走完所有岛。在输入时判断两个岛之间的距离。View Code #include <iostream>#include <cmath>using namespace std;#define INF 0x3fffffff#define MAX 100+10double map[MAX][MAX];int used[MAX];double dis[MAX];double sum;int n;int type;struct node{ double
阅读全文
hdu1102 Constructing Roads(Prim算法)
摘要:题意:给出几个村庄修路所花费的费用,现在再给出几组已经有路的村庄。输出这些村庄联通所要生成的最小费用。处理:把已经存在的路更新为0就行了。初始化map数组时初始为-1即可。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1102View Code #include <iostream>#include <cmath>using namespace std;#define INF 0x3fffffff#define MAX 100+10int map[MAX][MAX];int used[MAX];int dis[MAX];int
阅读全文
hdu 1162 Eddy's picture(Prim算法)
摘要:题意:先算出没两点之间的长度,然后直接套用Prim模版就行。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162View Code #include <iostream>#include <cmath>using namespace std;#define INF 0x3fffffff#define MAX 100+10double map[MAX][MAX];int used[MAX];double dis[MAX];double sum;int n;struct node{ double i; double j;};vo
阅读全文
HDU 3790 最短路径问题 (dijkstra算法)
摘要:题意:找出输出的两点间最短路径,当最短路相等时输出最小费用.解题思路:定义一个结构体,里面定义两个数,一个记录权值,一个记录费用.dis数组是记录当前节点的权值和费用,map就不用说了.在松弛操作里面判断路径是否相等,若相等则判断其费用是否最小.本题还有一个很坑的地方,就是要判重,这个很重要.本题交了3次,第一次为wa,原因是没有判重,第二次是pe,一个很小的错误.View Code #include <iostream>using namespace std;const int INF=0x7ffffff;const int MAX=1000+10;int used[MAX];i
阅读全文
hdu 1879继续畅通工程(最小生成树Prim)
摘要:题意:计算出全省畅通需要的最低成本,本题是一个Prim算法的模版题,加一个判断就可以了.当该路短已经存在时就令其为0.连接:http://acm.hdu.edu.cn/showproblem.php?pid=1879View Code #include <iostream>using namespace std;const int INF=0x7ffffff;const int MAX=100+10;int map[MAX][MAX];int used[MAX];int dis[MAX];int sum;int n;void Prim(){ memset(used,0,sizeof
阅读全文
hdu 1385Minimum Transport Cost (floyd算法加记录路径)
摘要:题意:运输货物,从一个地方到另一个地方所需要的最小花费。中途经过的城市还要交税费,只有起点和终点不用交。并记录运输所走过的路径,在运费相同时输出字典序的路径,也就是最小的路径(当不是最短的路径)。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1385解题思路:floyd算法,开一个数组(path)记录当前点上一个点的位置。在floyd算法中判断是否为节点最小的路径。View Code #include <iostream>//using namespace std;int map[110][110];int path[110][110];
阅读全文
hdu 2544 最短路(floyd算法)
摘要:题意:就不再说了,用floyd 算法时 复杂度蛮高的 但是 代码简单 超级简单连接:http://acm.hdu.edu.cn/showproblem.php?pid=2544View Code #include <iostream>//floyd 算法 很简单的floydusing namespace std;#define INF 0xfffffff#define MAX (10000+10)int map[MAX][MAX];void init(int n)//各种初始化{ for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++.
阅读全文
hdu 2544 最短路(dijkstra算法)
摘要:题意同上连接:http://acm.hdu.edu.cn/showproblem.php?pid=2544View Code #include <iostream>using namespace std;#define INF 0x3fffffff#define MAX (10000+10)int dis[MAX];int map[MAX][MAX];int used[MAX];void init(int n)//各种初始化{ for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { map[i...
阅读全文
hdu 2544 最短路(spfa算法)
摘要:题意:题意很好理解,就是从起点带终点的最短距离。连接:http://acm.hdu.edu.cn/showproblem.php?pid=2544View Code 1 #include <iostream> 2 using namespace std; 3 #define INF 0x3fffffff 4 #include <queue> 5 #define MAX 1000+10 6 int map[MAX][MAX]; 7 int n; 8 int m; 9 int dis[MAX];10 void spfa(int k)11 {12 int used[MAX];
阅读全文
|
|