青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

USACO 4.1 Fence Loops


???? 這題是求無向圖中的一個最小環的長度。
???? 主要思路是:因為邊都是直線,邊的兩點之間的最短距離必然是這個邊長。那么,再求一條到兩頂點的最短距徑,這個路徑與邊構成了一個環。這個環是包含該邊的最小環。枚舉一下所有邊,計算出最小環即可。對于每個邊,刪除該邊,然后計算兩頂點的最短路徑,再恢復該邊。
???? 但是這個圖的輸入是用邊表示的,一個難點就是將其轉換成用點表示。這里用邊的集合來表示一個點。然后用map<set<int>,int>來存儲某一邊對應的邊的編號。每找到一個新的頂點則分配一個新的編號。這部分主要通過函數get_vertex(set<int>&s)來實現。

代碼如下:
#include?<iostream>
#include?
<fstream>
#include?
<set>
#include?
<map>
#include?
<climits>
#include?
<cstring>

using?namespace?std;

ifstream?fin(
"fence6.in");
ofstream?fout(
"fence6.out");

#ifdef?_DEBUG
#define?out?cout
#define?in?cin
#else
#define?out?fout
#define?in?fin
#endif

struct?Edge{
????
int?va,vb,len;
};

int?edge_num;
int?vertex_num;
int?graph[100][100];
Edge?edges[
100];

int?get_vertex(set<int>&s)
{
????
static?map<set<int>,int>vertex;

????
if(?vertex.find(s)?==?vertex.end()?){
????????vertex[s]?
=?vertex_num;
????????
return?vertex_num++;
????}
else{
????????
return?vertex[s];
????}
}

void?build_graph()
{
????
in>>edge_num;

????
for(int?i=0;i<100;++i)
????????
for(int?j=0;j<100;++j)
????????????graph[i][j]?
=?INT_MAX/2;

????
for(int?i=0;i<edge_num;++i){
????????
int?edge,tmp,len;
????????
int?left_num,right_num;
????????
set<int>?s;
????????
in>>edge>>len>>left_num>>right_num;
????????s.insert(edge);
????????
for(int?j=0;j<left_num;++j){
????????????
in>>tmp;
????????????s.insert(tmp);
????????}
????????
int?left_vertex?=?get_vertex(s);
????????s.clear();
????????s.insert(edge);
????????
for(int?j=0;j<right_num;++j){
????????????
in>>tmp;
????????????s.insert(tmp);
????????}
????????
int?right_vertex?=?get_vertex(s);
????????graph[left_vertex][right_vertex]?
=?
????????????graph[right_vertex][left_vertex]?
=?len;
????????edges[i].va?
=?left_vertex;
????????edges[i].vb?
=?right_vertex;
????????edges[i].len?
=?len;
????}
}

int?shortest_path(int?va,int?vb)
{
????
int?shortest[100];
????
bool?visited[100];

????memset(visited,
0,sizeof(visited));
???
????
for(int?i=0;i<vertex_num;++i){
????????shortest[i]?
=?graph[va][i];
????}

????visited[va]?
=?true;

????
while(true){
????????
int?m?=?-1;
????????
for(int?i=0;i<vertex_num;++i){
??????????????
if(!visited[i]){
????????????????
if(m==-1||shortest[i]<shortest[m])
????????????????????m?
=?i;
??????????????}
????????}
????????
//沒有新加結點了
????????
????????visited[m]?
=?true;

????????
if(?m==vb?)
????????????
return?shortest[vb];

????????
for(int?i=0;i<vertex_num;++i){
????????????
if(!visited[i])
????????????shortest[i]?
=?min(shortest[i],shortest[m]+graph[m][i]);
????????}
????}
}

void?solve()
{
????build_graph();

????
int?best?=?INT_MAX;

????
for(int?i=0;i<edge_num;++i){
??????graph[edges[i].va][edges[i].vb]?
=?graph[edges[i].vb][edges[i].va]?=?INT_MAX/2;?
??????best?
=?min(best,edges[i].len+shortest_path(edges[i].va,edges[i].vb)?);
??????graph[edges[i].va][edges[i].vb]?
=?graph[edges[i].vb][edges[i].va]?=?edges[i].len;?
????}

????
out<<best<<endl;
}

int?main(int?argc,char?*argv[])
{
????solve();?
????
return?0;
}


Fence Loops

The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only at their endpoints though sometimes more than two fences join together at a given endpoint. The result is a web of fences enclosing his pastures. Farmer Brown wants to start to straighten things out. In particular, he wants to know which of the pastures has the smallest perimeter.

Farmer Brown has numbered his fence segments from 1 to N (N = the total number of segments). He knows the following about each fence segment:

  • the length of the segment
  • the segments which connect to it at one end
  • the segments which connect to it at the other end.
Happily, no fence connects to itself.

Given a list of fence segments that represents a set of surrounded pastures, write a program to compute the smallest perimeter of any pasture. As an example, consider a pasture arrangement, with fences numbered 1 to 10 that looks like this one (the numbers are fence ID numbers):

           1
+---------------+
|\ /|
2| \7 / |
| \ / |
+---+ / |6
| 8 \ /10 |
3| \9 / |
| \ / |
+-------+-------+
4 5

The pasture with the smallest perimeter is the one that is enclosed by fence segments 2, 7, and 8.

PROGRAM NAME: fence6

INPUT FORMAT

Line 1: N (1 <= N <= 100)
Line 2..3*N+1:

N sets of three line records:

  • The first line of each record contains four integers: s, the segment number (1 <= s <= N); Ls, the length of the segment (1 <= Ls <= 255); N1s (1 <= N1s <= 8) the number of items on the subsequent line; and N2sthe number of items on the line after that (1 <= N2s <= 8).
  • The second line of the record contains N1 integers, each representing a connected line segment on one end of the fence.
  • The third line of the record contains N2 integers, each representing a connected line segment on the other end of the fence.

SAMPLE INPUT (file fence6.in)

10
1 16 2 2
2 7
10 6
2 3 2 2
1 7
8 3
3 3 2 1
8 2
4
4 8 1 3
3
9 10 5
5 8 3 1
9 10 4
6
6 6 1 2
5
1 10
7 5 2 2
1 2
8 9
8 4 2 2
2 3
7 9
9 5 2 3
7 8
4 5 10
10 10 2 3
1 6
4 9 5

OUTPUT FORMAT

The output file should contain a single line with a single integer that represents the shortest surrounded perimeter.

SAMPLE OUTPUT (file fence6.out)

12




posted on 2009-07-17 14:26 YZY 閱讀(616) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm 、USACO 、圖論

導航

<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

統計

常用鏈接

留言簿(2)

隨筆分類

隨筆檔案

搜索

積分與排名

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲美女精品久久| 欧美精品亚洲一区二区在线播放| 午夜国产精品影院在线观看| 日韩视频在线观看一区二区| 亚洲国产精品一区| 91久久精品一区二区三区| 最新中文字幕一区二区三区| 日韩天堂在线视频| 亚洲网址在线| 欧美在线91| 欧美暴力喷水在线| 亚洲国产精品成人va在线观看| 久久久久久久999精品视频| 午夜视频一区| 欧美电影专区| 在线视频一区二区| 欧美一区二区免费观在线| 久久在线91| 欧美日韩一区综合| 激情亚洲成人| 亚洲图片欧洲图片日韩av| 欧美一区二区三区久久精品| 久久天天躁夜夜躁狠狠躁2022 | 国产视频在线观看一区二区三区 | 亚洲精品乱码久久久久| 亚洲深夜福利视频| 欧美顶级艳妇交换群宴| 一本一本久久a久久精品综合麻豆| 亚洲人成7777| 亚洲免费影视| 欧美绝品在线观看成人午夜影视| 欧美小视频在线| 在线精品国精品国产尤物884a| 99精品国产在热久久下载| 欧美一乱一性一交一视频| 免费亚洲视频| 小黄鸭精品密入口导航| 欧美精品在线视频观看| 黄色一区二区三区四区| 亚洲性av在线| 亚洲高清色综合| 久久电影一区| 国产精品每日更新在线播放网址| 亚洲日本无吗高清不卡| 久久亚洲精品中文字幕冲田杏梨| 夜夜躁日日躁狠狠久久88av| 久久久久中文| 国产视频综合在线| 亚洲一区二区精品| 亚洲精品久久久久久下一站| 久久久精品一区| 国产私拍一区| 欧美亚洲一区三区| 一本色道久久综合亚洲精品婷婷| 欧美国产免费| 亚洲国产日韩欧美在线99| 久久九九99| 西西人体一区二区| 国产视频观看一区| 亚洲男同1069视频| 99v久久综合狠狠综合久久| 欧美成人激情在线| 亚洲国产婷婷香蕉久久久久久99| 久久久一本精品99久久精品66| 一区二区三区日韩| 国产精品chinese| 亚洲女ⅴideoshd黑人| 这里只有精品电影| 国产精品一级在线| 久久国产精品久久久久久电车| 亚洲一区二区伦理| 国产亚洲在线| 欧美aⅴ一区二区三区视频| 久久人人爽人人| 亚洲国产欧美一区二区三区丁香婷| 裸体素人女欧美日韩| 久久久av网站| 亚洲国产成人一区| 亚洲片在线资源| 欧美日韩国产系列| 亚洲免费视频网站| 久久精品99国产精品酒店日本| 黑人一区二区| 欧美成人免费小视频| 欧美激情久久久| 国产精品国产三级欧美二区| 久久深夜福利免费观看| 伊人久久综合97精品| 亚洲电影天堂av| 欧美激情免费在线| 亚洲女人天堂成人av在线| 亚洲欧美日本日韩| 精品69视频一区二区三区| 亚洲国产成人av在线| 欧美性猛交视频| 麻豆成人综合网| 欧美日韩成人在线视频| 欧美一区二区三区婷婷月色 | 伊人久久男人天堂| 久久成人精品视频| 美国十次了思思久久精品导航| 亚洲高清一区二| aa国产精品| 国内精品久久久久久久果冻传媒| 亚洲电影免费观看高清完整版在线观看| 美玉足脚交一区二区三区图片| av不卡在线| 久久国产一区二区三区| 日韩视频在线一区| 欧美一区二区三区免费观看视频| 91久久久国产精品| 亚洲欧美激情一区二区| 亚洲国产精品999| 亚洲欧美日韩一区二区三区在线观看 | 久久日韩精品| 一区二区三区黄色| 一区二区视频免费完整版观看| 亚洲激情午夜| 国内成人自拍视频| 亚洲伊人一本大道中文字幕| 亚洲美女性视频| 久久精品亚洲精品| 午夜精品久久久久久久久| 欧美极品影院| 欧美激情四色 | 国产精品免费看片| 亚洲精品久久在线| 亚洲人永久免费| 久久精品二区| 久久久999成人| 国产精品乱码人人做人人爱| 亚洲精品网站在线播放gif| 影视先锋久久| 久久精品女人的天堂av| 欧美成人小视频| 久久久青草婷婷精品综合日韩| 国产精品二区三区四区| 亚洲另类黄色| 亚洲视频1区2区| 欧美视频免费| 夜夜嗨av一区二区三区网站四季av| 亚洲欧洲视频| 毛片一区二区| 欧美黄色一区二区| 99av国产精品欲麻豆| 欧美激情在线观看| 亚洲高清不卡在线| 亚洲视频在线观看网站| 国产精品国产三级国产专播精品人 | 国产精品伦一区| 亚洲一区国产精品| 午夜在线视频一区二区区别 | 亚洲国产视频a| 噜噜噜躁狠狠躁狠狠精品视频 | 欧美精品三区| 在线亚洲美日韩| 久久av一区二区三区| 国产欧美日韩免费| 欧美自拍偷拍午夜视频| 欧美1区免费| 亚洲免费不卡| 欧美午夜性色大片在线观看| 国产精品99久久久久久久女警 | 国产欧美日韩高清| 久久久亚洲精品一区二区三区| 欧美成人亚洲成人| 9色精品在线| 国产精品一区一区三区| 久久精品在线免费观看| 亚洲欧洲精品一区| 性色av一区二区三区| 狠狠噜噜久久| 欧美日韩成人一区二区| 韩国欧美一区| 欧美日产国产成人免费图片| 亚洲夜间福利| 免费观看成人鲁鲁鲁鲁鲁视频 | 欧美在线观看网址综合| 老司机久久99久久精品播放免费| 亚洲美女中文字幕| 国产一区欧美日韩| 欧美日韩一本到| 久久影视精品| 一本久道久久综合狠狠爱| 久久夜色精品国产亚洲aⅴ| 日韩一级二级三级| 国产精品主播| 欧美影院成人| 欧美成人精品激情在线观看| 日韩网站在线观看| 久久久国产一区二区| 亚洲毛片网站| 国产一区欧美| 国产精品xnxxcom| 欧美一区二区三区播放老司机| 久久精品在线视频| 亚洲国内在线| 国产亚洲在线| 国产精品免费福利| 欧美精品久久99久久在免费线|