2011年12月18日日曜日

JOI死んだ死にたい

JOI死んだ死にたい
JOI死んだ死にたい
JOI死んだ死にたい

問4の簡単な2パターンの見落としで死にました



問1
#include <iostream>
using namespace std;

main(){
  int pasta[3];
  int juice[2];
  for (int i = 0; i < 3; i++) cin >> pasta[i];
  for (int i = 0; i < 2; i++) cin >> juice[i];
  int result = min(pasta[0], min(pasta[1], pasta[2])) + min(juice[0], juice[1]) - 50;
  cout << result << endl;
}

問2
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

main(){

  int teamc;
  cin >> teamc;
  int match = teamc * (teamc - 1) / 2;

  vector<int> team(teamc);
  for (int i = 0; i < teamc; i++) team[i] = 0;

  for (int z = 0; z < match; z++){
    int A,B,AA,BB;
    cin >> A >> B >> AA >> BB;
    if (AA > BB){
      team[A-1] += 3;
    }else if (AA < BB){
      team[B-1] += 3;
    }else{
      team[A-1]++;
      team[B-1]++;
    }
  }
  for (int i = 0; i < teamc; i++){
    team[i] = team[i] * 1000 + i;
  }

  sort(team.begin(), team.end(), greater<int>());

  int rank[teamc];
  int score = -1;
  int c_rank = 0;
  for (int i = 0; i < teamc; i++){
    if (team[i] / 1000 == score){
      rank[team[i] % 1000] = c_rank;
    }else{
      rank[team[i] % 1000] = i;
      score = team[i] / 1000;
      c_rank = i;
    }
  }

  for (int i = 0; i < teamc; i++){
    cout << rank[i] + 1 << endl;
  }
}

問3
#include <iostream>
#include <vector>
#include <functional>
using namespace std;


main(){
  int toppingcount;
  int kiji;
  int kiji_nedan;
  int topping_nedan;


  cin >> toppingcount;
  cin >> kiji_nedan >> topping_nedan >> kiji;
  vector<int> topping(toppingcount);



  for (int i = 0; i < toppingcount; i++){
    cin >> topping[i];
  }
  sort(topping.begin(), topping.end(), greater<int>());

  int current[101];
  current[0] = kiji;
  for (int i = 1; i < topping.size() + 1; i++){
    int cal = current[i-1] + topping[i-1];
    current[i] = cal;
  }

  int result = 0;
  for (int i = 0; i < topping.size() + 1; i++){
    int price = current[i] / (kiji_nedan + topping_nedan * i);
    result = max(result, price);
  }
  cout << result << endl;
}

price変数なんてなかった

問4(コードを約3行くらい書き換えると正常に動きます探さないでください)
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int solve(int, int, int);

int dp[101][3][3];
vector<int> fixed_(100);
int N, K;

main(){
  cin >> N >> K;
  for (int i = 0; i < K; i++){
    int day, type;
    cin >> day >> type;
    fixed_[day-1] = type;
  }
  memset(dp, -1, sizeof(dp));

  int result = solve(0, -1, -2);
  cout << result << endl;
}

int solve(int i, int j1, int j2){

  if (fixed_[i] != 0){
    return solve(i + 1, j2, fixed_[i]);
  }
  if (j1 >= 0 && j2 >= 0){
    if (dp[i][j1][j2] != -1){
      return dp[i][j1][j2];
    }
  }

  if (i == N-1){
    if (j1 == j2){
      return 2;
    }else{
      return 3;
    }
  }

  int k1 = fixed_[i+1];
  int k2 = fixed_[i+2];

  int result = 0;
  if (j2 == k1){
    for (int cur = 1; cur <= 3; cur++){
      if (cur != j2){
        result += solve(i + 1, j2, cur);
      }
    }
  }else if (j1 == j2){
    if (k1 == k2){
      for (int cur = 1; cur <= 3; cur++){
        if (cur != j1 && cur != k1) {
          result = solve(i + 1, j2, cur);
          break;
        }
      }
    }else{
      for (int cur = 1; cur <= 3; cur++){
        if (cur != j1){
          result += solve(i + 1, j2, cur);
        }
      }
    }
  }else if (k1 == k2){
    for (int cur = 1; cur <= 3; cur++){
      if (cur != k1){
        result += solve(i + 1, j2, cur);
      }
    }
  }else{
    if (k1 == k2){
      for (int cur = 1; cur <= 3; cur++){
        if (cur != k1){
          result += solve(i + 1, j2, cur);
        }
      }
    }else{
      for (int cur = 1; cur <= 3; cur++){
        result += solve(i + 1, j2, cur);
      }
    }
  }
  dp[i][j1][j2] = result % 10000;
  return dp[i][j1][j2];
}

コードが汚いのは気にしちゃだめ。

0 件のコメント:

コメントを投稿