1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsでiverilog その200

Last updated at Posted at 2025-07-06

概要 

windowsでiverilogやってみた。
練習問題やってみた。

練習問題

atcoderを解け。
ABC 086 C - Traveling
時刻0のとき、平面上の(0, 0)にいます。平面上のN箇所の点を、ある時刻に移動できるかという問題です。

投入するソース

2
3 1 2
6 1 1

期待値

YES

サンプルコード

module test;
	integer stdin = 'h8000_0000;
	integer n,
		a,
		b,
		c,
		ch,
		i,
		j,
		k,
		t,
		p,
		v,
		x,
		y;
	reg [7:0] pc;
	always #1
	begin
		case(pc)
		10:
		begin
			ch = $fscanf(stdin, "%d", n);
			pc <= 20;
		end
		20:
		begin
			p = p + 1;
			ch = $fscanf(stdin, "%d%d%d", t, x, y);
			pc <= 30;
		end
		30:
		begin
			//$display(" %d%d%d", t, x, y);
			pc <= 40;
		end
		40:
		begin
			a = i - t;
			if (a < 0)
				a = a * -1;
			b = j - x;
			if (b < 0)
				b = b * -1;
			c = k - y;
			if (c < 0)
				c = c * -1;
			//$display(" %d%d%d", a, b, c);
			b = b + c;
			if (a < b)
				v = 1;
			a = a % 2;
			b = b % 2;
			if (a != b)
				v = 1;
			i = t;
			j = x;
			k = y;
			pc <= 50;
		end
		50:
		begin
			if (p < n)
			begin
				pc <= 20;
			end
			else
			begin
				pc <= 60;
			end
		end
		60:
		begin
			if (v == 0)
				$write("YES");
			else
				$write("NO");
			pc <= 70;
		end
		70:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		pc <= 10;
		a = 0;
		b = 0;
		c = 0;
		p = 0;
		v = 0;
		i = 0;
		j = 0;
		k = 0;
	end
endmodule





実行結果

>vvp a.out
2
3 1 2
6 1 1
YES

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?