AOJ1077 the Great Summer Contest

The Great Summer Contest | Aizu Online Judge

Introduction to Programming Introduction to Algorithms and Data Structures Library of Data Structures Library of Graph Algorithms Library of Computational Geometry Library of Dynamic Programming Library of Number Theory

それぞれの分野の問題が与えられるので,最大何回コンテストを開けるかを答える.
最初は合わせて 問,ということでどちらかは必ず無いとダメと勘違いしていた.そうではないのでMathとDP,GreedyとGraph,GeometryとOtherの区別が入らない.バランスの良いコンテストを 回行うのと,それぞれのコンテストを 回やるのは同じであるが, バランスの良いコンテストを行えるだけ行う場合では,それぞれの分野のコンテストを行ったほうが良い場合がある. 例えば では,バランスの良いコンテストは 回行えるがそれぞれの分野のコンテストは 回行える.なので バランスの良いコンテスト行えるだけ行ったもの, それから 段階戻して,それぞれの分野のコンテストを行ったもの を取った.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  ll a, b, c, d, e, f;
  while(cin >> a >> c >> e >> b >> d >> f) {
      if(a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0) break;

      ll ans = 0, A = 0, B = 0, C = 0;
      ll res = min(a + b, min(c + d, e + f));

      A = (a + b) - res;
      B = (c + d) - res;
      C = (e + f) - res;
      ans = res + (A / 3) + (B / 3) + (C / 3);

      if(res >= 1) {
          A++; B++; C++;
          res--;
      }
      else if(res >= 2) {
          A += 2; B += 2; C += 2;
          res -= 2;
      }

      cout << max(ans, res + (A / 3) + (B / 3) + (C / 3)) << endl;
  }
  return 0;
}
May 16th, 2016