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

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 閱讀(610) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO圖論

導航

<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

統計

常用鏈接

留言簿(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>
            欧美在线视频免费播放| 99精品欧美一区二区三区综合在线 | 黑人中文字幕一区二区三区| 国产精品www.| 国产精品你懂的在线欣赏| 国产精品视频导航| 黄色在线一区| 亚洲精品久久久久久久久| 亚洲最新视频在线| 欧美一级大片在线观看| 亚洲女同在线| 久久久久.com| 亚洲国产精品久久| 一本大道久久精品懂色aⅴ| 亚洲天堂成人| 久久尤物视频| 国产精品福利在线观看| 激情成人综合| 亚洲自拍偷拍视频| 鲁大师成人一区二区三区| 日韩视频在线观看免费| 久久成人免费电影| 欧美日韩亚洲国产精品| 国产综合激情| 99这里只有精品| 久久久久国色av免费看影院| 亚洲精品1区| 午夜免费久久久久| 欧美极品影院| 精品电影一区| 欧美影院成人| 亚洲美洲欧洲综合国产一区| 久久精品九九| 国产精一区二区三区| 99视频+国产日韩欧美| 久久精品30| 亚洲调教视频在线观看| 欧美乱人伦中文字幕在线| 黄色免费成人| 欧美一区综合| 亚洲无限av看| 欧美日韩亚洲一区三区| 亚洲国产91色在线| 久久综合给合| 久久九九99| 国产视频久久久久| 亚洲欧美中文另类| 一本色道久久88综合亚洲精品ⅰ| 另类亚洲自拍| 亚洲第一视频网站| 久久久久久综合网天天| 亚洲欧美日韩一区二区| 国产精品a级| 欧美日韩国产经典色站一区二区三区| 亚洲欧美在线播放| 国产精品你懂的| 亚洲一区二区在线| 91久久精品国产91久久性色tv| 久久免费偷拍视频| 红桃视频一区| 欧美成人第一页| 蜜臀99久久精品久久久久久软件 | 欧美在线观看视频在线 | 欧美1区2区| 久久精品一区二区| 樱花yy私人影院亚洲| 久久中文久久字幕| 久久综合影视| 亚洲黄色av| 亚洲日韩第九十九页| 欧美日韩精品一区二区天天拍小说| 亚洲欧洲日产国产综合网| 欧美高清在线播放| 欧美欧美全黄| 午夜激情综合网| 亚洲欧美成人一区二区在线电影 | 噜噜噜在线观看免费视频日韩| 精品成人一区| 亚洲福利精品| 国产精品福利在线观看| 欧美中文字幕| 久久婷婷色综合| 在线视频中文亚洲| 亚洲在线第一页| 在线免费观看日韩欧美| 亚洲国产天堂久久国产91| 欧美日韩视频一区二区三区| 午夜国产精品视频免费体验区| 欧美一区日本一区韩国一区| 亚洲高清免费在线| 日韩视频不卡| 国产亚洲欧美另类中文| 欧美激情一级片一区二区| 欧美午夜电影一区| 麻豆精品在线视频| 欧美日韩一二区| 久久综合给合久久狠狠狠97色69| 欧美极品一区二区三区| 欧美一区二区三区的| 男人的天堂成人在线| 性做久久久久久久免费看| 久久久久久久999精品视频| 一本色道久久88综合亚洲精品ⅰ | 国产精品视频xxxx| 亚洲第一毛片| 黄色av一区| 亚洲一区二区三区高清| 亚洲国产成人午夜在线一区| 一区二区国产精品| 亚洲国产精品v| 亚洲一区二区在| 亚洲欧洲一区二区天堂久久| 亚洲自拍偷拍色片视频| 亚洲精品国产欧美| 久久精品国产999大香线蕉| 一本久久精品一区二区| 久久精品亚洲一区二区| 午夜精品美女久久久久av福利| 免费欧美日韩| 美腿丝袜亚洲色图| 国产热re99久久6国产精品| 日韩视频在线观看免费| 亚洲欧洲另类国产综合| 久久综合99re88久久爱| 欧美中文字幕在线观看| 欧美亚韩一区| 一区二区三区四区五区在线| 亚洲日本激情| 女人色偷偷aa久久天堂| 嫩草国产精品入口| 伊人色综合久久天天| 久久国产福利| 久久亚洲综合色一区二区三区| 国产欧美日韩激情| 亚洲永久网站| 亚洲在线视频一区| 欧美视频二区36p| 日韩视频三区| 亚洲一级影院| 欧美日韩一区免费| 亚洲图色在线| 欧美一区二区国产| 国产日韩欧美亚洲一区| 欧美一乱一性一交一视频| 久久成人一区| 极品av少妇一区二区| 久久久久久香蕉网| 免费黄网站欧美| 日韩视频精品在线| 欧美日韩91| 中日韩高清电影网| 欧美在线视频一区二区三区| 国产主播喷水一区二区| 久热精品视频| 99re热精品| 久久久精品性| 亚洲人成网在线播放| 欧美日韩国产在线看| 亚洲一区激情| 你懂的亚洲视频| 一区二区不卡在线视频 午夜欧美不卡在| 欧美国产91| 中文一区字幕| 久久综合电影| 中文亚洲免费| 国内精品亚洲| 欧美国产精品专区| 亚洲免费在线精品一区| 噜噜噜噜噜久久久久久91| 日韩视频免费在线| 国产欧美丝祙| 欧美国产先锋| 小处雏高清一区二区三区| 欧美国产视频在线观看| 亚洲主播在线播放| 麻豆精品一区二区av白丝在线| 国产免费成人av| 久久―日本道色综合久久| 亚洲免费电影在线| 免费中文日韩| 午夜视频在线观看一区二区三区 | 欧美精品一区二区精品网| 亚洲午夜精品一区二区三区他趣| 免费不卡在线视频| 性欧美办公室18xxxxhd| 亚洲精品一二| 激情综合亚洲| 国产精品综合| 国产精品sm| 蜜臀a∨国产成人精品| 欧美一级大片在线免费观看| 亚洲欧洲偷拍精品| 久久婷婷蜜乳一本欲蜜臀| 亚洲无亚洲人成网站77777 | 快射av在线播放一区| 亚洲少妇最新在线视频| 欧美福利在线| 老司机精品视频网站| 欧美在线精品一区| 亚洲欧美日本国产有色|