亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

PAT甲級1072

2019-11-11 04:54:58
字體:
來源:轉載
供稿:網友

1072. Gas Station (30)

時間限制200 ms內存限制65536 kB代碼長度限制16000 B判題程序Standard作者CHEN, Yue

A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.

Now given the map of the city and several candidate locations for the gas station, you are supposed to give the best recommendation. If there are more than one solution, output the one with the smallest average distance to all the houses. If such a solution is still not unique, output the one with the smallest index number.

Input Specification:

Each input file contains one test case. For each case, the first line contains 4 positive integers: N (<= 103), the total number of houses; M (<= 10), the total number of the candidate locations for the gas stations; K (<= 104), the number of roads connecting the houses and the gas stations; and DS, the maximum service range of the gas station. It is hence assumed that all the houses are numbered from 1 to N, and all the candidate locations are numbered from G1 to GM.

Then K lines follow, each describes a road in the formatP1 P2 Distwhere P1 and P2 are the two ends of a road which can be either house numbers or gas station numbers, and Dist is the integer length of the road.

Output Specification:

For each test case, PRint in the first line the index number of the best location. In the next line, print the minimum and the average distances between the solution and all the houses. The numbers in a line must be separated by a space and be accurate up to 1 decimal place. If the solution does not exist, simply output “No Solution”.

Sample Input 1:
4 3 11 51 2 21 4 21 G1 41 G2 32 3 22 G2 13 4 23 G3 24 G1 3G2 G1 1G3 G2 2Sample Output 1:
G12.0 3.3Sample Input 2:
2 1 2 101 G1 92 G1 20Sample Output 2:
No Solution
#include<cstdio>#include<iostream>#include<vector>#include<map>#include<string>#include<algorithm>#include<queue>using namespace std;struct Node{	int v, dis;}node;struct compare{	bool Operator()(Node n1, Node n2)	{		return n1.dis > n2.dis;	}};struct Result{	string solution;	double mindistance, averagedistance;	bool operator<(Result r)	{		if (mindistance != r.mindistance)			return mindistance > r.mindistance;//最大的最近距離,注意理解題意		else if (averagedistance != r.averagedistance)			return averagedistance < r.averagedistance;		else			return solution < r.solution;	}}result;int N, M, K, Ds;const int maxn = 1020;//這里注意maxn必須是1011以上const int INF = 1000000000;map<string, int> gas2num;map<int,string> num2gas;vector<Node> Adj[maxn];bool vis[maxn];int d[maxn];vector<Result> solutions;void Dijkstra(int s){	fill(vis, vis + maxn, false);	fill(d, d + maxn, INF);	d[s] = 0;	priority_queue<Node, vector<Node>, compare>Q;	node.v = s; node.dis = 0;	Q.push(node);	int u;	for (int i = 1; i <= N + M; i++)	{		if (!Q.empty())		{			u = Q.top().v;			vis[u] = true;			Q.pop();		}		for (int j = 0; j < Adj[u].size(); j++)		{			int v = Adj[u][j].v;			int dis = Adj[u][j].dis;			if (!vis[v]&&d[u]+dis<d[v])			{				d[v] = d[u] + dis;				node.v = v; node.dis = d[v];				Q.push(node);			}		}	}	double sum = 0.0;	result.mindistance = INF;	for (int i = 1; i <= N; i++)	{		if (d[i] > Ds)return;		else sum += d[i];		if (result.mindistance > d[i])		{			result.mindistance = d[i];		}	}	result.solution = num2gas[s];	result.averagedistance = sum / N;	solutions.push_back(result);}int main(){	scanf("%d%d%d%d", &N, &M, &K, &Ds);	string s1, s2; int distance;	int n = N;	for (int i = 0; i < K; i++)	{		cin >> s1 >> s2>>distance;		int v1, v2;		if (s1[0] != 'G')		{			//v1 = s1[0] - '0';這個地方注意若輸入的是10以上的數就不行			v1 = stoi(s1);		}		else		{			if (gas2num.find(s1) == gas2num.end())			{				v1 = gas2num[s1] = ++n;				num2gas[n] = s1;			}			else				v1 = gas2num[s1];		}		if (s2[0] != 'G')		{			//v2 = s2[0] - '0';			v2 = stoi(s2);		}		else		{			if (gas2num.find(s2) == gas2num.end())			{				v2 = gas2num[s2] = ++n;				num2gas[n] = s2;			}			else				v2 = gas2num[s2];		}		node.v = v2; node.dis = distance;		Adj[v1].push_back(node); node.v = v1;		Adj[v2].push_back(node);	}	for (int i = N + 1; i <= N + M; i++)	{		Dijkstra(i);	}	if (solutions.size())	{		sort(solutions.begin(), solutions.end());		cout << solutions[0].solution << endl;		printf("%.1f %.1f/n", solutions[0].mindistance, solutions[0].averagedistance);	}	else		printf("No Solution/n");	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日韩精品极品视频免费观看| 中文字幕自拍vr一区二区三区| 日韩av高清不卡| 日韩av手机在线观看| 欧美日韩在线看| 欧美色另类天堂2015| 久久精品99久久久香蕉| 欧美性xxxx极品hd欧美风情| 精品五月天久久| 国产精品白丝av嫩草影院| 国产ts人妖一区二区三区| 亚洲欧洲美洲在线综合| 日韩国产在线看| 亚洲精品网址在线观看| 中文字幕欧美在线| 久久精品国产精品亚洲| 九九久久久久久久久激情| 久久精品免费电影| 欧美日韩爱爱视频| 国产精品狠色婷| 成人综合网网址| 91国在线精品国内播放| 欧美日韩黄色大片| 国产一区二区三区在线播放免费观看| 国产精品免费福利| 久久久久久久香蕉网| 午夜欧美不卡精品aaaaa| 日韩av在线电影网| 欧美午夜精品久久久久久浪潮| 亚洲国产小视频| 欧美国产日韩一区二区三区| 日韩欧美在线观看视频| 亚洲国产精品va在看黑人| 中文字幕无线精品亚洲乱码一区| 久久精品91久久香蕉加勒比| 欧美人与物videos| 亚洲人线精品午夜| 色综合久久天天综线观看| 国产精品日日做人人爱| 久久777国产线看观看精品| 日韩精品在线视频| 欧美国产日本高清在线| 精品香蕉一区二区三区| 色与欲影视天天看综合网| 欧美日韩成人网| 国产欧美婷婷中文| 日韩美女视频在线观看| 亚洲欧美国产日韩中文字幕| 亚洲国产精品成人一区二区| 国内精品免费午夜毛片| 国产精品国产三级国产aⅴ浪潮| 国产成人一区二区三区电影| 久久天堂av综合合色| 国产91精品不卡视频| 国产福利成人在线| 亚洲国产精品一区二区三区| 亚洲高清久久久久久| 久久天天躁狠狠躁夜夜爽蜜月| 欧美电影免费观看高清完整| 久久久久久久久综合| 国产不卡av在线| 在线观看国产成人av片| 日韩av电影在线免费播放| 中文字幕一精品亚洲无线一区| 日产精品99久久久久久| 91国产精品视频在线| 成人午夜一级二级三级| 午夜欧美大片免费观看| 日韩乱码在线视频| 亚洲经典中文字幕| 欧美裸体xxxx极品少妇软件| 国产视频精品久久久| 91精品国产网站| 久久久精品免费| 国产精品美女久久久久av超清| 欧美人交a欧美精品| 国产精品美女久久久久久免费| 日韩av在线导航| 一区三区二区视频| 亚洲aⅴ日韩av电影在线观看| 欧美性猛交xxxx乱大交3| 久久精品电影一区二区| 97久久精品国产| 日韩在线播放一区| 欧美日韩亚洲精品一区二区三区| 91精品国产乱码久久久久久久久| 国产日韩欧美日韩| 国产精品福利无圣光在线一区| 成人免费直播live| 成人日韩av在线| 欧美尤物巨大精品爽| 亚洲的天堂在线中文字幕| 一区二区三区天堂av| 国产精品一区二区久久国产| 精品国产一区二区三区久久久狼| 亚洲最大成人网色| 日本免费在线精品| 懂色av一区二区三区| 日韩中文娱乐网| 亚洲色无码播放| 欧美激情精品久久久久久| 久久久久久成人| 日韩经典中文字幕在线观看| 亚洲欧洲日产国码av系列天堂| 欧美激情中文字幕在线| 亚洲精品乱码久久久久久按摩观| 久久影院资源站| 亚洲欧美一区二区三区情侣bbw| 国产综合视频在线观看| 成人免费高清完整版在线观看| 亚洲美女动态图120秒| 国产中文字幕日韩| 国产女精品视频网站免费| 亚洲成色777777在线观看影院| 日韩精品中文字幕有码专区| 国产精品福利网站| 国产精品18久久久久久麻辣| 日韩电影第一页| 国内精品免费午夜毛片| 精品一区二区三区四区| 国产91色在线|| 中文字幕在线看视频国产欧美| 日韩久久免费视频| 777午夜精品福利在线观看| 少妇精69xxtheporn| 亚洲激情成人网| 久久久999国产精品| 久久69精品久久久久久久电影好| 亚洲欧美国产一区二区三区| 日韩成人网免费视频| 国产精品久久av| 国产成人精品视频在线观看| 亚洲一区中文字幕| 欧美极品在线视频| 精品色蜜蜜精品视频在线观看| 亚洲人成在线观看| 色香阁99久久精品久久久| 91精品综合视频| 97香蕉超级碰碰久久免费的优势| 欧美日韩国产精品一区二区三区四区| 日本精品免费观看| 国产一区二区三区在线看| 亚洲精品一区中文字幕乱码| 亚洲欧洲日产国码av系列天堂| 日韩在线视频网| 青青草原一区二区| 国产一区二区三区在线看| 国产精品久久久久久婷婷天堂| 欧美日韩美女在线| 欧美资源在线观看| …久久精品99久久香蕉国产| 亚洲福利视频二区| 亚洲精品在线观看www| 欧美亚洲一级片| 国产香蕉97碰碰久久人人| 亚洲无限乱码一二三四麻| 日韩中文视频免费在线观看| 欧美精品做受xxx性少妇| 日韩激情av在线播放| 亚洲一区二区三区在线视频| 日韩成人xxxx| 亚洲有声小说3d| 国产成人综合久久| 中文字幕综合一区|