Poj OpenJudge 百练 1062 昂贵的聘礼
1.Link:
http://poj.org/problem?id=1062
http://bailian.openjudge.cn/practice/1062/
2.Content:
昂贵的聘礼
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37631 Accepted: 10872 Description
年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。"探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,他可以降低价格。探险家于是又跑到其他地方,其他人也提出了类似的要求,或者直接用金币换,或者找到其他东西就可以降低价格。不过探险家没必要用多样东西去换一样东西,因为不会得到更低的价格。探险家现在很需要你的帮忙,让他用最少的金币娶到自己的心上人。另外他要告诉你的是,在这个部落里,等级观念十分森严。地位差距超过一定限制的两个人之间不会进行任何形式的直接接触,包括交易。他是一个外来人,所以可以不受这些限制。但是如果他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。因此你需要在考虑所有的情况以后给他提供一个最好的方案。
为了方便起见,我们把所有的物品从1开始进行编号,酋长的允诺也看作一个物品,并且编号总是1。每个物品都有对应的价格P,主人的地位等级L,以及一系列的替代品Ti和该替代品所对应的"优惠"Vi。如果两人地位等级差距超过了M,就不能"间接交易"。你必须根据这些数据来计算出探险家最少需要多少金币才能娶到酋长的女儿。Input
输入第一行是两个整数M,N(1 <= N <= 100),依次表示地位等级差距限制和物品的总数。接下来按照编号从小到大依次给出了N个物品的描述。每个物品的描述开头是三个非负整数P、L、X(X < N),依次表示该物品的价格、主人的地位等级和替代品总数。接下来X行每行包括两个整数T和V,分别表示替代品的编号和"优惠价格"。Output
输出最少需要的金币数。Sample Input
1 4 10000 3 2 2 8000 3 5000 1000 2 1 4 200 3000 2 1 4 200 50 2 0Sample Output
5250Source
3.Method:
dijkstra算法的应用,这题还增加了等级的考虑,我使用的枚举,然后运用算法前直接排除掉等级不符合要求的
4.Code:
#include <iostream>
#include <cstring>
#include <limits>
#include <cstdlib>
#include <cmath>
using namespace std;
int intMax = numeric_limits<int>::max();
int main()
{
//freopen("D://input.txt","r",stdin);
int i,j, k, ii;
int m, n;
cin >> m >> n;
//cout << m << " " << n << endl;
int **arr_map = new int*[n];
; i < n; ++i)
{
arr_map[i] = new int[n];
; j < n; ++j) arr_map[i][j] = intMax;
}
int *arr_p = new int[n];
int *arr_L = new int[n];
int p,L,x;
; i < n; ++i)
{
cin >> p >> L >> x;
arr_p[i] = p;
arr_L[i] = L;
int t,v;
; j < x; ++j)
{
cin >> t >> v;
arr_map[t - ][i] = v;
}
}
//for(j = 0; j < n; ++j)
//{
// for(k = 0; k < n; ++k) cout << arr_map[j][k] << " ";
// cout << endl;
//}
//cout << endl;
];
int *arr_d = new int[n];
bool *arr_m = new bool[n];
int **arr_map2 = new int*[n];
; i < n; ++i) arr_map2[i] = new int[n];
; i < n; ++i)
{
; ii <= m; ++ii)
{
int l_bettom = arr_L[i] - m + ii;
int l_top = arr_L[i] + ii;
; j < n; ++j) memcpy(arr_map2[j], arr_map[j], sizeof(int) * n);
; j < n; ++j)
{
/*if(abs(arr_L[j] - arr_L[i]) > m)
{
for(k = 0; k < n; ++k)
{
arr_map2[k][j] = intMax;
arr_map2[j][k] = intMax;
}
}*/
if(arr_L[j] < l_bettom || arr_L[j] > l_top)
{
; k < n; ++k)
{
arr_map2[k][j] = intMax;
arr_map2[j][k] = intMax;
}
}
}
//for(j = 0; j < n; ++j)
//{
// for(k = 0; k < n; ++k) cout << arr_map2[j][k] << " ";
// cout << endl;
//}
//cout << endl;
memcpy(arr_d, arr_map2[i], sizeof(int) * n);
memset(arr_m, ,sizeof(bool) * n);
arr_d[i] = ;
arr_m[i] = true;
; j < n; ++j)
{
int min_d = intMax;
int idx_d;
; k < n; ++k)
{
if(!arr_m[k] && min_d > arr_d[k])
{
min_d = arr_d[k];
idx_d = k;
}
}
if(min_d == intMax) break;
arr_m[idx_d] = true;
; k < n; ++k)
{
if(!arr_m[k] && arr_map2[idx_d][k] != intMax && min_d + arr_map2[idx_d][k] < arr_d[k])
{
arr_d[k] = min_d + arr_map2[idx_d][k];
}
}
//for(k = 0; k < n; ++k) cout << arr_d[k] << " ";
//cout << endl;
}
] != intMax && min_p > arr_d[] + arr_p[i]) min_p = arr_d[] + arr_p[i];
}
}
cout << min_p << endl;
; i < n; ++i) delete [] arr_map2[i];
delete [] arr_map2;
delete [] arr_m;
delete [] arr_d;
delete [] arr_L;
delete [] arr_p;
; i < n; ++i) delete [] arr_map[i];
delete [] arr_map;
;
}
5.Reference:
Poj OpenJudge 百练 1062 昂贵的聘礼的更多相关文章
- Poj OpenJudge 百练 1860 Currency Exchang
1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...
- Poj OpenJudge 百练 2602 Superlong sums
1.Link: http://poj.org/problem?id=2602 http://bailian.openjudge.cn/practice/2602/ 2.Content: Superlo ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- Poj OpenJudge 百练 Bailian 1008 Maya Calendar
1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...
- poj 1062 昂贵的聘礼 (dijkstra最短路)
题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submission ...
- 最短路(Dijkstra) POJ 1062 昂贵的聘礼
题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...
- POJ 1062 昂贵的聘礼(图论,最短路径)
POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...
随机推荐
- offer档次排名,2014最新版
转自:http://tieba.baidu.com/p/2748469183 综合考虑发展,薪水,环境,压力. 第0档:美国互联网总部special offer(15万刀起薪) 第一档: 股份制银行总 ...
- STC51系列单片机免掉电下载(热启动下载)
相信喜欢单片机的朋友都用过STC的单片机,用过STC单片机的朋友都有这种感受:实惠.易用.功能强大!就是每次下载都要冷启动特别恶心,相信很多朋友的开发板上的电源键都按烂了. 其实STC单片机可以不用免 ...
- PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
文档注释,无非“//”和“/**/”两种 ,自己写代码,就那么点,适当写几句就好了:但是一个人总有融入团队的一天,团队的交流不是那几句注释和一张嘴能解决的,还需要通用的注释标准. PHPDoc是PHP ...
- Localizing WPF with .resx files
WPF用Resource.resX中的字符串进行国际化 增加命名空间 xmlns:prop="clr-namespace:XXAppName.Properties" 引用的地方的格 ...
- oc中的block
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- Android Studio常用快捷键汇总(mac)
查看原文:http://blog.csdn.net/u010818425/article/details/52266195 mac上按键符号 ⌥ : option / alt ⇧ : shift ⌃ ...
- 安卓Design包之CollapsingToolbarLayout(可折叠的工具栏布局)的简单使用
转自: CollapsingToolbarLayout的使用 注意:使用前需要添加Design依赖包,使用toolbar时需要隐藏标题头 CollapsingToolbarLayout作用是提供了一个 ...
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position xxx ordinal
python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't deco ...
- VMware系统运维(十)部署虚拟化桌面 Horizon View 5.2 Connection Server安装
部署桌面虚拟化,首先得安装连接服务器,下面我们开始安装Connection Server. 1.下载并安装以下软件,提示:只能在Win2008R2上安装,Win2012R2无法安装. 2.双击打开程序 ...
- 插件介绍 :cropper是一款使用简单且功能强大的图片剪裁jQuery插件。
简要教程 cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持鼠标滚轮操作,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. c ...