PAT 1087 All Roads Lead to Rome (30 分)

1087 All Roads Lead to Rome (30 分)

Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.


Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers N (2≤N≤200), the number of cities, and K, the total number of routes between pairs of cities; followed by the name of the starting city. The next N−1 lines each gives the name of a city and an integer that represents the happiness one can gain from that city, except the starting city. Then K lines follow, each describes a route between two cities in the format City1 City2 Cost. Here the name of a city is a string of 3 capital English letters, and the destination is always ROM which represents Rome.


Output Specification:
For each test case, we are supposed to find the route with the least cost. If such a route is not unique, the one with the maximum happiness will be recommanded. If such a route is still not unique, then we output the one with the maximum average happiness – it is guaranteed by the judge that such a solution exists and is unique.

Hence in the first line of output, you must print 4 numbers: the number of different routes with the least cost, the cost, the happiness, and the average happiness (take the integer part only) of the recommanded route. Then in the next line, you are supposed to print the route in the format City1->City2->…->ROM.

Sample Input:

6 7 HZH
ROM 100
PKN 40
GDN 55
PRS 95
BLN 80
ROM GDN 1
BLN ROM 1
HZH PKN 1
PRS ROM 2
BLN HZH 2
PKN GDN 1
HZH PRS 1

Sample Output:

3 3 195 97
HZH->PRS->ROM




解析

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int INF = 0x3fffffff;
unordered_map<string, int> Name2index;
unordered_map<int, string> index2Name;
struct Node {
	int v, cost;
	Node() = default;
	Node(int _v,int _cost):v(_v),cost(_cost){}
};
vector<vector<Node>> G;
vector<int> Happy;
vector<vector<int>> pre;
void dijkstra(int s,vector<int> & d) {
	vector<bool> vis(G.size(), false);
	pre.resize(G.size());
	d.resize(G.size(), INF);
	d[s] = 0;
	for (int i = 0; i < G.size(); i++) {
		int u = -1, min = INF;
		for (int j = 0; j < G.size(); j++) {
			if (vis[j] == false && min > d[j]) {
				min = d[j];
				u = j;
			}
		}
		vis[u] = true;
		for (auto x : G[u]) {
			int v = x.v;
			if (vis[v] == false) {
				if (d[v] > d[u] + x.cost) {
					pre[v].clear();
					pre[v].push_back(u);
					d[v] = d[u] + x.cost;
				}
				else if (d[v] == d[u] + x.cost) {
					pre[v].push_back(u);
				}
			}
		}
	}
}
int num = 0;  //最短;路径条数
int opthappy=-1, avghappy=-1;
vector<int> temppath, path;
void DFS(int s, int v) {
	if (s == v) {
		temppath.push_back(v);
		num++;
		int H = 0;
		for (int i = temppath.size() - 1; i >= 0; i--) 
			H += Happy[temppath[i]];
		if (opthappy < H) {
			opthappy = H;
			avghappy = H / (temppath.size() - 1);
			path = temppath;
		}
		else if (opthappy == H) {
			H /= temppath.size() - 1;
			if (H > avghappy) {
				avghappy = H;
				path = temppath;
			}
		}
		temppath.pop_back();
	}
	temppath.push_back(v);
	for (auto x : pre[v])
		DFS(s, x);
	temppath.pop_back();
}
int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	string start;
	cin >> start;
	Name2index[start] = 0;
	index2Name[0] = start;
	Happy.resize(N, 0);
	G.resize(N);
	string city;
	int happy_value;
	for (int i = 1; i < N; i++) {
		cin >> city >> happy_value;
		Name2index[city] = i;
		index2Name[i] = city;
		Happy[i] = happy_value;
	}
	string city1, city2;
	int cost;
	for (int i = 0; i < K; i++) {
		cin >> city1 >> city2 >> cost;
		G[Name2index[city1]].push_back(Node(Name2index[city2], cost));
		G[Name2index[city2]].push_back(Node(Name2index[city1], cost));
	}
	vector<int> d;
	dijkstra(0,d);
	DFS(0, Name2index[string("ROM")]);
	printf("%d %d %d %d\n", num, d[Name2index[string("ROM")]], opthappy, avghappy);
	for (int i = path.size()-1; i >=0; i--) {
		printf("%s", index2Name[path[i]].c_str());
		if (i == 0)    printf("\n");
		else	printf("->");
	}
}
### 回答1: 这两个处理器都是目前市面上比较常见的高性能处理器。其中,锐龙 R7 5800H 是 AMD 公司推出的一款移动处理器,而 i5-11300H 则是 Intel 公司推出的一款移动处理器。 从处理器性能的角度来看,锐龙 R7 5800H 在多线程性能方面表现出色,可以更好地处理多任务并行,而 i5-11300H 则在单线程性能方面表现较强,适合单个任务的处理。 此外,锐龙 R7 5800H 的功耗较高,可能导致发热电池寿命的问题,而 i5-11300H 的功耗相对较低,能够更好地保持电池续航时间稳定性。 因此,如果您需要处理多任务并行,可以考虑锐龙 R7 5800H;如果您更注重单个任务的性能,可以考虑 i5-11300H。当然,您还可以根据自己的具体需求使用场景进行选择。 ### 回答2: 锐龙R7-5800Hi5-11300H都是当今市场上非常受欢迎的高性能CPU,它们都能满足多数用户的需求。但是,它们在性能特点上还是存在很的差异。 首先,锐龙R7-5800H是一款采用7nm FinFET制程的八核心十六线程处理器,其主频为3.2GHz,最高主频可达4.4GHz。它还内置了AMD的集成显卡Vega 8,最高核心频率为2.1GHz。相比之下,i5-11300H是基于10nm SuperFin制程的四核八线程处理器,主频为3.1GHz,最高主频可达4.4GHz,但它不带集成显卡。 在性能方面,锐龙R7-5800H表现优异,特别是针对多线程任务。它的性能比i5-11300H优越,尤其是在处理多线程任务时。在游戏方面,R7-5800H的性能也要稍高于i5-11300H。但是,i5-11300H的单线程性能却要比R7-5800H更好,因此在执行单线程任务时,i5-11300H更具有优势。 在功耗方面,i5-11300H的TDP只有35W,相比之下,锐龙R7-5800H的TDP则高达45W。因此,从功耗的角度来看,i5-11300H更省电,适合用于移动设备,而R7-5800H则更适合台式机或型游戏本。 最后,价格也是两者之间一个重要的因素。一般来说,i5-11300H的价格比R7-5800H要低得多,但是,当需要高性能处理器时,R7-5800H也是一个更好的选择。 综上所述,锐龙R7-5800Hi5-11300H都有自己的特点优势,具体应该根据用户的需求来选择。如果用户需要高性能处理器用于多线程任务或者游戏,那么R7-5800H是更好的选择。如果用户注重功耗轻便性,则应选择i5-11300H。 ### 回答3: 锐龙r7-5800h是AMD推出的一款处理器,而i5-11300h是Intel推出的一款处理器。这两款处理器都是针对笔记本电脑开发的。 首先来看锐龙r7-5800h。该处理器是基于7nm工艺制造的,具备8个物理核心16个线程,主频为3.2GHz,最增强频率为4.4GHz。该处理器采用AMD的Zen 3架构,拥有32MB的L3缓存4MB的L2缓存。它还配备了Radeon Vega 8集成显卡,支持DDR4-3200MHz内存。总体来说,锐龙r7-5800h性能强劲,适合运行型应用程序游戏。 然后是i5-11300h。该处理器也是基于10nm工艺制造的,具备4个物理核心8个线程,主频为3.1GHz,最增强频率为4.4GHz。它采用了Intel的Tiger Lake架构,拥有12MB的L3缓存,但没有L2缓存。它配备了Intel Xe集成显卡,支持DDR4-3200MHz内存。总体来说,i5-11300h性能比较强,可以应对日常使用需求。 从性能方面来看,锐龙r7-5800h比i5-11300h更加强。它有更多的核心线程,更的缓存更好的集成显卡。但考虑到业务场景的不同,i5-11300h已经足够满足多数人的日常需要。 总体来说,无论选择哪款处理器,都要考虑自己的使用需求笔记本电脑的其他配置,以获得更好的使用体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值