SPOJ

SPOJ SHORTEN 6088 "Sorting points" XYZ_SORT

問題:https://www.spoj.pl/SHORTEN/problems/XYZ_SORT/必死こいて短くしようとしてみたけどそんなに短くならなかったし,元よりこの問題はGo言語受け付けてなかった.思ったよりもsortパッケージがうまく使えなかった.304B package main import."fmt" func…

SPOJ 0450 "Enormous Input Test" INTEST

問題:https://www.spoj.pl/problems/INTEST/Go言語の標準入力について.Go言語で標準入力を受けとる方法はいくつかあるみたい. ・fmtのScanf等を使う ・scannerのScannerを使う ・bufioのReaderを使う ・io/ioutilのReadAllを使う

SPOJ 3700 "Easy Dijkstra Problem" EZDIJKST

問題:http://www.spoj.pl/problems/EZDIJKST/Go言語で書き直してみた. package main import ( "scanner" "os" "strconv" "bufio" "container/vector" "container/heap" ) func run() { for t := next(); t > 0; t-- { g := NewGraph(next()) for k := next…

SPOJ 3916 "Bicolor" BICOLOR

問題:https://www.spoj.pl/problems/BICOLOR/2彩色問題. 隣接する頂点をそれぞれ別の色で塗ることができるグラフかどうかを判定. import java.util.*; // 3916 bicolor BICOLOR public class Main { public static void main(String[] args) throws Exce…

SPOJ 3440 "Enormous Input and Output Test" INOUTEST

問題:https://www.spoj.pl/problems/INOUTEST/巨大な入力に対して巨大な出力をするテスト. 入力は別の問題でテストできるので出力でちょっと試した. 入力:System.inで自作. 出力:PrintWriter(4.39s) System.out(TLE) 出力:PrintWriter 時間:4.39s pu…

SPOJ 6219 "Problem" PROBLEM

問題:https://www.spoj.pl/problems/PROBLEM/解けた.

SPOJ 1872 "Making Book" MKBOOK

問題:https://www.spoj.pl/problems/MKBOOK/

SPOJ 7236 "The next odd number"

問題:https://www.spoj.pl/problems/NEXTODD/100B以内の問題なのでテキトーにTclで. while {![eof stdin]} { gets stdin n puts [expr $n+1+$n%2] }

SPOJ 0442 "Searching the Graph" TDBFS

問題:http://www.spoj.pl/problems/TDBFS/なぜか苦労したので試行の記録をしてみる.

簡単な(典型的な)問題 ※放り込み

降順ソート:https://www.spoj.pl/problems/MEOWIST/ ナップサック問題:https://www.spoj.pl/problems/KNAPSACK/ グリッド探索問題:https://www.spoj.pl/problems/COUNTISL/ マージソート:https://www.spoj.pl/problems/MERGSORT/ グラフ探索DFS・BFS:ht…

SPOJ 42 "Adding Reversed Numbers"

問題:https://www.spoj.pl/problems/ADDREV/Go言語で書き直してみた.けっこうめちゃくちゃな気がする. package main import ( "scanner" "strconv" "os" "fmt" "bytes" "strings" ) func rev(s string) string { buf := bytes.NewBufferString(s).Bytes()…

SPOJ 24 "Small factorials"

問題:https://www.spoj.pl/problems/FCTRL2/ package main import( "scanner" "os" "strconv" "fmt" "big" ) func main() { var s scanner.Scanner s.Init(os.Stdin) s.Scan(); for t,_ := strconv.Atoi(s.TokenText());t>0;t--{ s.Scan() r:=big.NewInt(1)…

SPOJ 1 "Life, the Universe, and Everything"

問題:https://www.spoj.pl/problems/TEST/Go言語を使う練習として. 標準入力をScannerで使ってみた. package main import( "os" "fmt" "scanner" ) func main() { var s scanner.Scanner s.Init(os.Stdin) tok := s.Scan() for tok != scanner.EOF { txt …

SPOJ 4301 "Tables"

問題:https://www.spoj.pl/problems/AE1B/ scan [gets stdin] {%s %s %s} n k s set a [lsort -integer -decreasing [gets stdin]] set m [expr {$k*$s}] set sum 0 for {set c 0} {$sum<$m} {incr c} { incr sum [lindex $a $c] } puts $c

SPOJ 206 "Bitmap"

問題:https://www.spoj.pl/problems/BITMAP/ たぶん合ってるけど遅すぎて通らない. for {gets stdin t} {$t>0} {incr t -1} { #puts [time { if ![expr [string compare [set s [gets stdin]] ""]] then { gets stdin s } scan $s {%s %s} n m set queue […

SPOJ 1112 "Number Steps"

問題:https://www.spoj.pl/problems/NSTEPS/ for {gets stdin t} {$t>0} {incr t -1} { scan [gets stdin] {%d %d} x y if {$x==$y} { set r [expr 2*$y-($y%2?1:0)] } elseif {[expr $x-$y]==2} { set r [expr 2*$y+($y%2?1:2)] } else { set r "No Number…

SPOJ 42 "Adding Reversed Numbers"

問題:https://www.spoj.pl/problems/ADDREV/普通にexprで計算しようとすると頭が0の場合8進数として扱われるのでscanでとった. proc f {a} { join [lreverse [split $a ""]] "" } for {gets stdin t} {$t>0} {incr t -1} { scan [gets stdin] {%s %s} a b…

SPOJ 24 "Small factorial"

問題:https://www.spoj.pl/problems/FCTRL2/ set a(0) 1 for {set i 1} {$i<=100} {incr i} { set a($i) [expr [set a([expr $i - 1])] * $i] } for {gets stdin t} {$t>0} {incr t -1} { puts [set a([gets stdin])] }

SPOJ 400 "To and Fro"

問題:https://www.spoj.pl/problems/TOANDFRO/ while {[set t [gets stdin]]>0} { gets stdin s set r "" for {set i 1} {$i <= $t} {incr i} { set b 0 for {set j $i} {$j <= [string length $s]} {incr j [expr $b?[expr 2*[expr $t-$i]+1]:[expr 2*$i-1…