complete 32930.cpp 6527.kt
This commit is contained in:
81
storage/zeta/cpp/completed/32930.cpp
Normal file
81
storage/zeta/cpp/completed/32930.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
uint32_t get_score(const pair<int32_t, int32_t> &a, const pair<int32_t, int32_t> &b) {
|
||||||
|
return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t get_maximum_score(
|
||||||
|
size_t n, size_t m,
|
||||||
|
vector<pair<int32_t, int32_t>> pre_targets,
|
||||||
|
queue<pair<int32_t, int32_t>> next_targets
|
||||||
|
) {
|
||||||
|
// pq로 관리하면 더 좋을듯
|
||||||
|
uint32_t score = 0;
|
||||||
|
pair<int32_t, int32_t> now{0, 0};
|
||||||
|
|
||||||
|
vector<pair<int32_t, int32_t>> targets = std::move(pre_targets);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m; i++) {
|
||||||
|
auto acc = max_element(targets.begin(), targets.end(),
|
||||||
|
[now](
|
||||||
|
pair<int32_t, int32_t> const &a, pair<int32_t, int32_t> const &b
|
||||||
|
) {
|
||||||
|
return get_score(now, a) < get_score(now, b);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
score += get_score(now, *acc);
|
||||||
|
now = *acc;
|
||||||
|
|
||||||
|
targets.erase(acc);
|
||||||
|
targets.push_back(next_targets.front());
|
||||||
|
next_targets.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t main() {
|
||||||
|
cin.tie(nullptr);
|
||||||
|
cout.tie(nullptr);
|
||||||
|
ios_base::sync_with_stdio(false);
|
||||||
|
|
||||||
|
size_t n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
|
||||||
|
vector<
|
||||||
|
pair<int32_t, int32_t>
|
||||||
|
> pre_targets;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
pair<int32_t, int32_t> p;
|
||||||
|
cin >> p.first >> p.second;
|
||||||
|
pre_targets.push_back(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
queue<
|
||||||
|
pair<int32_t, int32_t>
|
||||||
|
>
|
||||||
|
next_targets;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m; i++) {
|
||||||
|
pair<int32_t, int32_t> p;
|
||||||
|
cin >> p.first >> p.second;
|
||||||
|
next_targets.push(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << get_maximum_score(n, m, pre_targets, next_targets) << endl;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
35
storage/zeta/kt/completed/6527.kt
Normal file
35
storage/zeta/kt/completed/6527.kt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import java.io.StreamTokenizer
|
||||||
|
|
||||||
|
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
|
||||||
|
this.resetSyntax()
|
||||||
|
this.wordChars('a'.code, 'z'.code)
|
||||||
|
this.wordChars('A'.code, 'Z'.code)
|
||||||
|
this.whitespaceChars(0, 'A'.code - 1)
|
||||||
|
this.whitespaceChars('z'.code + 1, 255)
|
||||||
|
|
||||||
|
val words = mutableSetOf<String>()
|
||||||
|
|
||||||
|
var gameCount = 0
|
||||||
|
var wordCount = 0
|
||||||
|
while (nextToken() != StreamTokenizer.TT_EOF) {
|
||||||
|
if (sval == null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val potentialWord = sval.trim()
|
||||||
|
if (potentialWord == "BULLSHIT") {
|
||||||
|
gameCount += 1
|
||||||
|
wordCount += words.count()
|
||||||
|
words.clear()
|
||||||
|
} else {
|
||||||
|
words.add(potentialWord.lowercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(2..500).forEach { i ->
|
||||||
|
while (wordCount % i == 0 && gameCount % i == 0) {
|
||||||
|
wordCount /= i; gameCount /= i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("$wordCount / $gameCount")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user