0
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?

More than 5 years have passed since last update.

at coder beginner 026

Last updated at Posted at 2018-09-22

B
高橋君は、丸が大好きです。今日も、原点を中心とした大きさの違う円を N 個書きました。
その円の集合に対し、外側から赤白交互に色を塗ったとき、赤く塗られる部分の面積を出力しなさい

# include<iostream>
# include<algorithm>
# include<iomanip>
using namespace std;
static const double pi = 3.141592653589793;
int main() {
	int N;
	int R[1010];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> R[i];
	}
	sort(R, R + N,greater<int>());
	double count = 0;
	for (int i = 0; i < N; i+=1) {
		if (i % 2 == 0)
			count += R[i] * R[i];
		else
			count -= R[i] * R[i];
	}
	cout <<fixed<<setprecision(7)<<count*pi << endl;
	return 0;
}

全然通らねーーとか思ってたら小数点以下の扱いがなってなかったっぽい。

をインクルードしてcout<<fixedで小数部の桁数をより正確に指定できる。<<setprecision(N)で、小数点以下N桁まで出力する。
(2)<<3.141;//"3.14"

C

# include <iostream>
# include<vector>
# include<algorithm>
using namespace std;
using ll = long long;
const int INF = 1e9;
int main() {
	int N;
	cin >> N;
	vector<int>flag[21];//部下の社員番号を保有する
	for (int i = 2; i <= N; ++i) {
		int b;
		cin >> b;
		flag[b-1].push_back(i-1);
	}
	vector<int>cost(N);//社員の給料
	for (int i = N-1; i >= 0; --i) {
		if (flag[i].size() == 0) {
			cost[i] = 1;
			continue;
		}
		else{
			int max_cost = 0;
			int min_cost = INF;
			for (int j = 0; j < flag[i].size(); ++j) {
				max_cost = max(max_cost, cost[flag[i][j]]);
				min_cost = min(min_cost, cost[flag[i][j]]);
			}
			cost.at(i) = max_cost + min_cost + 1;
		}
	}
	cout << cost[0] << endl;
	return 0;
}
0
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
0
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?