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

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

PAT甲級1072

2019-11-11 05:42:22
字體:
來源:轉載
供稿:網友

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;}
上一篇:網絡基礎

下一篇:C#之MySql更新

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日韩精品在线免费| 97在线免费观看| 欧美xxxx做受欧美.88| 精品爽片免费看久久| 亚洲精品一区二区三区不| 久久中国妇女中文字幕| 国产91热爆ts人妖在线| 国产精品99久久久久久白浆小说| 欧美日韩成人精品| 在线看片第一页欧美| 色青青草原桃花久久综合| y97精品国产97久久久久久| 欧美怡红院视频一区二区三区| 日韩女优在线播放| 中文字幕视频在线免费欧美日韩综合在线看| 亚洲女人初尝黑人巨大| 亚洲精品成人久久电影| 国产xxx69麻豆国语对白| 亚洲电影av在线| 日本道色综合久久影院| 久久av红桃一区二区小说| 欧美高清自拍一区| 久久伊人色综合| 成人精品久久久| 91av在线视频观看| 国产精品欧美激情| 亚洲精品www久久久久久广东| 欧美成人精品xxx| 久久天天躁狠狠躁夜夜av| 91精品国产91久久久久| 亚洲第一区中文99精品| 欧美激情一区二区三区成人| 欧美在线视频播放| 日韩一级裸体免费视频| 久久精品视频导航| 在线观看欧美日韩国产| 欧美多人爱爱视频网站| 国产精品大陆在线观看| 欧美裸体xxxx极品少妇软件| 精品亚洲一区二区三区四区五区| 日本不卡视频在线播放| 国内精品美女av在线播放| 91在线国产电影| 久久久免费高清电视剧观看| 亚洲最新视频在线| 国产91在线播放九色快色| 亚洲成人动漫在线播放| 日韩精品免费电影| 日韩免费观看av| 亚洲欧美精品一区二区| 成人免费福利在线| 国产精品88a∨| 亚洲天堂av网| 欧美日韩国产精品一区二区三区四区| 欧美日韩一区二区精品| 国产亚洲欧美日韩精品| 久久久久久久香蕉网| 中文字幕不卡av| 午夜免费在线观看精品视频| 亚洲第一天堂av| 久久久免费观看视频| 国内精品久久久久久久久| 中文字幕欧美国内| 欧美主播福利视频| 亚洲国产精品人人爽夜夜爽| 大荫蒂欧美视频另类xxxx| 日韩最新中文字幕电影免费看| 91视频国产高清| 精品视频在线播放色网色视频| 亚洲精品免费在线视频| 97在线视频观看| 91日韩在线播放| 黄色成人在线播放| 欧美激情乱人伦| 亚洲美女免费精品视频在线观看| 亚洲一区二区三区四区在线播放| 国产精品老女人精品视频| 九九久久久久99精品| 久久免费高清视频| 亚洲男人av在线| 97av在线视频| 国产第一区电影| 色婷婷**av毛片一区| 欧美精品一区二区免费| 国产精品国产亚洲伊人久久| 欧美日韩免费区域视频在线观看| 亚洲最大的av网站| 91天堂在线观看| 久久久精品视频成人| 97香蕉久久夜色精品国产| 亚洲免费电影一区| 日韩性xxxx爱| 亚洲综合自拍一区| 日韩国产欧美区| 久久久人成影片一区二区三区观看| www.xxxx欧美| 亚洲成人a级网| 欧美专区日韩视频| 精品精品国产国产自在线| xxxx欧美18另类的高清| 亚洲精品aⅴ中文字幕乱码| 日韩在线观看免费| 亚洲天堂成人在线| 精品久久久久久国产| 午夜精品一区二区三区在线| 欧美中文字幕在线观看| 中文字幕在线看视频国产欧美| 国产精品午夜视频| 亚洲a级在线播放观看| 97超碰国产精品女人人人爽| 狠狠干狠狠久久| 国内外成人免费激情在线视频| 91精品国产91久久久久久久久| 国产精品亚洲欧美导航| 日韩电影免费在线观看中文字幕| 久久91精品国产91久久跳| 日韩欧美黄色动漫| 亚洲自拍高清视频网站| 欧美日韩亚洲一区二| 庆余年2免费日韩剧观看大牛| 性日韩欧美在线视频| 欧美色道久久88综合亚洲精品| 精品久久中文字幕| 欧美成年人在线观看| 久久精品一本久久99精品| 精品亚洲va在线va天堂资源站| 欧美亚洲另类制服自拍| 欧美性xxxxx| 国产精品久久久久久中文字| 国产精品一区专区欧美日韩| 午夜精品久久久久久久99黑人| 日韩精品中文字幕在线观看| 亚洲欧美一区二区三区情侣bbw| 欧美乱大交做爰xxxⅹ性3| 97视频com| 九九热视频这里只有精品| 日韩激情片免费| 国产日韩精品一区二区| 美女久久久久久久久久久| 国产一区二区丝袜高跟鞋图片| 成人激情在线观看| 亚洲欧美成人网| 欧美精品久久久久久久久| 欧美色视频日本高清在线观看| 国产午夜精品全部视频播放| 国产精品视频久| 久久这里只有精品视频首页| 欧美一级淫片aaaaaaa视频| 国产成+人+综合+亚洲欧美丁香花| 亚洲美女av在线| 亚洲网在线观看| 亚洲人成欧美中文字幕| 一区二区三区美女xx视频| 日韩精品电影网| 成人国产精品日本在线| 国产精品日韩在线一区| 日产精品99久久久久久| 91精品免费看| 丝袜美腿精品国产二区| 国产日韩欧美日韩| 日韩欧美aⅴ综合网站发布| 久久国产精品久久国产精品| 欧美高清视频免费观看| 亚洲午夜av电影|