7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

日本の中心は三重県説

Posted at

#日本の中心は三重県説
都道府県を越境するのにかかるコストを1として、それぞれの都道府県へ移動するコストの総和が最も少ない県が日本の中心であるとする。

各都道府県の連結関係を列挙

Aomori Iwate
Aomori Akite
Iwate Miyagi
Miyagi Akita
Miyagi Yamagata
Miyagi Fukushima
Akita Yamagata
Yamagata Fukushima
Yamagata Niigata
Fukushima Ibaraki
Fukushima Tochigi
Fukushima Gunma
Fukushima Niigata
Ibaraki Tochigi
Ibaraki Saitama
Ibaraki Chiba
Tochigi Gunma
Tochigi Saitama
Gunma Saitama
Gunma Niigata
Gunma Nagano
Saitama Chiba
Saitama Tokyo
Saitama Yamanashi
Saitama Nagano
Chiba Tokyo
Tokyo Kanagawa
Tokyo Yamanashi
Kanagawa Yamanashi
Kanagawa Shizuoka
Niigata Toyama
Niigata Nagano
Toyama Ishikawa
Toyama Nagano
Toyama Gifu
Ishikawa Fukui
Ishikawa Gifu
Fukui Gifu
Fukui Shiga
Fukui Kyoto
Yamanashi Nagano
Yamanashi Shizuoka
Nagano Gifu
Nagano Shizuoka
Nagano Aichi
Gifu Aichi
Gifu Mie
Gifu Shiga
Shizuoka Aichi
Aichi Mie
Mie Shiga
Mie Osaka
Mie Nara
Mie Wakayama
Shiga Kyoto
Shiga Osaka
Kyoto Osaka
Kyoto Hyogo
Osaka Hyogo
Osaka Nara
Osaka Wakayama
Hyogo Tottori
Hyogo Okayama
Nara Wakayama
Tottori Shimane
Tottori Okayama
Tottori Hiroshima
Shimane Hiroshima
Shimane Yamaguchi
Okayama Hiroshima
Hiroshima Yamaguchi
Tokushima Kagawa
Tokushima Ehime
Tokushima Kochi
Kagawa Ehime
Ehime Kochi
Fukuoka Saga
Fukuoka Kumamoto
Fukuoka Oita
Saga Nagasaki
Kumamoto Oita
Kumamoto Miyazaki
Kumamoto Kagoshima
Oita Miyazaki
Miyazaki Kagoshima
Hokkaido Aomori
Chiba Kanagawa
Hyogo Tokushima
Okayama Kagawa
Hiroshima Ehime
Yamaguchi Fukuoka
Kagoshima Okinawa

下から7行は陸続きではないが、橋がかかっていたり、海上隣接であったりするので、便宜上隣接しているものとした。

ループをグルグル回して、集計。

#include <iostream>
#include <fstream>
#include <string>

#define PREFECTURES 47

using namespace std;


string prefectures[PREFECTURES] ={"Hokkaido",
	"Aomori","Iwate","Miyagi","Akita","Yamagata","Fukushima",
	"Ibaraki","Tochigi","Gunma","Saitama","Chiba","Tokyo","Kanagawa",
	"Niigata","Toyama","Ishikawa","Fukui","Yamanashi","Nagano","Gifu","Shizuoka","Aichi",
	"Mie","Shiga","Kyoto","Osaka","Hyogo","Nara","Wakayama",
	"Tottori","Shimane","Okayama","Hiroshima","Yamaguchi",
	"Tokushima","Kagawa","Ehime","Kochi",
	"Fukuoka","Saga","Nagasaki","Kumamoto","Oita","Miyazaki","Kagoshima",
	"Okinawa"};
int conectted[PREFECTURES][PREFECTURES]={{0}};

int ptoi(string str){
	int i;
	for(i=0; i<PREFECTURES; i++){
		if(str == prefectures[i]){
			return i;
		}
	}
}

int main(void){
	ifstream ifs("prefectures.txt");
	ofstream ofs("log.txt");
	string p1,p2;
	for(int i=0; i<PREFECTURES; i++){
		for(int j=0; j<PREFECTURES; j++){
			conectted[i][j]=99;
		}
	}
	for(int i=0; i<PREFECTURES; i++){
		conectted[i][i]=0;
	}
	while(ifs >> p1 >> p2){
		conectted[ptoi(p1)][ptoi(p2)]=1;
	}

	for(int i=0; i<PREFECTURES-1; i++){
		for(int j=i+1; j<PREFECTURES; j++){
			if(conectted[i][j]==1){
				conectted[j][i]=1;
			}
		}
	}

	for(int i=0; i<PREFECTURES*2; i++){
		for(int j=0; j<PREFECTURES; j++){
			for(int k=0; k<PREFECTURES-1; k++){
				if(conectted[j][k]!=99){
					for(int l=k+1; l<PREFECTURES; l++){
						if(conectted[j][k]+conectted[j][l]<conectted[k][l]){
							conectted[k][l]=conectted[j][k]+conectted[j][l];
						}
					}
				}
			}
		}
	}

	for(int i=0; i<PREFECTURES; i++){
		for(int j=0; j<PREFECTURES; j++){
			conectted[j][i]=conectted[i][j];
		}
	}

	for(int i=0; i<PREFECTURES; i++){
		int len=0;
		for(int j=0; j<PREFECTURES;j++){
			len += conectted[i][j];
		}
		ofs << len << "," << prefectures[i] << endl;
	}
}

結果

411,Hokkaido
366,Aomori
323,Iwate
282,Miyagi
293,Akita
252,Yamagata
246,Fukushima
252,Ibaraki
253,Tochigi
222,Gunma
227,Saitama
260,Chiba
267,Tokyo
250,Kanagawa
222,Niigata
205,Toyama
207,Ishikawa
203,Fukui
232,Yamanashi
195,Nagano
186,Gifu
212,Shizuoka
189,Aichi
184,Mie
187,Shiga
191,Kyoto
187,Osaka
195,Hyogo
208,Nara
208,Wakayama
215,Tottori
239,Shimane
215,Okayama
234,Hiroshima
262,Yamaguchi
224,Tokushima
254,Kagawa
243,Ehime
257,Kochi
293,Fukuoka
336,Saga
381,Nagasaki
331,Kumamoto
333,Oita
373,Miyazaki
373,Kagoshima
418,Okinawa

三重県の184が最良のスコアであるので、三重県が日本の中心であると言える

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?