SlideShare una empresa de Scribd logo
1 de 15
   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 大規模 小規模 regex crc pool tokenizer random lexical_cast function array rational type_traits timer iterators operators any tuple 実装より
ぼくのかんがえた「ぶーすと」のぶんるい ~1.30 アプリより 異次元 preprocessor test spirit date_time graph filesystem progress_display たんはココ thread 大規模 小規模 format regex crc pool tokenizer random lexical_cast function array lambda rational type_traits timer iterators multi_array mpl any optional tuple 実装より
ぼくのかんがえた「ぶーすと」のぶんるい ~1.35 アプリより 異次元 preprocessor asio test gil wave spirit date_time graph filesystem progress_display たんはココ statechart thread serialization 大規模 小規模 format program_options interprocess regex crc pool xpressive tokenizer random lexical_cast bimap function multi_index intrusive parameter array lambda range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
ぼくのかんがえた「ぶーすと」のぶんるい ~1.40 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph filesystem progress_display たんはココ statechart thread serialization 大規模 小規模 format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
ぼくのかんがえた「ぶーすと」のぶんるい ~1.45 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph property_tree filesystem polygon progress_display たんはココ msm statechart thread serialization 大規模 小規模 uuid format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
ぼくのかんがえた「ぶーすと」のぶんるい ~1.46 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph property_tree filesystem polygon ICL progress_display たんはココ msm statechart thread serialization 大規模 小規模 uuid format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional 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 <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; } #include 含めて 25 行
解答例全文 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;         sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1);     } 今回は数だが集合も可能 右開区間 [s, t) 1 1 + + 1 1 split_interval_map 1 interval_map 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 ||             (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());     }); // 集計値は second // 区間は first (upper(), lower() で境界値) 集計された区間の結果を iteration 可能なので普通に max_element で最大値取得
Interval Container Library 1.46 で導入 開区間、閉区間等全部取り扱い可能 区間に対する集合演算、「集計」が可能 interval_set, interval_map 区間の統合方法として join, separate, split を選択可能 ストリーム出力有り(例:{(1,3][4.6](7,8]}) Traits 用意すれば自前の interval を突っ込むことも可能 数値に限定されないので例えばcotinuous_interval<std::string> w(“a”, “c”) // right_openとか書くと a, b で始まる文字列全部を表すことになる。 Example がいっぱいなのでそれ見ればOK interval_set a interval_set b interval_set a - b

Más contenido relacionado

La actualidad más candente

C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプKohsuke Yuasa
 
Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Keisuke Fukuda
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由kikairoya
 
Wrapping a C++ library with Cython
Wrapping a C++ library with CythonWrapping a C++ library with Cython
Wrapping a C++ library with Cythonfuzzysphere
 
Boost.Coroutine
Boost.CoroutineBoost.Coroutine
Boost.Coroutinemelpon
 
Cython ことはじめ
Cython ことはじめCython ことはじめ
Cython ことはじめgion_XY
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチンyohhoy
 
Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Yuichi Sakuraba
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかYuki Miyatake
 
C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみたfirewood
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.ContextAkira Takahashi
 
競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性Hibiki Yamashiro
 
NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門Shiqiao Du
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案yohhoy
 
C++11概要 ライブラリ編
C++11概要 ライブラリ編C++11概要 ライブラリ編
C++11概要 ライブラリ編egtra
 

La actualidad más candente (20)

Emcpp item31
Emcpp item31Emcpp item31
Emcpp item31
 
C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプ
 
Emcjp item33,34
Emcjp item33,34Emcjp item33,34
Emcjp item33,34
 
Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
 
Wrapping a C++ library with Cython
Wrapping a C++ library with CythonWrapping a C++ library with Cython
Wrapping a C++ library with Cython
 
Boost.Coroutine
Boost.CoroutineBoost.Coroutine
Boost.Coroutine
 
Cython ことはじめ
Cython ことはじめCython ことはじめ
Cython ことはじめ
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン
 
Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうか
 
boost tour 1.48.0 all
boost tour 1.48.0 allboost tour 1.48.0 all
boost tour 1.48.0 all
 
C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみた
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.Context
 
競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性
 
NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門
 
llvm入門
llvm入門llvm入門
llvm入門
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案
 
C++11概要 ライブラリ編
C++11概要 ライブラリ編C++11概要 ライブラリ編
C++11概要 ライブラリ編
 
コルーチンの使い方
コルーチンの使い方コルーチンの使い方
コルーチンの使い方
 

Similar a Brief introduction of Boost.ICL

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
競技プログラミングのためのC++入門
競技プログラミングのためのC++入門競技プログラミングのためのC++入門
競技プログラミングのためのC++入門natrium11321
 
.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#信之 岩永
 
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
 
2008.10.18 L4u Tech Talk
2008.10.18 L4u Tech Talk2008.10.18 L4u Tech Talk
2008.10.18 L4u Tech Talkmitamex4u
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputingNoboru Irieda
 
C++コンパイラ GCCとClangからのメッセージをお読みください
C++コンパイラ GCCとClangからのメッセージをお読みくださいC++コンパイラ GCCとClangからのメッセージをお読みください
C++コンパイラ GCCとClangからのメッセージをお読みくださいdigitalghost
 
C++ lecture-1
C++ lecture-1C++ lecture-1
C++ lecture-1sunaemon
 
PL/CUDA - GPU Accelerated In-Database Analytics
PL/CUDA - GPU Accelerated In-Database AnalyticsPL/CUDA - GPU Accelerated In-Database Analytics
PL/CUDA - GPU Accelerated In-Database AnalyticsKohei KaiGai
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPAkira Takahashi
 
最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)Akihiko Matuura
 
C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編道化師 堂華
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)ryos36
 
入出力
入出力入出力
入出力rippro
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Springanyakichi
 

Similar a Brief introduction of Boost.ICL (20)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
競技プログラミングのためのC++入門
競技プログラミングのためのC++入門競技プログラミングのためのC++入門
競技プログラミングのためのC++入門
 
CLR/H No.35-2
CLR/H No.35-2CLR/H No.35-2
CLR/H No.35-2
 
.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#
 
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]
 
2008.10.18 L4u Tech Talk
2008.10.18 L4u Tech Talk2008.10.18 L4u Tech Talk
2008.10.18 L4u Tech Talk
 
Pfi Seminar 2010 1 7
Pfi Seminar 2010 1 7Pfi Seminar 2010 1 7
Pfi Seminar 2010 1 7
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputing
 
C++コンパイラ GCCとClangからのメッセージをお読みください
C++コンパイラ GCCとClangからのメッセージをお読みくださいC++コンパイラ GCCとClangからのメッセージをお読みください
C++コンパイラ GCCとClangからのメッセージをお読みください
 
C++ lecture-1
C++ lecture-1C++ lecture-1
C++ lecture-1
 
PL/CUDA - GPU Accelerated In-Database Analytics
PL/CUDA - GPU Accelerated In-Database AnalyticsPL/CUDA - GPU Accelerated In-Database Analytics
PL/CUDA - GPU Accelerated In-Database Analytics
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JP
 
初めてのSTL
初めてのSTL初めてのSTL
初めてのSTL
 
VerilatorとSystemC
VerilatorとSystemCVerilatorとSystemC
VerilatorとSystemC
 
Slide
SlideSlide
Slide
 
最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)
 
C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)
 
入出力
入出力入出力
入出力
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Spring
 

Más de yak1ex

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
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competitionyak1ex
 
Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]yak1ex
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 
GC in C++0x [eng]
GC in C++0x [eng]GC in C++0x [eng]
GC in C++0x [eng]yak1ex
 
GC in C++0x
GC in C++0xGC in C++0x
GC in C++0xyak1ex
 

Más de yak1ex (7)

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]
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competition
 
Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 
GC in C++0x [eng]
GC in C++0x [eng]GC in C++0x [eng]
GC in C++0x [eng]
 
GC in C++0x
GC in C++0xGC in C++0x
GC in C++0x
 

Brief introduction of Boost.ICL

  • 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 のさわりだけ、というかさわりしか分からない
  • 4. ぼくのかんがえた「ぶーすと」のぶんるい ~1.25 アプリより test graph progress_display たんはココ thread 大規模 小規模 regex crc pool tokenizer random lexical_cast function array rational type_traits timer iterators operators any tuple 実装より
  • 5. ぼくのかんがえた「ぶーすと」のぶんるい ~1.30 アプリより 異次元 preprocessor test spirit date_time graph filesystem progress_display たんはココ thread 大規模 小規模 format regex crc pool tokenizer random lexical_cast function array lambda rational type_traits timer iterators multi_array mpl any optional tuple 実装より
  • 6. ぼくのかんがえた「ぶーすと」のぶんるい ~1.35 アプリより 異次元 preprocessor asio test gil wave spirit date_time graph filesystem progress_display たんはココ statechart thread serialization 大規模 小規模 format program_options interprocess regex crc pool xpressive tokenizer random lexical_cast bimap function multi_index intrusive parameter array lambda range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
  • 7. ぼくのかんがえた「ぶーすと」のぶんるい ~1.40 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph filesystem progress_display たんはココ statechart thread serialization 大規模 小規模 format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
  • 8. ぼくのかんがえた「ぶーすと」のぶんるい ~1.45 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph property_tree filesystem polygon progress_display たんはココ msm statechart thread serialization 大規模 小規模 uuid format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional tuple 実装より
  • 9. ぼくのかんがえた「ぶーすと」のぶんるい ~1.46 アプリより 異次元 preprocessor asio test gil accmulators wave spirit date_time graph property_tree filesystem polygon ICL progress_display たんはココ msm statechart thread serialization 大規模 小規模 uuid format program_options interprocess proto regex crc pool xpressive tokenizer random lexical_cast scope_exit bimap function unordered multi_index intrusive parameter array lambda flyweight range ptr_container fusion variant rational type_traits timer iterators foreach multi_array mpl typeof any optional 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 <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; } #include 含めて 25 行
  • 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; sum += std::make_pair(boost::icl::interval<int>::right_open(s, t), 1); } 今回は数だが集合も可能 右開区間 [s, t) 1 1 + + 1 1 split_interval_map 1 interval_map 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 || (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()); }); // 集計値は second // 区間は first (upper(), lower() で境界値) 集計された区間の結果を iteration 可能なので普通に max_element で最大値取得
  • 15. Interval Container Library 1.46 で導入 開区間、閉区間等全部取り扱い可能 区間に対する集合演算、「集計」が可能 interval_set, interval_map 区間の統合方法として join, separate, split を選択可能 ストリーム出力有り(例:{(1,3][4.6](7,8]}) Traits 用意すれば自前の interval を突っ込むことも可能 数値に限定されないので例えばcotinuous_interval<std::string> w(“a”, “c”) // right_openとか書くと a, b で始まる文字列全部を表すことになる。 Example がいっぱいなのでそれ見ればOK interval_set a interval_set b interval_set a - b