A - Large Digits

按要求求出两个数的每位之和,进行比较即可。

时间复杂度 AtCoder Beginner Contest 187 题解 - 图1)#card=math&code=%5Cmathcal%7BO%7D%28%5Clog%28AB%29%29)。

B - Gentle Pairs

枚举所有点对求斜率。

时间复杂度 AtCoder Beginner Contest 187 题解 - 图2#card=math&code=%5Cmathcal%7BO%7D%28N%5E2%29)。

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int n;
  4. cin >> n;
  5. int x[1010], y[1010];
  6. int cnt = 0;
  7. for (int i = 0; i < n; ++i) {
  8. cin >> x[i] >> y[i];
  9. }
  10. for (int i = 0; i < n; ++i)
  11. for (int j = 0; j < n; ++j) {
  12. if (i != j)
  13. if (abs(y[i] - y[j]) <= abs(x[i] - x[j])) cnt++;
  14. }
  15. cout << cnt / 2 << "\n";
  16. return 0;
  17. }

C - 1-SAT

用两个HashSet分别存储不带!和带!的字符串的纯字符部分,求两个HashSet的交集。若有交集,则输出其中任意一个字符串;否则按要求输出satisfiable

时间复杂度 AtCoder Beginner Contest 187 题解 - 图3#card=math&code=%5Cmathcal%7BO%7D%28N%29)。

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int n;
  4. cin >> n;
  5. string s;
  6. unordered_set<string> s1, s2;
  7. for (int i = 0; i < n; ++i) {
  8. cin >> s;
  9. if (s[0] == '!') s1.insert(s.substr(1));
  10. else
  11. s2.insert(s);
  12. }
  13. for (auto x : s1) {
  14. if (s2.count(x)) {
  15. cout << x << "\n";
  16. return 0;
  17. }
  18. }
  19. cout << "satisfiable\n";
  20. return 0;
  21. }

D - Choose Me

将所有城镇按照AtCoder Beginner Contest 187 题解 - 图4降序排列,然后贪心选取即可。

时间复杂度 AtCoder Beginner Contest 187 题解 - 图5#card=math&code=%5Cmathcal%7BO%7D%28N%5Clog%20N%29)。

  1. using ll = long long;
  2. int main() {
  3. ios_base::sync_with_stdio(false), cin.tie(0);
  4. int n;
  5. cin >> n;
  6. vector<pair<ll, ll>> towns;
  7. ll sa = 0, sb = 0; // T,A
  8. for (int i = 0; i < n; ++i) {
  9. int a, b;
  10. cin >> a >> b;
  11. towns.emplace_back(a, b);
  12. sa += a;
  13. }
  14. sort(towns.begin(), towns.end(), [](pair<ll, ll>& p, pair<ll, ll>& q) {
  15. return p.first * 2 + p.second > q.first * 2 + q.second;
  16. });
  17. for (int i = 0; i < n; ++i) {
  18. if (sa < sb) {
  19. cout << i << "\n";
  20. return 0;
  21. }
  22. sa -= towns[i].first, sb += towns[i].first + towns[i].second;
  23. }
  24. cout << n << "\n";
  25. return 0;
  26. }

AtCoder Beginner Contest 187 题解 - 图6