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

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

PAT甲級1072

2019-11-11 04:14:06
字體:
來源:轉載
供稿:網友

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
成人黄色av网站| 97色在线视频观看| 中文字幕在线看视频国产欧美在线看完整| 欧美日韩中文在线观看| 欧美成人精品一区| 欧美性猛交丰臀xxxxx网站| 国产91色在线播放| 亚洲精品久久7777777| 日韩成人av在线| 欧美人与性动交a欧美精品| 亚洲视频网站在线观看| 中文字幕日韩欧美在线| 不卡av在线播放| 欧美一区二区视频97| 国产精品久久久久99| 欧美中文在线字幕| 欧美日韩激情小视频| 久久久影视精品| 中文字幕在线成人| 国产精品极品美女在线观看免费| 亚洲网在线观看| 国产一区二区三区18| 国产精品男人爽免费视频1| 午夜精品一区二区三区在线视频| 亚洲性xxxx| 日韩精品中文字幕在线| 97久久国产精品| 久久久亚洲国产天美传媒修理工| 日韩电影免费观看中文字幕| 欧美一区二区.| 这里只有精品在线播放| 久久精品国产91精品亚洲| 久久久久久com| 91精品国产网站| 国产69精品99久久久久久宅男| 国产精品对白刺激| 欧美激情喷水视频| 国产一区二区三区四区福利| 欧美性xxxx18| 中文字幕无线精品亚洲乱码一区| 国产一区二区三区日韩欧美| 亚洲美女免费精品视频在线观看| 日韩av在线网址| 欧美黑人视频一区| 欧美国产日韩在线| 91麻豆国产语对白在线观看| 成人乱人伦精品视频在线观看| 国产精国产精品| 国产一区二区在线播放| 精品无码久久久久久国产| 青青精品视频播放| 精品久久久久久久大神国产| 国产婷婷色综合av蜜臀av| 51久久精品夜色国产麻豆| 国产精品一区二区3区| 亚洲精品久久久久久久久久久久久| 欧美精品一区二区免费| 激情懂色av一区av二区av| 深夜成人在线观看| 国产精品美乳在线观看| 精品国产老师黑色丝袜高跟鞋| 日韩免费观看在线观看| 91精品中国老女人| 精品国产福利视频| 欧美激情中文网| 日韩电影中文字幕av| 精品日本高清在线播放| 91tv亚洲精品香蕉国产一区7ujn| 欧美午夜宅男影院在线观看| 91理论片午午论夜理片久久| 欧日韩在线观看| 成人免费视频在线观看超级碰| 97成人在线视频| 国产欧美精品日韩| 91精品一区二区| 国产成人午夜视频网址| 热久久免费国产视频| 亚洲男人的天堂在线| 欧美日韩国产黄| 日韩av电影中文字幕| 亚洲综合自拍一区| 91欧美精品午夜性色福利在线| 亚洲男人第一av网站| 欧美性猛交xxxx免费看久久久| 成人激情免费在线| 欧美日韩性视频在线| 庆余年2免费日韩剧观看大牛| 亚洲国产精品成人av| 国产精品久久久久久久久影视| 7m第一福利500精品视频| 欧美性猛交xxxx黑人| 亚洲人高潮女人毛茸茸| 欧美尺度大的性做爰视频| 深夜福利91大全| 在线电影中文日韩| 欧美激情在线狂野欧美精品| 色播久久人人爽人人爽人人片视av| 国产一区二区三区高清在线观看| 国产精品成熟老女人| 亚洲iv一区二区三区| 久久国产精品久久久久久| 一本大道久久加勒比香蕉| 亚洲影院污污.| 69av在线视频| 久久中文字幕国产| 欧美亚洲在线视频| 91久久在线观看| 国产精品亚洲片夜色在线| 黑人狂躁日本妞一区二区三区| 亚洲欧美国产精品久久久久久久| 亚洲精品免费网站| 亚洲激情视频网| 久久亚洲国产精品成人av秋霞| 美女av一区二区| 亚洲欧美另类在线观看| 色yeye香蕉凹凸一区二区av| 欧美大片在线看免费观看| 久久成人人人人精品欧| 欧美电影院免费观看| 在线观看国产精品日韩av| 国产精品一久久香蕉国产线看观看| 欧美性资源免费| 成人日韩av在线| 亚洲电影免费观看高清完整版在线观看| 国产经典一区二区| 精品一区二区三区四区在线| 色悠悠久久久久| 欧美日韩免费网站| www日韩中文字幕在线看| 中文字幕亚洲一区| 久久国产色av| 狠狠躁18三区二区一区| 亚洲曰本av电影| 91久久久久久久一区二区| 亚洲高清一区二| 海角国产乱辈乱精品视频| 在线看日韩欧美| 精品在线欧美视频| 最近中文字幕mv在线一区二区三区四区| 精品二区三区线观看| 国产精品高清在线观看| 亚洲男子天堂网| 久久午夜a级毛片| 日韩在线观看免费高清| 亚洲黄色免费三级| 欧美大片在线看免费观看| 亚洲欧美制服综合另类| 亚洲综合国产精品| 欧美性猛交xxxx乱大交极品| 精品国内亚洲在观看18黄| 欧美美最猛性xxxxxx| 亚洲a级在线观看| 2019亚洲日韩新视频| 国产做受69高潮| 久久久免费精品视频| 91国内精品久久| 亚洲乱码国产乱码精品精天堂| 日韩在线资源网| 国产精品一区二区三区成人| 2019国产精品自在线拍国产不卡| 韩国精品久久久999| 92国产精品久久久久首页| 最近更新的2019中文字幕| www国产亚洲精品久久网站|