夢追い人

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

0024~0028

Codeforcesの前にやってたやつです。

0024

ガラス玉が割れる速度からガラス玉がわれる高さ(建物の階数)を求める。
物理の問題。

#include <iostream>
#include <cmath>

using namespace std;

int main() {
	double v;
	while (cin >> v){
		double t = v/9.8;
		double y = 4.9*pow(t,2);
		int N;
		for (N=1;;N++) {
			if (5*N-5>=y) break;
		}
		cout << N << endl;
	}
}

0025

hit&blowのhitとblowを求める問題。
何かを間違えてて最初は通らなかった。

#include <iostream>

using namespace std;

int main() {
	int a[4],b[4];
	while (cin>>a[0]>>a[1]>>a[2]>>a[3]) {
		cin>>b[0]>>b[1]>>b[2]>>b[3];
		int hit=0, blow=0;
		for (int i=0; i<4; i++) {
			for (int j=0; j<4; j++) {
				if (i==j&&a[i]==b[j]) hit++;
				else if (a[i]==b[j]) blow++;
			}
		}
		cout << hit << " " << blow << endl;
	}
}

0026

大中小の水滴をある座標に落としていったとき、濡れなかったところと、最大の濃さを調べるみたいなの。
コメントアウトが俺、それ以外がネットから。
同じコードのはずなのに俺はWA、ネットはAC。なぜだかは未だ不明。

#include <cstdio>

using namespace std;

int main() {
	/*
	int p[10][10];
	for (int i=0; i<10; i++) {
		for (int j=0; j<10; j++) {
			p[i][j] = 0;
		}
	}
	int x,y,size;
	int dx[] = { 0, 0,-1, 1,-1,-1, 1, 1, 0, 0,-2, 2};
	int dy[] = {-1, 1, 0, 0,-1, 1,-1, 1,-2, 2, 0, 0};
	while (scanf("%d,%d,%d", &x, &y, &size)!=EOF) {
		p[x][y]++;
		for (int i=0; i<size*4; i++) {
			int mx=x+dx[i];
			int my=x+dy[i];
			if (mx>=0&&mx<10&&my>=0&&my<10) {
				p[mx][my]++;
			}
		}
	}
	int c=0,m=0;
	for (int i=0; i<10; i++) {
		for (int j=0; j<10; j++) {
			if (p[i][j] == 0) {
				c++;
			} else if (p[i][j]>m) {
				m=p[i][j];
			}
		}
	}
	printf("%d\n%d\n",c,m);
	return 0;
	*/
		int map[10][10],ink,x,y,max=0,count=0;
	int dx[] = { 0, 0,-1, 1,-1,-1, 1, 1, 0, 0,-2, 2};
	int dy[] = {-1, 1, 0, 0,-1, 1,-1, 1,-2, 2, 0, 0};

	for(int i=0 ; i<10 ; i++){
		for(int j=0 ; j<10 ; j++){
			map[i][j] = 0;
		}
	}
	while( scanf("%d,%d,%d", &x, &y, &ink) != EOF ){
		map[y][x]++;
		for(int i=0 ; i<ink*4 ; i++){
			int mx = x + dx[i];
			int my = y + dy[i];
			if(mx>=0 && mx<10 && my>=0 && my<10){
				map[my][mx]++;
			}
		}
	}
	for(int y=0 ; y<10 ; y++){
		for(int x=0 ; x<10 ; x++){
			if(map[y][x]==0){
				count++;
			}
			if(map[y][x]>max){
				max = map[y][x];
			}
		}
	}
	printf("%d\n%d\n", count , max);
}

0027

与えられた日付の曜日を求める問題。2004年なので閏年。

#include <iostream>
#include <string>

using namespace std;

// 1-31 2-29 3-31 4-30 5-31 6-30 7-31 8-31 9-30 10-31 11-30 12-31

int main() {
	int mon, day;
	int month[] = {31,29,31,30,31,30,31,31,30,31,30,31};
	string days[] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
	while (cin >> mon >> day && mon != 0) {
		int pass=0;
		if (mon==1) {
			cout << days[(day-1)%7] << endl;
			continue;
		}
		for (int i=0; i<mon-1; i++) {
			pass += month[i];
		}
		pass += day;
		cout << days[(pass-1)%7] << endl;
	}
	return 0;
}

ずっと最後のpassをdayにしててあわないなぁと思ってた(;´Д`)

0028

あたえられたアルファベットの濃度が最大であるアルファベットを求める問題。
mapとかsetとか色々つかったりしたけど結局pairに落ち着いた。

#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	pair<int,int> num[100];
	for (int i=0; i<100; i++) {
		num[i].first = 0;
		num[i].second = i+1;
	}
	int n;
	while (cin >> n) {
		num[n-1].first++;
	}
	sort(num, num+100);
	reverse(num, num+100);
	int max=num[0].first;
	vector<int> maxs;
	maxs.push_back(num[0].second);
	for (int i=1; i<100; i++) {
		if (max==num[i].first) {
			maxs.push_back(num[i].second);
		} else {
			break;
		}
	}
	sort(maxs.begin(), maxs.end());
	for (int i=0; i<maxs.size(); i++) {
		cout << maxs[i] << endl;
	}
}

じゃあ腰をすえてCodeChefやってきます。