Let's write β

プログラミング中にできたことか、思ったこととか

ICPC

JAG2009 ProblemA

Luck Manipulator (defun next-rand (a b c x) (mod (+ (* a x) b) c)) (defun manip-slot (y-list a b c x) (labels ((%manup-slot (y-list a b c x frm) (cond ((null y-list) ;;前のフレームでゲームが終了していたという事なので (1- frm)) ;;達成不能 (…

JAG2007ProblemD

Square Route (defun read-town (n m) (list (loop for i from 1 upto n collect (read)) (loop for i from 1 upto m collect (read)))) (defun collect-cdr (list) (loop for lst = list then (cdr lst) until (null lst) collect lst)) (defun count-squar…

JAG2010ProblemB

Moonlight Farm (defstruct seed name p a b c d e f s m) (defmethod calc-max-time ((s seed)) (+ (seed-a s) (seed-b s) (seed-c s) (seed-d s) (seed-e s) (loop for i from 1 upto (1- (seed-m s)) sum (+ (seed-d s) (seed-e s))))) (defmethod calc-m…

JAG2010ProblemA

Sum of Consecutive (defun iota (num) (loop for n from 1 upto num collect n)) (defun get-all-pattern (num) (let ((seq (iota (1+ (floor num 2))))) (loop for pat in (loop for i from 0 upto (1- (length seq)) append (loop for j from (+ 2 i) upt…

ICPC2009ProblemB

How Many Island? #include <stdio.h> int filledp(int map[][50],int w, int h) { int i,j; int filledp = 1; for(i = 0; i < h; i++) { for(j = 0; j < w; j++) { if(map[i][j] == 1) { filledp = 0; } } } return filledp; } void mark(int map[][50], int x, int </stdio.h>…

JAG2008 ProblemA

Princess's Gamble (defun ticket (m p votes) (let ((sum-of (* (/ (- 100 p) 100) (* 100 (apply #'+ votes))))) (if (zerop (nth (1- m) votes)) 0 (floor (/ sum-of (nth (1- m) votes)))))) (defun main () (loop for n = (read) for m = (read) for p …

JAG2011 ProblemA

koukyoukoukokukikou (defvar *qwarty-right* (coerce "yuiophjklnm" 'list)) (defvar *qwarty-left* (coerce "qwretasdfgzxcvb" 'list)) (defun count-hand-change (string) (let ((ch-list (coerce string 'list))) (labels ((%count-hand-change (ch-list…

ICPC2011ProblemA

チェビシェフの定理 (defun sieve-of-erathostenes (num) (let ((sieve (make-array num :initial-element 1))) (setf (aref sieve 0) 0) (loop for i from 1 upto (sqrt num) when (= 1 (aref sieve i)) do (loop for j from (1+ i) until (> (* (1+ i) j) …

ICPC2011 ProblemB

ちょっと時間がとれないので簡単な物ですみません。 (defun balancingp (str) (let ((ch-list (coerce str 'list))) (labels ((%balancing-p (ch-list stack) (if (char= #\. (car ch-list)) (null stack) (cond ((or (char= #\[ (car ch-list)) (char= #\( …

PKU Common Subsequence

さき程のコードをつかって PKU Common Subsequence http://poj.org/problem?id=1458 (defun create-lcs-table (i j) (make-array `(,(1+ i) ,(1+ j)))) (defun last1 (sequence) (typecase sequence (string (aref sequence (1- (length sequence)))) (list …

ICPC2005 ProblemF

動的計画法 import java.util.*; public class Gathm { static class Person { int id; List<Integer> freeDays; List<Integer> pieaces; public Person(int id) { this.id = id; this.freeDays = new ArrayList<Integer>(); pieaces = new ArrayList<Integer>(); pieaces.add(id); } void addFre</integer></integer></integer></integer>…

ICPC2006ProblemA

Mysterious Game 破壊的に更新する事になるので、Cでも良いかと。 #include <stdio.h> int main() { int m,n; int map[21][21]; int rbX, rbY; while(1) { scanf("%d",&n); if(n == 0) break; int i; int x,y; //initialize map for(y = 0; y < 21; y++) { for(x = 0;</stdio.h>…

ICPC2005 ProblemC

Numerial Systemです。 (defun num-char-p (char) (when (typep char 'character) (<= (char-code #\0) (char-code char) (char-code #\9)))) (defun num-char-to-num (num-char) (- (char-code num-char) (char-code #\0))) (defun num-to-num-char (num) (…

ICPC2005 ProblemB

Make Purse Light! (defun calc-return (money) (multiple-value-bind (500-yen rem) (floor money 500) (multiple-value-bind (100-yen rem) (floor rem 100) (multiple-value-bind (50-yen rem) (floor rem 50) (multiple-value-bind (10-yen rem) (floor …

ICPC2005 ProblemA

Ohgas' Fortune もちろんLis(ry (defun fukuri (money year nenri tesuuryou) (if (zerop year) money (fukuri (- (+ money (floor (* money nenri))) tesuuryou) (1- year) nenri tesuuryou))) (defun tanri (money year nenri tesuuryou) (labels ((%tanri…

ICPC2004 Problem A

Hanafuda Shuffle もちろんLispで (defun create-deck (num) (loop for card from num downto 1 collect card)) (defun cut (cards p c) (let ((head (loop for idx from 1 upto (1- p) collect (nth (1- idx) cards))) (selected (loop for idx from p upto…

ICPC2012 Problem B

さて、ひきつづき、問題Bです。 こちらも、乱暴な事ができるLispの出番です。 (defun convert-to-zero-filled-str (num len) (format nil "~v,'0,,D" len num)) (defun next-num (num len) (let* ((num-str (convert-to-zero-filled-str num len)) (max-num …

ICPC2012 Problem A

ICPC2012の問題が公開になりました。 http://www.psg.cs.titech.ac.jp/icpc/icpc2012/contest/all_ja.html というわけでLispで解いてみましょう。 さて、ProblemAですが、こんな感じですかね。 (defun calc-year-day (year) (if (zerop (mod year 3)) (* 20 …

ICPC2005 ProblemA

Keitai Message これもまぁ素直な実装ね。再帰でやるのがたのしい (defvar *button-table* '((#\. #\, #\! #\? #\Space) (#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i) (#\j #\k #\l) (#\m #\m #\o) (#\p #\q #\r #\s) (#\t #\u #\v) (#\w #\x #\y #\z))) (def…

僕が働いているAzit.incでは一緒に働けるエンジニアを募集しています!
採用情報 — 株式会社アジット|Azit Inc.