東方算程譚

Oriental Code Talk ── επιστημηが与太をこく、弾幕とは無縁のシロモノ。

目次

Blog 利用状況

ニュース

著作とお薦めの品々は

著作とお薦めの品々は
東方熱帯林へ。

あわせて読みたい

わんくま

  1. 東京勉強会#2
    C++/CLI カクテル・レシピ
  2. 東京勉強会#3
    template vs. generics
  3. 大阪勉強会#6
    C++むかしばなし
  4. 東京勉強会#7
    C++むかしばなし
  5. 東京勉強会#8
    STL/CLRによるGeneric Programming
  6. TechEd 2007 @YOKOHAMA
    C++・C++/CLI・C# 適材適所
  7. 東京勉強会#14
    Making of BOF
  8. 東京勉強会#15
    状態遷移
  9. 名古屋勉強会#2
    WinUnit - お気楽お手軽UnitTest

CodeZine

  1. Cで実現する「ぷちオブジェクト指向」
  2. CUnitによるテスト駆動開発
  3. SQLiteで組み込みDB体験(2007年版)
  4. C++/CLIによるCライブラリの.NET化
  5. C# 1.1からC# 3.0まで~言語仕様の進化
  6. BoostでC++0xのライブラリ「TR1」を先取りしよう (1)
  7. BoostでC++0xのライブラリ「TR1」を先取りしよう (2)
  8. BoostでC++0xのライブラリ「TR1」を先取りしよう (3)
  9. BoostでC++0xのライブラリ「TR1」を先取りしよう (4)
  10. BoostでC++0xのライブラリ「TR1」を先取りしよう (5)
  11. C/C++に対応した、もうひとつのUnitTestFramework ─ WinUnit
  12. SQLiteで"おこづかいちょう"
  13. STL/CLRツアーガイド
  14. マージ・ソート : 巨大データのソート法
  15. ヒープソートのアルゴリズム
  16. C++0xの新機能「ラムダ式」を次期Visual Studioでいち早く試す
  17. .NETでマンデルブロ集合を描く
  18. .NETでマンデルブロ集合を描く(後日談)
  19. C++/CLI : とある文字列の相互変換(コンバージョン)
  20. インテルTBBによる選択ソートの高速化
  21. インテルTBB3.0 によるパイプライン処理
  22. Visual C++ 2010に追加されたSTLアルゴリズム
  23. Visual C++ 2010に追加されたSTLコンテナ「forward_list」
  24. shared_ptrによるObserverパターンの実装
  25. .NETでマンデルブロ集合を描く(番外編) ── OpenCLで超並列コンピューティング
  26. StateパターンでCSVを読む
  27. 状態遷移表からStateパターンを自動生成する
  28. 「ソートも、サーチも、あるんだよ」~標準C++ライブラリにみるアルゴリズムの面白さ
  29. インテルTBBの同期メカニズム
  30. なぜsetを使っちゃいけないの?
  31. WPFアプリケーションで腕試し ~C++でもWPFアプリを
  32. C++11 : スレッド・ライブラリひとめぐり
  33. Google製のC++ Unit Test Framework「Google Test」を使ってみる
  34. メールでデータベースを更新するココロミ
  35. Visitorパターンで遊んでみたよ
  36. Collection 2題:「WPFにバインドできる辞書」と「重複を許す検索set」
  37. Visual C++ 2012:stateless-lambdaとSQLiteのぷち拡張
  38. 「Visual C++ Compiler November 2012 CTP」で追加された6つの新機能

@IT

  1. Vista時代のVisual C++の流儀(前編)Vista到来。既存C/C++資産の.NET化を始めよう!
  2. Vista時代のVisual C++の流儀(中編)MFCから.NETへの実践的移行計画
  3. Vista時代のVisual C++の流儀(後編) STL/CLRによるDocument/Viewアーキテクチャ
  4. C++開発者のための単体テスト入門 第1回 C++開発者の皆さん。テスト、ちゃんとしていますか?
  5. C++開発者のための単体テスト入門 第2回 C++アプリケーションの効率的なテスト手法(CppUnit編)
  6. C++開発者のための単体テスト入門 第3回 C++アプリケーションの効率的なテスト手法(NUnit編)

AWARDS


Microsoft MVP
for Visual Developer - Visual C++


Wankuma MVP
for いぢわる C++


Nyantora MVP
for こくまろ中国茶

Xbox

Links

記事カテゴリ

書庫

日記カテゴリ

渡る者の途絶えた橋 (C#/LINQ版)

えとー、こんなもんかの。

#define SET_3

using System;
using System.Collections.Generic;
using System.Linq;

namespace DAG {
  struct bridge {
    public char fr;
    public char to;
    public bridge(char f, char t) { fr = f; to = t; }
  }

  class Program
  {
      static void Main() {
      List<bridge> path = new List<bridge>
#if SET_1
      {
        new bridge('A','B'),
        new bridge('B','C'),
        new bridge('A','C'),
        new bridge('A','D'),
        new bridge('C','D'),
      };
#elif SET_2
      {
        new bridge('A','B'),
        new bridge('A','C'),
        new bridge('B','C'),
        new bridge('B','D'),
        new bridge('D','A'),
        new bridge('D','C'),
      };
#elif SET_3
      {
        new bridge('A','B'),
        new bridge('B','C'),
        new bridge('C','D'),
        new bridge('D','E'),
        new bridge('E','F'),
        new bridge('F','G'),
        new bridge('G','H'),
        new bridge('H','F'),
      };
#endif
      while ( true ) {
        // 表示
        path.ForEach(item => Console.WriteLine("{0}->{1}", item.fr, item.to));
        Console.WriteLine();
        // 入口/出口セットを作る
        var froms = (from item in path select item.fr).Distinct();
        var tos   = (from item in path select item.to).Distinct();
        // 入口/出口セットの一方にあって他方にないものをremoveに
        // symmetrc-diference に相当するもんがなさげな
んで"X-Y と Y-X の和集合"で代用
     var remove = Enumerable.Union(froms.Except(tos), tos.Except(froms));
        if ( remove.Count() == 0 ) break;
        // removeに含まれない橋を抽出する
        path = (from item in path
                where !(remove.Contains(item.fr) || remove.Contains(item.to))
                select item).ToList();
      }
      Console.WriteLine(path.Count() == 0 ? "DAG!!" : "cyclic!!");
    }
  }
}

投稿日時 : 2011年1月28日 22:58

コメントを追加

# re: 渡る者の途絶えた橋 (C#/LINQ版) 2011/01/28 23:36 επιστημη

とりこびっちの反応が楽しみではあるwww

ところで素でわからんのだが、DB上に

CREATE TABLE Bridge (
fr INTEGER,
to INTEGER
)

でこさえられた集合に対して同様の操作をSQLでどう書けばいいのん?
おしえてえらいひと。

# re: 渡る者の途絶えた橋 (C#/LINQ版) 2011/01/29 13:26 泥爺

通りすがりです。
おもしろそうなので自分もlinqで書いてみました。

int count = int.MaxValue;
while (count > path.Count)
{
count = path.Count;
path = path.Where(p1 => path.Any(p2 => p2.fr== p1.to) &&
path.Any(p2 => p2.to== p1.fr)).ToList();
}
Console.WriteLine(path.Count == 0 ? "DAG!!" : "cyclic!!");

# re: 渡る者の途絶えた橋 (C#/LINQ版) 2011/01/29 13:35 επιστημη

あ、なるほどぉー…

# 
Twitter Trackbacks for

??????????????????????????? (C#/LINQ???)
[wankuma.com]
on Topsy.com
2011/01/31 13:04 Pingback/TrackBack


Twitter Trackbacks for

??????????????????????????? (C#/LINQ???)
[wankuma.com]
on Topsy.com

# qnBNBLLfmb 2014/07/19 6:38 http://crorkz.com/

tPi8CO I truly appreciate this blog article. Awesome.

# WgVdeNoPsnqwoeYdLD 2014/08/07 11:06 http://crorkz.com/

bCM9at Thanks a lot for the article post.Much thanks again. Keep writing.

# eyoCVIhmAayNmJWlCva 2014/08/29 7:11 http://podle.pl/

Very well written article. It will be useful to anybody who usess it, as well as myself. Keep doing what you are doing - i will definitely read more posts.

# dpnsWfojjPphvSUkAa 2014/09/09 21:04 http://www.designingdigitally.com

you have got an important weblog right here! would you wish to make some invite posts on my weblog?

# mLJbUIBknDnV 2014/09/11 20:10 http://www.ukessays.com

Very good written information. It will be helpful to everyone who utilizes it, including myself. Keep doing what you are doing - looking forward to more posts.

# dImuSoaTZvTsswGZE 2014/09/14 19:29 http://www.distanceentredeuxvilles.com/

I've learn several good stuff here. Certainly worth bookmarking for revisiting. I wonder how a lot attempt you set to create any such fantastic informative website.

# GOvoChABXOwJZue 2014/09/17 15:53 http://www.1818-888.com

I am usually to running a blog and i really recognize your content. The article has actually peaks my interest. I'm going to bookmark your web site and maintain checking for brand new information.

# ylxSYQKqDoLlCiBjeP 2014/09/17 17:37 https://local.amazon.com/south-orange-county/B00NF

Thanks for some other fantastic post. Where else may anybody get that type of information in such a perfect way of writing? I've a presentation next week, and I'm on the look for such info.

# This web site trᥙly has all of the іnformation ɑnd faϲts I ᴡanted about thіs subject and diɗn't know who tο ɑsk. 2017/12/14 23:22 Thiѕ web site truⅼy һas all of thе informatіоn and

Thi? web site truly hhas al? of the information and facts I wаnted aout this subject аnd didn't know who
to аsk.

# 渡る者の途絶えた橋 (C#/LINQ版) 2017/12/15 0:51 An outstanding share! І һave jist forwarded tһis

Αn outstanding share! ? ?ave j?st forwarded th?s onto a co-worker
w?o ?as been doing a little homework on th?s. And he actually bought
me lunch bec?usе I discovered it for him...
lol. S? let me reword t?is.... ?hank YOU fоr the meal!!
But yeah, t?anks for spending thе tiime tto discuss t??s subject herе on y?ur website.

# 渡る者の途絶えた橋 (C#/LINQ版) 2017/12/15 2:15 Its likе yoᥙ read my mind! You appear tо know ѕo

Its like youu read myy mind! Y?u aрpear t? кnow so much
about th?s, ?ike you wrote tthe book in ?t or s?mething.
I think that уou cou?d do with some pics tо drive the message home a little bit, but instead of t??t, this is fantastic blog.
A ?reat re?d. I'll ?efinitely bе back.

タイトル
名前
URL
コメント