SlideShare a Scribd company logo
1 of 11
Download to read offline
Problem J:Char Swap
怒髪@dohatsutsu
問題概要
文字列Sが与えられます。
隣り合った2つの文字をスワップする操作を行うことで、文字列Sを回文にしたいです。
最小で何回のスワップを行う必要があるでしょうか?
考察
文字列Sが次のような文字列だった場合について考えます。
a a b c b c a d d a
考察
説明をより分かりやすくするため、一部の文字の色を変えます。
a は4回出現しているので、左から見て行って最初の2個のa は赤色に染めます。
b は2回出現しているので、左から見て行って最初の1個のb は赤色に染めます。
c と d も同様です。
a a b c b c a d d a
考察
この文字列を最小のスワップ回数で回文にするためには、
赤い文字をすべて最初の5文字として使わなければなりません。
これは、同じアルファベットが隣り合っているときにそのアルファベットどうしをスワップす
ることがあり得ないためです。
a a b c b c a d d a
↓
? ? ? ? ? ? ? ? ? ?
考察
とりあえず、赤い文字が左側にくるように、スワップしていくと、こうなります。
a a b c b c a d d a
↓
a a b c d b c a d a
考察
あとは、右半分の文字が、左半分の文字をRverseした状態にするための最小回数を求
めるだけです。( 反対に、左半分を右半分に合わせるようにしてもよいです。)
a a b c d b c a d a
↓
d c b a a ---- b c a d a
考察
これは、蟻本にあるバブルソートの交換回数と同じ方法で求めることができます。
p162にのっています。
謝罪
既出だったらしいです。すいませんでした。
AC数 ÷提出数 = 6÷16 = 0.3750 … ( 38% )
First AC
maroonさん 80分
テスター
dohatsu 61行
arrows 75行
kzyKT 55行
sate 79行
uku 69行

More Related Content

More from Takumi Yamashita (20)

Deposited Ranges
Deposited RangesDeposited Ranges
Deposited Ranges
 
RUPC2017:F解説
RUPC2017:F解説RUPC2017:F解説
RUPC2017:F解説
 
RUPC2017:L解説
RUPC2017:L解説RUPC2017:L解説
RUPC2017:L解説
 
RUPC2017:G解説
RUPC2017:G解説RUPC2017:G解説
RUPC2017:G解説
 
RUPC2017:Dの解説
RUPC2017:Dの解説RUPC2017:Dの解説
RUPC2017:Dの解説
 
RUPC2017:Bの解説
RUPC2017:Bの解説RUPC2017:Bの解説
RUPC2017:Bの解説
 
RUPC2017:Cの解説
RUPC2017:Cの解説RUPC2017:Cの解説
RUPC2017:Cの解説
 
RUPC2017:I解説
RUPC2017:I解説RUPC2017:I解説
RUPC2017:I解説
 
RUPC2017:Aの解説
RUPC2017:Aの解説RUPC2017:Aの解説
RUPC2017:Aの解説
 
RUPC2017:Hの解説
RUPC2017:Hの解説RUPC2017:Hの解説
RUPC2017:Hの解説
 
RUPC2017:K解説
RUPC2017:K解説RUPC2017:K解説
RUPC2017:K解説
 
RUPC2017:E解説
RUPC2017:E解説RUPC2017:E解説
RUPC2017:E解説
 
RUPC2017:M問題
RUPC2017:M問題RUPC2017:M問題
RUPC2017:M問題
 
0: 全体の講評
0: 全体の講評0: 全体の講評
0: 全体の講評
 
H : hegemony get
H : hegemony getH : hegemony get
H : hegemony get
 
G : 解説
G : 解説G : 解説
G : 解説
 
F : 解説
F : 解説F : 解説
F : 解説
 
E : 解説
E : 解説E : 解説
E : 解説
 
D : 解説
D : 解説D : 解説
D : 解説
 
C : 解説
C : 解説C : 解説
C : 解説
 

Recently uploaded

3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイントshu1108hina1020
 
Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfoganekyokoi
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdfoganekyokoi
 
The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.oganekyokoi
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...yutakashikano1984
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrRodolfFernandez1
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1Toru Oga
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfoganekyokoi
 
Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...oganekyokoi
 

Recently uploaded (9)

3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
 
Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdf
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdf
 
The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdf
 
Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...
 

J : 解説