JOI2012予選おつかれさまでした
今年の予選はえーなんだったんでしょうね。
終わった感じボーダー80点台な空気バンバンするんですがどうでしょう。
とりあえずコードと感想貼っときます
問1
やるだけ。
#include <iostream> #include <string> #include <vector> #include <cstring> #include <algorithm> using namespace std; main(){ int L, A, B, C ,D; cin >> L >> A >> B >> C >> D; int lang = A/C; if (A%C) lang++; int math = B/D; if (B%D) math++; cout << L - max(lang, math) << endl; }
問2
やるだけ。(問題覚えてない)
#include <iostream> #include <string> #include <vector> #include <cstring> #include <algorithm> using namespace std; main(){ int N; cin >> N; vector<vector<int> > number(N, vector<int>(3)); for (int i = 0; i < N; i++){ for (int j = 0; j < 3; j++){ cin >> number[i][j]; } } vector<int> score(N); for (int i = 0; i < N; i++){ score[i] = 0; } for (int i = 0; i < 3; i++){ for (int j = 0; j < N; j++){ bool flag = true; for (int k = 0; k < N; k++){ if (j == k) continue; if (number[j][i] == number[k][i]){ flag = false; } } if (flag) score[j] += number[j][i]; } } for (int i = 0; i < N; i++){ cout << score[i] << endl; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JOI2012_3 { class Program { static bool canMake(string str, string board) { if (str.Length > board.Length) return false; bool result = canMake(str, board.Substring(1, board.Length - 1)); if (result) return true; for (int space = 0; space < board.Length; space++) { bool flag = true; for (int i = 0; i < str.Length; i++) { if (i * (space + 1) >= board.Length) { flag = false; break; } if (board[i * (space + 1)] != str[i]) { flag = false; } } if (flag) { result = true; break; } } return result; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string name = Console.ReadLine(); List<string> boards = new List<string>(); for (int i = 0; i < N; i++) { boards.Add(Console.ReadLine()); } int count = 0; boards.ForEach(s => { if (canMake(name, s)) { count++; } }); Console.WriteLine(count); } } }
問4
テストケースに気温55度とか平気であるけど早く逃げろ
1,2だけ通るけど結構自信持った実装だったからこころへしおられた
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JOI2012_4 { struct C { public int high; public int low; public int value; public bool canWear(int temp) { return low <= temp && temp <= high; } } class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int D = int.Parse(line[0]); int N = int.Parse(line[1]); List<int> temperatures = new List<int>(); for (int i = 0; i < D; i++) { temperatures.Add(int.Parse(Console.ReadLine())); } List<C> clothes = new List<C>(); for (int i = 0; i < N; i++) { line = Console.ReadLine().Split(' '); C c = new C(); c.low = int.Parse(line[0]); c.high = int.Parse(line[1]); c.value = int.Parse(line[2]); clothes.Add(c); } List<List<int>> calc = new List<List<int>>(); for (int i = 0; i < D; i++) { for (int j = 0; j < N; j++) { calc.Add(new List<int>()); calc[i].Add(0); } } for (int i = 1; i < D; i++) { for (int j = 0; j < N; j++) { int temp = temperatures[i]; if (!clothes[j].canWear(temp)) continue; int value = clothes[j].value; int sub = 0; int sub_i = 0; for (int k = 0; k < N; k++) { //着られない if (!clothes[k].canWear(temperatures[i-1])) continue; int d = Math.Abs(value - clothes[k].value); if (d > sub) { sub_i = k; sub = d; } } if (calc[i - 1][sub_i] != int.MaxValue) { calc[i][j] = calc[i - 1][sub_i] + sub; } } } int M = 0; for (int i = 0; i < N; i++) { M = Math.Max(calc[D - 1][i], M); } Console.WriteLine(M); } } }