夢追い人

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

0031,0045,0047,0055,0057,0060

なんか全部解説するのは面倒だ。

0031

貪欲

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
typedef vector<int> vi;

const int w[] = {9,8,7,6,5,4,3,2,1,0};

int main() {
	int in;
	while (cin>>in) {
		vi used;
		REP(i,10) {
			int weight = pow(2,w[i]);
			if (weight<=in) {
				in -= weight;
				used.push_back(weight);
			}
		}
		sort(used.begin(),used.end());
		REP(i,used.size()) {
			if(i!=0) cout<<" ";
			cout<<used[i];
		}
		cout<<endl;
	}
}

0045

なんだか

#include <cstdio>
using namespace std;
int main() {
	int amt=0,qut=0,cnt=0,a,b;
	while (scanf("%d,%d",&a,&b)!=EOF) {
		amt += a*b;
		qut += b;
		cnt++;
	}
	int res = qut/cnt;
	double dec = (double)qut/(double)cnt-res;
	if (dec>=0.5) res+=1;
	printf("%d\n%d\n",amt,res);
}

0047

やるだけ

#include <cstdio>
using namespace std;
int main() {
	char from,to,ball='A';
	while (scanf("%c,%c",&from,&to)!=EOF) {
		if (ball==from) {
			ball=to;
		} else if (ball==to) {
			ball=from;
		}
	}
	printf("%c\n",ball);
}

0055

とりあえず

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	double a;
	while (cin>>a) {
		double s[10], res=a;
		s[0]=a;
		for (int i=1; i<10; i++) {
			if (i%2==0) {
				s[i]=s[i-1]/3.0;
			} else {
				s[i]=s[i-1]*2.0;
			}
			res+=s[i];
		}
		printf("%.8f\n",res);
	}
}

0057

平面 分割でぐぐる⇒漸化式みつける

#include <iostream>
using namespace std;
int main() {
	int n;
	while(cin>>n) {
		int l[10001];
		l[0] = 2;
		for (int i=1;i<n;i++) {
			l[i]=l[i-1]+i+1;
		}
		cout << l[n-1] << endl;
	}
}

0060

#include <iostream>
#include <vector>
using namespace std;
int main() {
	int a,b,c;
	while (cin>>a>>b>>c) {
		int sum=a+b;
		vector<int> flag(10,0);
		flag[a-1]=flag[b-1]=flag[c-1]=1;
		int cnt=0;
		for (int i=0; i<20-sum; i++) {
			if (flag[i]==0) {
				cnt++;
			}
		}
		if (cnt/7.0>=0.5) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
}

AOJ

botの誘導が神。

広告を非表示にする