SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
紹介
        詳解 ICL
 (Interval Container Library)

2011/2/26 Boost 勉強会 #4 未発表
       @yak_ex / 新 康孝
自己紹介
• 氏名: 新 康孝 (あたらし やすたか)
• Twitter ID: yak_ex
• Web: http://yak3.myhome.cx:8080/junks

• C++ / Perl が主戦場
• 現在、仕事でコードに触れていないので
  競技プログラミング(TopCoder、Codeforces)で
  潤い補充
• 闇の軍団に憧れるただの C++ 好き
  – 今回は ICL のさわりだけ、というかさわりしか分からない
ぼくのかんがえた「ぶーすと」のぶんるい
         アプリより




小規模              大規模




         実装より
ぼくのかんがえた「ぶーすと」のぶんるい
                                       アプリより                ~1.25
                                                     test

                                                            graph
 progress_display た
      んはココ                              thread
小規模                                                                     大規模
      crc              pool                              regex
   tokenizer
      lexical_cast            random

                       function
     array
  timer rational                                 iteratorstype_traits
  any operators
               tuple                   実装より
ぼくのかんがえた「ぶーすと」のぶんるい
   異次元                                     アプリより                   ~1.30
   preprocessor                                            test
                                                                           spirit
                                                       date_time
                                                                   graph
                              filesystem
 progress_display た
      んはココ                                   thread
小規模                format                                                     大規模
      crc              pool                                   regex
   tokenizer
      lexical_cast            random

                       function
     array                                     lambda
  timer rational         multi_array                 iteratorstype_traits
  any optional                                                        mpl
               tuple                       実装より
ぼくのかんがえた「ぶーすと」のぶんるい
   異次元                                       アプリより                      ~1.35
   preprocessor                                                  test asio
   wave                                                      gil
                                                                                spirit
                                                            date_time
                                                                        graph
                            filesystem
 progress_display た
                          statechart      thread
      んはココ                                                    serialization
小規模                format program_options                            interprocess 大規模
      crc              pool                                          regex
   tokenizer                                                        xpressive

      lexical_cast            random
                                                    bimap
                       function                      multi_index
     array                parameter                  lambda           intrusive
                               variant ptr_container         range         fusion
  timer rational
       foreach            multi_array                       iteratorstype_traits
  any optional                                                        typeof mpl
               tuple                          実装より
ぼくのかんがえた「ぶーすと」のぶんるい
   異次元                                       アプリより                      ~1.40
   preprocessor                                                  test asio
   wave                                         accmulators gil
                                                                                spirit
                                                           date_time
                                                                        graph
                            filesystem
 progress_display た
                          statechart      thread
      んはココ                                            serialization
小規模                format program_options        proto       interprocess 大規模
      crc              pool                                          regex
   tokenizer                                                        xpressive

      lexical_cast            random
       scope_exit                                   bimap
                       function unordered            multi_index
     array                parameter                  lambda
                                             flyweight                intrusive
                               variant ptr_container         range         fusion
  timer rational
       foreach            multi_array                       iteratorstype_traits
  any optional                                                        typeof mpl
               tuple                          実装より
ぼくのかんがえた「ぶーすと」のぶんるい
   異次元                                       アプリより                      ~1.45
   preprocessor                                                  test asio
   wave                                    accmulators gil
                                                                         spirit
                                                      date_time
                                                                   graph
                        filesystem property_tree            polygon
 progress_display た                                   msm
                      statechart            thread
      んはココ                                              serialization
小規模       uuid     format program_options          proto       interprocess 大規模
      crc              pool                                          regex
   tokenizer                                                        xpressive

      lexical_cast            random
       scope_exit                                   bimap
                       function unordered            multi_index
     array                parameter                  lambda
                                             flyweight                intrusive
                               variant ptr_container         range         fusion
  timer rational
       foreach            multi_array                       iteratorstype_traits
  any optional                                                        typeof mpl
               tuple                          実装より
ぼくのかんがえた「ぶーすと」のぶんるい
   異次元                                       アプリより                      ~1.46
   preprocessor                                                  test asio
   wave                                    accmulators gil
                                                                         spirit
                                                      date_time
                                                                   graph
                        filesystem property_tree      ICL   polygon
 progress_display た                                   msm
                      statechart            thread
      んはココ                                              serialization
小規模       uuid     format program_options          proto       interprocess 大規模
      crc              pool                                          regex
   tokenizer                                                        xpressive

      lexical_cast            random
       scope_exit                                   bimap
                       function unordered            multi_index
     array                parameter                  lambda
                                             flyweight                intrusive
                               variant ptr_container         range         fusion
  timer rational
       foreach            multi_array                       iteratorstype_traits
  any optional                                                        typeof mpl
               tuple                          実装より
ここで競技コーディングのお時間です
• akira さん(仮名)はパーティーを開くことになりました。N 人
  のお客さんが参加する予定ですが参加時間帯[si, ti)が皆ば
  らばらです。場所の予約のために参加人数の最も多い時間
  帯を知りたいのでプログラムを作って akira さんを助けてあ
  げましょう。

  – 1 ≦ N ≦ 1000
  – -109 ≦ si < ti ≦ 109, si, ti は整数 (i=1,2,…,N)
  – 参加人数が同じ時間帯が隣接している場合、参加者が異なっていて
    も一つの時間帯と見なす
  – 同一参加人数の時間帯が複数ある場合は最長の時間帯を、同じ長
    さの時間帯が複数ある場合は開始時刻がもっとも早い時間帯を返す
  – 入力: N<改行>s1<空白>t1<改行>…sN<空白>tN<改行>
  – 出力:開始時刻<空白>終了時刻<空白>人数<改行>
解答例全文 using ICL
#include <iostream>
#include <algorithm>
#include <utility>                                                                             #include 含めて 25 行
#include <boost/icl/interval_map.hpp>

int main(void)
{
   boost::icl::interval_map<int, int> sum;
   int n;
   std::cin >> n;
   for(int i = 0; i < n; ++i) {
       int s, t;
       std::cin >> s >> t;
       sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1);
   }
   typedef boost::icl::interval_map<int, int>::value_type value_type;
   auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const value_type &v2) {
       return
          v1.second < v2.second ||
          (v1.second == v2.second && v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) ||
          (v1.second == v2.second && v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() &&
                                                                                            v1.first.lower() < v2.first.lower());
   });
   std::cout << it->first.lower() << ' ' << it->first.upper() << ' ' << it->second << std::endl;
   return 0;
}
解答例全文 using ICL
#include <iostream>
#include <algorithm>                             ヘッダのインクルード
#include <utility>
#include <boost/icl/interval_map.hpp>

int main(void)
{
   boost::icl::interval_map<int, int> sum;
   int n;
   std::cin >> n;
   for(int i = 0; i < n; ++i) {
       int s, t;                                                                            入力と登録
       std::cin >> s >> t;
       sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1);
   }
   typedef boost::icl::interval_map<int, int>::value_type value_type;                                            最大値取得
   auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const value_type &v2) {
       return
          v1.second < v2.second ||
          (v1.second == v2.second && v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) ||
          (v1.second == v2.second && v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() &&
                                                                                            v1.first.lower() < v2.first.lower());
   });
   std::cout << it->first.lower() << ' ' << it->first.upper() << ' ' << it->second << std::endl;
   return 0;                                                                                           出力
}
解答例 入力と登録
boost::icl::interval_map<int, int> sum;
int n;
std::cin >> n;
for(int i = 0; i < n; ++i) {                            今回は数だが集合も可能
   int s, t;
   std::cin >> s >> t;                  右開区間 [s, t)
   sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1);
}
                 1
                                             1
         +                               +
     1                            1
                                                     split_interval_map
                          interval_map                              1
             2                           1                1
 1                   1
解答例 最大値取得
typedef boost::icl::interval_map<int, int>::value_type value_type;
   auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const
    value_type &v2) {
       return
          v1.second < v2.second ||          // 集計値は second
          (v1.second == v2.second &&            // 区間は first (upper(), lower() で境界値)
            v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) ||
          (v1.second == v2.second &&
            v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() &&
            v1.first.lower() < v2.first.lower());
   });

 集計された区間の結果を iteration 可能なので普通に max_element で最大値取得
Interval Container Library
•   1.46 で導入
•   開区間、閉区間等全部取り扱い可能
•   区間に対する集合演算、「集計」が可能
•   interval_set,
    interval_map                                         interval_set a
                                                         interval_set b
                                         interval_set a - b
•   区間の統合方法として join, separate, split を選択可能
•   ストリーム出力有り(例:{(1,3][4.6](7,8]})
•   Traits 用意すれば自前の interval を突っ込むことも可能
•   数値に限定されないので例えば
    cotinuous_interval<std::string> w(“a”, “c”) // right_open
    とか書くと a, b で始まる文字列全部を表すことになる。
•   Example がいっぱいなのでそれ見ればOK

Contenu connexe

En vedette

GC in C++0x
GC in C++0xGC in C++0x
GC in C++0xyak1ex
 
Tribocracy.com presentation
Tribocracy.com presentationTribocracy.com presentation
Tribocracy.com presentationKwamecorp
 
Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp
 
kwamecorp open design
kwamecorp open design kwamecorp open design
kwamecorp open design Kwamecorp
 
GC in C++0x [eng]
GC in C++0x [eng]GC in C++0x [eng]
GC in C++0x [eng]yak1ex
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competitionyak1ex
 

En vedette (8)

GC in C++0x
GC in C++0xGC in C++0x
GC in C++0x
 
Tribocracy.com presentation
Tribocracy.com presentationTribocracy.com presentation
Tribocracy.com presentation
 
Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013
 
kwamecorp open design
kwamecorp open design kwamecorp open design
kwamecorp open design
 
Impossible
ImpossibleImpossible
Impossible
 
GC in C++0x [eng]
GC in C++0x [eng]GC in C++0x [eng]
GC in C++0x [eng]
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competition
 

Similaire à Brief introduction of Boost.ICL [PDF]

Similaire à Brief introduction of Boost.ICL [PDF] (6)

エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7
 
エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半
 
そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4
 
Rcppのすすめ
RcppのすすめRcppのすすめ
Rcppのすすめ
 
R spec勉強会
R spec勉強会R spec勉強会
R spec勉強会
 
Rの高速化
Rの高速化Rの高速化
Rの高速化
 

Plus de yak1ex

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]yak1ex
 
Introduction to programming competition [revised]
Introduction to programming competition [revised]Introduction to programming competition [revised]
Introduction to programming competition [revised]yak1ex
 
Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]yak1ex
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 

Plus de yak1ex (6)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]
 
Introduction to programming competition [revised]
Introduction to programming competition [revised]Introduction to programming competition [revised]
Introduction to programming competition [revised]
 
Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 

Dernier

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 

Dernier (9)

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 

Brief introduction of Boost.ICL [PDF]

  • 1. 紹介 詳解 ICL (Interval Container Library) 2011/2/26 Boost 勉強会 #4 未発表 @yak_ex / 新 康孝
  • 2. 自己紹介 • 氏名: 新 康孝 (あたらし やすたか) • Twitter ID: yak_ex • Web: http://yak3.myhome.cx:8080/junks • C++ / Perl が主戦場 • 現在、仕事でコードに触れていないので 競技プログラミング(TopCoder、Codeforces)で 潤い補充 • 闇の軍団に憧れるただの C++ 好き – 今回は ICL のさわりだけ、というかさわりしか分からない
  • 3. ぼくのかんがえた「ぶーすと」のぶんるい アプリより 小規模 大規模 実装より
  • 4. ぼくのかんがえた「ぶーすと」のぶんるい アプリより ~1.25 test graph progress_display た んはココ thread 小規模 大規模 crc pool regex tokenizer lexical_cast random function array timer rational iteratorstype_traits any operators tuple 実装より
  • 5. ぼくのかんがえた「ぶーすと」のぶんるい 異次元 アプリより ~1.30 preprocessor test spirit date_time graph filesystem progress_display た んはココ thread 小規模 format 大規模 crc pool regex tokenizer lexical_cast random function array lambda timer rational multi_array iteratorstype_traits any optional mpl tuple 実装より
  • 6. ぼくのかんがえた「ぶーすと」のぶんるい 異次元 アプリより ~1.35 preprocessor test asio wave gil spirit date_time graph filesystem progress_display た statechart thread んはココ serialization 小規模 format program_options interprocess 大規模 crc pool regex tokenizer xpressive lexical_cast random bimap function multi_index array parameter lambda intrusive variant ptr_container range fusion timer rational foreach multi_array iteratorstype_traits any optional typeof mpl tuple 実装より
  • 7. ぼくのかんがえた「ぶーすと」のぶんるい 異次元 アプリより ~1.40 preprocessor test asio wave accmulators gil spirit date_time graph filesystem progress_display た statechart thread んはココ serialization 小規模 format program_options proto interprocess 大規模 crc pool regex tokenizer xpressive lexical_cast random scope_exit bimap function unordered multi_index array parameter lambda flyweight intrusive variant ptr_container range fusion timer rational foreach multi_array iteratorstype_traits any optional typeof mpl tuple 実装より
  • 8. ぼくのかんがえた「ぶーすと」のぶんるい 異次元 アプリより ~1.45 preprocessor test asio wave accmulators gil spirit date_time graph filesystem property_tree polygon progress_display た msm statechart thread んはココ serialization 小規模 uuid format program_options proto interprocess 大規模 crc pool regex tokenizer xpressive lexical_cast random scope_exit bimap function unordered multi_index array parameter lambda flyweight intrusive variant ptr_container range fusion timer rational foreach multi_array iteratorstype_traits any optional typeof mpl tuple 実装より
  • 9. ぼくのかんがえた「ぶーすと」のぶんるい 異次元 アプリより ~1.46 preprocessor test asio wave accmulators gil spirit date_time graph filesystem property_tree ICL polygon progress_display た msm statechart thread んはココ serialization 小規模 uuid format program_options proto interprocess 大規模 crc pool regex tokenizer xpressive lexical_cast random scope_exit bimap function unordered multi_index array parameter lambda flyweight intrusive variant ptr_container range fusion timer rational foreach multi_array iteratorstype_traits any optional typeof mpl tuple 実装より
  • 10. ここで競技コーディングのお時間です • akira さん(仮名)はパーティーを開くことになりました。N 人 のお客さんが参加する予定ですが参加時間帯[si, ti)が皆ば らばらです。場所の予約のために参加人数の最も多い時間 帯を知りたいのでプログラムを作って akira さんを助けてあ げましょう。 – 1 ≦ N ≦ 1000 – -109 ≦ si < ti ≦ 109, si, ti は整数 (i=1,2,…,N) – 参加人数が同じ時間帯が隣接している場合、参加者が異なっていて も一つの時間帯と見なす – 同一参加人数の時間帯が複数ある場合は最長の時間帯を、同じ長 さの時間帯が複数ある場合は開始時刻がもっとも早い時間帯を返す – 入力: N<改行>s1<空白>t1<改行>…sN<空白>tN<改行> – 出力:開始時刻<空白>終了時刻<空白>人数<改行>
  • 11. 解答例全文 using ICL #include <iostream> #include <algorithm> #include <utility> #include 含めて 25 行 #include <boost/icl/interval_map.hpp> int main(void) { boost::icl::interval_map<int, int> sum; int n; std::cin >> n; for(int i = 0; i < n; ++i) { int s, t; std::cin >> s >> t; sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1); } typedef boost::icl::interval_map<int, int>::value_type value_type; auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const value_type &v2) { return v1.second < v2.second || (v1.second == v2.second && v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) || (v1.second == v2.second && v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() && v1.first.lower() < v2.first.lower()); }); std::cout << it->first.lower() << ' ' << it->first.upper() << ' ' << it->second << std::endl; return 0; }
  • 12. 解答例全文 using ICL #include <iostream> #include <algorithm> ヘッダのインクルード #include <utility> #include <boost/icl/interval_map.hpp> int main(void) { boost::icl::interval_map<int, int> sum; int n; std::cin >> n; for(int i = 0; i < n; ++i) { int s, t; 入力と登録 std::cin >> s >> t; sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1); } typedef boost::icl::interval_map<int, int>::value_type value_type; 最大値取得 auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const value_type &v2) { return v1.second < v2.second || (v1.second == v2.second && v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) || (v1.second == v2.second && v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() && v1.first.lower() < v2.first.lower()); }); std::cout << it->first.lower() << ' ' << it->first.upper() << ' ' << it->second << std::endl; return 0; 出力 }
  • 13. 解答例 入力と登録 boost::icl::interval_map<int, int> sum; int n; std::cin >> n; for(int i = 0; i < n; ++i) { 今回は数だが集合も可能 int s, t; std::cin >> s >> t; 右開区間 [s, t) sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1); } 1 1 + + 1 1 split_interval_map interval_map 1 2 1 1 1 1
  • 14. 解答例 最大値取得 typedef boost::icl::interval_map<int, int>::value_type value_type; auto it = max_element(sum.begin(), sum.end(), [](const value_type &v1, const value_type &v2) { return v1.second < v2.second || // 集計値は second (v1.second == v2.second && // 区間は first (upper(), lower() で境界値) v1.first.upper() - v1.first.lower() < v2.first.upper() - v2.first.lower()) || (v1.second == v2.second && v1.first.upper() - v1.first.lower() == v2.first.upper() - v2.first.lower() && v1.first.lower() < v2.first.lower()); }); 集計された区間の結果を iteration 可能なので普通に max_element で最大値取得
  • 15. Interval Container Library • 1.46 で導入 • 開区間、閉区間等全部取り扱い可能 • 区間に対する集合演算、「集計」が可能 • interval_set, interval_map interval_set a interval_set b interval_set a - b • 区間の統合方法として join, separate, split を選択可能 • ストリーム出力有り(例:{(1,3][4.6](7,8]}) • Traits 用意すれば自前の interval を突っ込むことも可能 • 数値に限定されないので例えば cotinuous_interval<std::string> w(“a”, “c”) // right_open とか書くと a, b で始まる文字列全部を表すことになる。 • Example がいっぱいなのでそれ見ればOK