夢追い人

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

ログ

一応ログ

CC-TEST

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	vector<int> n;
	int tmp;
	while (scanf("%d", &tmp) != EOF) {
		n.push_back(tmp);
	}
	for (int i=0; i<n.size(); i++) {
		if (n[i] == 42) break;
		cout << n[i] << endl;
	}
	return 0;
}

CC-HS08TEST

import java.util.*;

class atm {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		double y = stdIn.nextDouble();
		double tmp = y-x-0.5;
		if (y-x >= 0.5 && x%5 == 0) {
			System.out.printf("%.2f\n",tmp);
		} else {
			System.out.printf("%.2f\n",y);
		}
	}
}

PKU-1005

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

bool ok(double x, double y, int year) {
	const double PI=3.1415926535897932384626433832795;
	double mile = 100*year;
	double R2 = mile/PI;
	if (pow(x,2)+pow(y,2)<R2) return false;
	return true;
}

int solve(double x, double y) {
	int ans;
	for (int i=1;;i++) {
		if (!ok(x,y,i)) {
			ans = i;
			break;
		}
	}
	return ans;
}

int main() {
	int N; cin >> N;
	double x, y;
	for (int i=0; i<N; i++) {
		cin >> x >> y;
		int ans = solve(x,y);
		cout << "Property " << i+1 << ": This property will begin eroding in year " << ans << "." << endl;
	}
	cout << "END OF OUTPUT." << endl;
}

PKU-1006

カンニング
コメントアウトが俺の答え。一年のはじめからd+21252日までカウントしなきゃいけないのに忘れてる。

#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

/*int solve(int p, int e, int i, int d) {
	const int P=23, E=28, I=33;
	int j;
	/*while (p>d) {
		p-=P;
		if (p<0) {
			p+=P;
			break;
		}
	}
	while (e>d) {
		e-=E;
		if (e<0) {
			e+=E;
			break;
		}
	}
	while (i>d) {
		i-=I;
		if (i<0) {
			i+=I;
			break;
		}
	}
	p%=P; e%=E; i%=I;
	if (p==e&&e==i&&p>d) {
		p-=d;
	} else {
		while (p<=21252) {
			if (p==min(p,min(e,i))) p+=P;
			if (p==e&&e==i&&p>d) {
				p-=d;
				break;
			}
			if (e==min(p,min(e,i))) e+=E;
			if (p==e&&e==i&&p>d) {
				p-=d;
				break;
			}
			if (i==min(p,min(e,i))) i+=I;
			if (p==e&&e==i&&p>d) {
				p-=d;
				break;
			}
		}
	}
	return p;
}
*/
int main() {
	int p,e,i,d;
	int c = 1;
	while (true) {
		cin >> p >> e >> i >> d;
		if (p==-1&&e==-1&&i==-1&&d==-1) break;
		for (int j=1; j<=21252; j++) {
			if ((j+d-p)%23==0&&(j+d-e)%28==0&&(j+d-i)%33==0) {
				printf("Case %d: the next triple peak occurs in %d days.\n",c,j);
				break;
			}
		}
		//int ans = solve(p,e,i,d);
		//printf("Case %d: the next triple peak occurs in %d days.\n",c,ans);
		c++;
	}
	return 0;
}

問題は各サイトで。とりあえず問題たくさん解けるように頑張ります。