一日一プロ

二分探索 using System; using System.Collections.Generic; namespace BinarySearch { class MainClass { public static void Main (string[] args) { Console.WriteLine ("Target:"); int target = int.Parse (Console.ReadLine ()); Console.WriteLine ("…

一日一プロ

リニアサーチ(番兵つき) using System; using System.Collections.Generic; namespace LinerSearch { class MainClass { public static void Main (string[] args) { Console.WriteLine ("target:"); int target = int.Parse (Console.ReadLine ()); Console…

一日一プロ

水たまり using System; using System.Collections.Generic; namespace Rainy { class MainClass { public class Data_B { public int left_p = 0; public int area = 0; public Data_B(int p, int a){ left_p = p; area = a; } } public static List<int> stackA</int>…

一日一プロ

キュー 擬似タスクスケジューリング using System; using System.Collections.Generic; namespace queue { class MainClass { public class Process { public string name; public int time; public Process(){ name = "ERROR"; time = 0; } public Process(…

一日一プロ

逆ポーランド記法 スタック練習 using System; using System.Collections.Generic; namespace stack { class MainClass { public const int ERROR = 0xFFFF; public static List<int> stack = new List<int> (); public static void Main (string[] args) { //入力 str</int></int>…

一日一プロ

シェルソート あらかじめソートしておき、挿入ソートでの計算回数を少なくする。 using System; using System.Collections.Generic; namespace ShellSort { class MainClass { public static void Main (string[] args) { int mode = 0; int gMax = 0; Conso…

一日一プロ

using System; namespace atcoder { class MainClass { public static void Main (string[] args) { int s, e,sum; sum = 0; for (int i = 0; i < 3; i++) { string[] str = Console.ReadLine ().Split (' '); s = int.Parse (str [0]); e = int.Parse (str …

一日一プロ

using System; using System.Collections.Generic; namespace atcoder3 { public struct iseki { public int l, r, s; } class MainClass { public static void Main (string[] args) { var list = new List<iseki>(); //Input string[] str = Console.ReadLine ().</iseki>…

一日一プロ

ソートの安定性 バブルソートと選択ソート using System; using System.Collections.Generic; namespace StalbeSort { class MainClass { public static void Main (string[] args) { int N; List<int> data = new List<int>(); N = int.Parse(Console.ReadLine ()); f</int></int>…

一日一プロ

SRM652 250 class ValueOfString { public int findValue(string s) { int moji = (int)'a'; int count = 0; int total = 0; for(int i=moji; i<(moji+26); i++){ string tmp = s; int i_tmp = 0; i_tmp = s.Length - tmp.Replace(((char)i).ToString(), "")…

一日一プロ

挿入ソート C++ #include <iostream> #include <vector> using namespace std; int main(int argc, const char * argv[]) { int n; vector<int> data; cin >> n; for(int i=0; i < n; i++){ int tmp; cin >> tmp; data.push_back(tmp); } for(int i=1; i<n; i++){ int v = data[i]; int j = i-1; while( (j >= 0) && (data[j] > …</n;></int></vector></iostream>

一日一プロ

アルゴリズムとデータ構造 問題 n個の数字R0〜Rn-1が与えられる。 Rj - Ri (i using System; using System.Collections.Generic; namespace MaximumProfit { class MainClass { const int MaximumProfit = 200000; public static void Main (string[] args) …

よく使いそうなコードまとめ(4)

動的配列 List using System.Collections.Generic; var R = new List<int>(); /*宣言 */ R.Add(int.Parse (Console.ReadLine ())); /* 要素追加 */ Console.WriteLine ("{0}", R[0]); /* 要素抽出 */ 定数定義 const int DEFINE 5 Max, Min関数 Math.Max( A, B );</int>…

C#でプロコン入力

C#

C#の標準入力処理 /* 標準入力より' 'で分割しstr配列へ格納 */ string[] str = Console.ReadLine ().Split (' '); /* 1番目の要素をint型に変換しNへ格納 */ int N = int.Parse (str [0]); /* 2番目の要素をint型に変換しMへ格納 */ int M = int.Parse (str…

Unityボードゲーム開発日誌 x日目

Unityでボードゲームを作る (いつから始めたかわからないからx日目) 目標 戦略ゲームっぽく 単純なボードゲームは作ってあったので、もう少し戦略ゲームっぽく修正します。 仕様はのちのち。 オフラインゲームっぽく オフラインでボードゲームをわいわい楽し…

はじめてのHaskell(9)

catn main = do cs <- getContents putStr $ numbering cs numbering :: String -> String numbering cs = unlines $ map format $ zipLineNumber $ lines cs zipLineNumber :: [String] -> [(Int, String)] zipLineNumber xs = zip [1..] xs format :: (Int…

はじめてのHaskell(8)

クイックソート import List main = print $ qsort [3,4,1,8,2,6,5] qsort :: [Int] -> [Int] qsort [] = [] qsort (p:xs) = qsort lt ++ [p] ++ qsort gteq where lt = [x | x <- xs, x < p] gteq = [x | x <- xs, x >= p] 関数 関数 概要 ++ (++)::[a] -> …

たらい回し関数

たらい回し関数 竹内関数。ベンチマークに使われる。 それ以外に特に用途は無いらしい。 tarai(x, y, z){ if (x <= y) return y; else tarai(tarai( x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)); }

はじめてのHaskell(7)

練習問題 countbyte.hs main = do cs <- getContents print $ countByte cs countByte cs = length cs countwords.hs main = do cs <- getContents print $ countWords cs countWords cs = length $ words cs swap.hs main = do cs <- getContents putStr $ …

はじめてのHaskell(6)

grepコマンド 関数 関数 概要 head リストの最初の要素を返す:[a]->a tail 最初の要素をのぞいたリストを返す:[a]->[a] filter リストの要素のうち、f x がTrueである要素を集めたリストを返す: filter::(a -> Bool) -> [a] -> [a] any リストの各要素に…

はじめてのHaskell(5)

echoコマンド作成 import 公開されるモジュールの型や関数を使えるようにする。 Systemモジュール 関数 関数名 概要 getArgs コマンドライン引数を取得する -- getArgs :: IO[string] Mainモジュール Preludeモジュール 関数 関数名 概要 unwords 文字列のリ…

はじめてのHaskell(4)

expand.hs ver2 パターンマッチ 関数の引数に文字リテラルや整数リテラルを指定することで、その値にマッチするときだけ、 関数を実行することができる。 例: Func 't' = xxxx Func 'c' = yyyy Func a = zzzz 't'にマッチしたとき、xxxxを行う。 'c'にマッ…

はじめてのHaskell(3)

expand.hs ver.0 if文 if 条件式 then 式1 else 式2 関数 関数 概要 (==) a->a->Bool: x==y (xとyの"内容"が等しいときTrueを返す) main = do cs <- getContents putStr $ expand cs expand :: String -> String expand cs = map translate cs translate :: …

はじめてのHaskell(2)

関数の型 String -> [String] 関数の第一引数の型:String 関数の返り値の型:[String]第一引数の型 -> 第二引数の型 -> .... -> 返り値の型 型変換 [a] -> Int [a]:多相型(どんな型と置き換えても良い) 型の宣言 firstNLines :: Int -> String -> String ..…

Haskell入門

標準出力 main = putStrLn "Hello, World!" アクション アクション 概要 main mainアクション 関数 関数名 概要 putStrLn 文字列と改行を標準出力する catコマンド main = do cs <- getContents putStr cs アクション アクション 概要 getContents 標準入力…

配列要素の回転

配列要素の回転 目的 配列の要素を循環させながらシフトさせたい。 例) a[10] = {0,1,2,3,4,5,6,7,8,9} 4だけシフト ▶︎{4,5,6,7,8,9,0,1,2,3} 解法 a : 配列の先頭から、シフト数分の要素の集合 b : a集合以外の要素の集合 とする。 例)arr[10] 4シフト a :…

CEDEC AI CHALLENGE 2014 まとめ(Part4 結果)

結果 予選2位で終わりでした。 得点がマイナス方向にいかなかったのはよかった。たまたまです。 戦略 多くの選手がモンテカルロによる方法を選択していることに驚いた。 全パターンを探索し、期待値が高い割当を行うという方法がセオリーかと思っていた。 …

CEDEC AI CHALLENGE 2014 まとめ(Part3 提出コード)

提出コード 環境 実装はC#で行った。 (とくに理由は無く、topcoderで最近お世話になっている為) 言い訳 予選コード、決勝コードともに1日で仕上げたため、 ほとんど直値でコメント無しという状態。 なのですぐ見て分かるように(自分が)以下に簡単な流れを示…

CEDEC AI CHALLENGE 2014 まとめ(Part2 戦略)

戦略 大まかな戦略 ・公開されている情報から相手の動きを予測する(期待値計算に使用)。 ・対戦サーバーに公開される対戦ログを参考にする。 ・熱狂度の配分により、目標値を設定する。 ・乱択アルゴリズム(モンテカルロ)に頼る。 ただし、予測や配分などに…

CEDEC AI CHALLENGE 2014 まとめ(Part1 ルール)

ルール概要 恋愛シミュレーションゲームのAI をつくる。 最も女の子に好かれるAIを作ることを目的とする。 ルール詳細 プレイヤーは4人、対象の女の子は8人。 プレイヤーはターン中にデートをすることにより女の子の"好感度"を上げていく。 ターン 1ゲー…