2017-03-01から1ヶ月間の記事一覧

codeforces #406 B. Not Afraid

方針 各グループについて、絶対値が等しい正負の値のペアが存在するか探索。 ペアが存在するグループは少なくとも全員がtraitorというわけではない。 ペアが存在しない場合は、グループ全員がtraitorの可能性がある。 一つのグループでも、グループ全員がtra…

codeforces #406 A. The Monster

方針 法則性とか考えないで総当りでいけるっぽい #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int ans = -1; for(int i=0;i<1000;i++) { bool flag = false; for(int</algorithm></vector></iostream>…

ABC D - Maximum Average Sets

#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <iomanip> typedef long long ll; using namespace std; int main() { int n, a, b; cin >> n >> a >> b; vector<ll> v(n); for(int i=0;i<n;i++) { cin >> v[i]; } sort(v.begin(), v.end(), greater<ll>()); int max_cnt = 0; int…</ll></n;i++)></ll></iomanip></algorithm></cmath></vector></iostream>

Codeforces #405 C. Bear and Different Names

方針 まず、n個の異なる名前を用意。 i番目が"NO"なら、ans[i+k-1] = ans[i]とするとi番目以外のk個のグループには影響がない。 ここで、ans[i] = ans[i+k-1]とすると、ans[i+k-1]が後から更新された場合にこまる。 自分の回答 #include <iostream> #include <vector> #include <algorithm></algorithm></vector></iostream>…

Codeforces #405 B. Bear and Friendship Condition

方針 グラフ中の全ての部分グラフ?で (辺の数)= (頂点の数)*(頂点の数-1) / 2 を満たしていれば “YES"、そうでなければ "NO"と出力。 全探索するために配列 vis[頂点の数] を用意。 dfsでは一つの辺に対して二回ずつカウントしている。 つまり、cnt_e…

Codeforces #403 C. Andryusha and Colored Balloons

方針 解けなかったので他の人の解答をみた。 #include <iostream> #include <vector> #include <set> using namespace std; set<int> c[200010]; vector<int> g[200010], p(200010, 0), a(200010, 0); void dfs(int cur, int pre) { if(pre != -1) { while(c[pre].count(p[pre])) p[pre]++; a[</int></int></set></vector></iostream>…

AGC011_B Colorful Creatures

方針 昇順にソートして、それぞれの累積和を計算しておく。すると、i番目の生き物が他のすべての生き物と合体するためには、0<=i<=n-2について(0から始まるインデックス基準)、(i番目の累積和)*2 >= (i+1番目の生物の大きさ)を満たしている必要がある。逆…

AGC011_A Airport Bus

方針 やるだけなのにやけに時間がかかった。自分はアルゴリズム云々の前に、こういう基本的なプログラムの挙動に対する直感がかけているのかも? #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { ll n, c, k; cin ></algorithm></vector></iostream>…