国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

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

Free DIY Tour

2019-11-11 02:26:36
字體:
來源:轉載
供稿:網友

PRoblem Description

Weiwei is a software engineer of ShiningSoft. He has just Excellently fulfilled a software project with his fellow workers. His boss is so satisfied with their job that he decide to provide them a free tour around the world. It’s a good chance to relax themselves. To most of them, it’s the first time to go abroad so they decide to make a collective tour.

The tour company shows them a new kind of tour circuit - DIY circuit. Each circuit contains some cities which can be selected by tourists themselves. According to the company’s statistic, each city has its own interesting point. For instance, Paris has its interesting point of 90, New York has its interesting point of 70, ect. Not any two cities in the world have straight flight so the tour company provide a map to tell its tourists whether they can got a straight flight between any two cities on the map. In order to fly back, the company has made it impossible to make a circle-flight on the half way, using the cities on the map. That is, they marked each city on the map with one number, a city with higher number has no straight flight to a city with lower number.

Note: Weiwei always starts from Hangzhou(in this problem, we assume Hangzhou is always the first city and also the last city, so we mark Hangzhou both 1 and N+1), and its interesting point is always 0.

Now as the leader of the team, Weiwei wants to make a tour as interesting as possible. If you were Weiwei, how did you DIY it? Input The input will contain several cases. The first line is an integer T which suggests the number of cases. Then T cases follows. Each case will begin with an integer N(2 ≤ N ≤ 100) which is the number of cities on the map. Then N integers follows, representing the interesting point list of the cities. And then it is an integer M followed by M pairs of integers [Ai, Bi] (1 ≤ i ≤ M). Each pair of [Ai, Bi] indicates that a straight flight is available from City Ai to City Bi. Output For each case, your task is to output the maximal summation of interesting points Weiwei and his fellow workers can get through optimal DIYing and the optimal circuit. The format is as the sample. You may assume that there is only one optimal circuit.

Output a blank line between two cases.

這道題蠻尷尬的,開始我記錄的路徑是從前往后的不是很好,會出現某種情況的死循環。 我到現在還沒找出來問題,只能從后往前了。 代碼如下

#include <iostream>#include <vector>using namespace std;int main(){ int test_case; cin>>test_case; int count_case=test_case; while(test_case--){ int city_num; cin>>city_num; vector<int>city_points(city_num+5,0); for(int i=0;i<city_num;++i) cin>>city_points[i+1]; vector<int>point_sum(city_points); vector<int>road(city_num+5,1); int roads; cin>>roads; for(int i=0;i<roads;++i){ int start_city,end_city; cin>>start_city>>end_city; if( point_sum[start_city] + city_points[end_city] > point_sum[end_city]){ point_sum[end_city] = point_sum[start_city] + city_points[end_city]; road [end_city]=start_city; } } int start = city_num+1; vector<int>answer; while(start!=1){ answer.push_back(road[start]); start=road[start]; } cout<<"CASE "<<count_case-test_case<<'#'<<endl; cout<<"points : "<<point_sum[city_num+1]<<endl; cout<<"circuit : "; for(auto it = answer.rbegin();it!=answer.rend();it++) cout<<*it<<"->"; cout<<'1'<<endl; if(test_case!=0) cout<<endl; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永年县| 临漳县| 北京市| 车致| 阜平县| 平谷区| 宁化县| 福海县| 安阳市| 定安县| 涞源县| 邯郸县| 邵东县| 静宁县| 合阳县| 墨江| 南陵县| 舒兰市| 定西市| 安丘市| 阳城县| 浦县| 佛坪县| 荥经县| 林甸县| 珠海市| 剑川县| 英德市| 东乌珠穆沁旗| 若羌县| 油尖旺区| 铁力市| 民丰县| 阿拉尔市| 乐至县| 永年县| 阿图什市| 颍上县| 长宁县| 德钦县| 西畴县|