読者です 読者をやめる 読者になる 読者になる

夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

PKUできたゆたさん越え

1656

やるだけ

#include <cstdio>
#include <cstring>

int board[100][100];

void fill(int x, int y, int L, int c) {
	for (int i=y; i<y+L; i++) for (int j=x; j<x+L; j++) board[i][j] = c;
}

int main() {
	for (int i=0; i<100; i++) for (int j=0; j<100; j++) board[i][j] = 0;
	int t,x,y,L; scanf("%d",&t);
	char com[32];
	for (int ix=0; ix<t; ix++) {
		scanf("%s%d%d%d",com,&x,&y,&L);
		x--; y--;
		if (strcmp(com,"WHITE")==0) {
			fill(x,y,L,0);
		} else if (strcmp(com,"BLACK")==0) {
			fill(x,y,L,1);
		} else {
			int res = 0;
			for (int i=y; i<y+L; i++) for (int j=x; j<x+L; j++)
				if (board[i][j] == 1) res++;
			printf("%d\n",res);
		}
	}
}

1503

Javaゲー

import java.util.*;
import java.math.*;
import java.math.BigInteger.*;

class Main {
	public static void main(String[] args) {
		Scanner std = new Scanner(System.in);
		BigInteger N, sum;
		sum = new BigInteger("0");
		while (true) {
			N = std.nextBigInteger();
			if (N.compareTo(new BigInteger("0"))==0) break;
			sum = sum.add(N);
			// System.out.println(sum+" "+N);
		}
		System.out.println(sum);
	}
}

1663

規則性を見つけて完了

#include <cstdio>

int main() {
	int N, x, y;
	scanf("%d", &N);
	for (int ix=0; ix<N; ix++) {
		scanf("%d%d",&x,&y);
		if (!(x==y)&&!(x-y==2)) {
			printf("No Number\n");
			continue;
		}
		int res = 0;
		if (x == y) {
			for (int i=0; i<x; i++) {
				if (i%2 == 0) res++;
				else res += 3;
			}
		} else {
			res = 2;
			for (int i=0; i<x-2; i++) {
				if (i%2 == 0) res++;
				else res += 3;
			}
		}
		printf("%d\n", res);
	}
}

1088

dp + dfs

#include <cstdio>
#include <algorithm>
using namespace std;

int R, C;
int map[100][100], dp[100][100];
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

int dfs(int x, int y, int cnt) {
	cnt++;
	int res = cnt;
	for (int i=0; i<4; i++) {
		int nx = dx[i]+x;
		int ny = dy[i]+y;
		if (nx<R&&nx>=0&&ny<C&&ny>=0&&map[nx][ny]<map[x][y]) {
			// printf("%d %d\n", map[nx][ny], map[x][y]);
			if (dp[nx][ny]!=-1) {
				res = max(res, cnt+dp[nx][ny]);
			} else {
				res = max(res, dfs(nx, ny, cnt));
			}
		}
	}
	return res;
}

int main() {
	scanf("%d%d", &R, &C);
	for (int i=0; i<R; i++) {
		for (int j=0; j<C; j++) {
			scanf("%d", &map[i][j]);
			dp[i][j] = -1;
		}
	}
	int res = -1;
	for (int i=0; i<R; i++) {
		for (int j=0; j<C; j++) {
			dp[i][j] = dfs(i, j, 0);
			res = max(res, dp[i][j]);
		}
	}
	// for (int i=0; i<R; i++) {
		// for (int j=0; j<C; j++) printf("%d ", dp[i][j]);
		// printf("\n");
	// }
	printf("%d\n", res);
}

1978

シュミレーションするだけ
デッキが降順なのに注意

#include <cstdio>
#include <cstring>

int main() {
	int n, r, p, c;
	while (scanf("%d%d", &n, &r)) {
		if (n == 0 && r == 0) break;
		int deck[n];
		for (int i=0; i<n; i++) deck[i] = n - i;
		for (int ix=0; ix<r; ix++) {
			scanf("%d%d", &p, &c);
			int temp[n];
			memcpy(temp, deck, sizeof(deck));
			for (int i=0; i<p-1; i++) {
				temp[i+c] = deck[i];
			}
			for (int i=p-1; i<p+c-1; i++) {
				temp[i-p+1] = deck[i];
			}
			memcpy(deck, temp, sizeof(temp));
			// for (int i=0; i<n; i++) printf("%d ", deck[i]);
			// printf("\n");
		}
		printf("%d\n", deck[0]);
	}
	return 0;
}

ascenticism

notepad++が使いやすい

広告を非表示にする