AtCoder Beginner Contest 187 题解
A - Large Digits
按要求求出两个数的每位之和,进行比较即可。
时间复杂度 \(\mathcal{O}(\log(AB))\)。
B - Gentle Pairs
枚举所有点对求斜率。
时间复杂度 \(\mathcal{O}(N^2)\)。
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
int x[1010], y[1010];
int cnt = 0;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
if (i != j)
if (abs(y[i] - y[j]) <= abs(x[i] - x[j])) cnt++;
}
cout << cnt / 2 << "\n";
return 0;
}
C - 1-SAT
用两个HashSet分别存储不带!和带!的字符串的纯字符部分,求两个HashSet的交集。若有交集,则输出其中任意一个字符串;否则按要求输出satisfiable。
时间复杂度 \(\mathcal{O}(N)\)。
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
string s;
unordered_set<string> s1, s2;
for (int i = 0; i < n; ++i) {
cin >> s;
if (s[0] == '!') s1.insert(s.substr(1));
else
s2.insert(s);
}
for (auto x : s1) {
if (s2.count(x)) {
cout << x << "\n";
return 0;
}
}
cout << "satisfiable\n";
return 0;
}
D - Choose Me
将所有城镇按照\(2A_i+B_i\)降序排列,然后贪心选取即可。
时间复杂度 \(\mathcal{O}(N\log N)\)。
using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
vector<pair<ll, ll>> towns;
ll sa = 0, sb = 0; // T,A
for (int i = 0; i < n; ++i) {
int a, b;
cin >> a >> b;
towns.emplace_back(a, b);
sa += a;
}
sort(towns.begin(), towns.end(), [](pair<ll, ll>& p, pair<ll, ll>& q) {
return p.first * 2 + p.second > q.first * 2 + q.second;
});
for (int i = 0; i < n; ++i) {
if (sa < sb) {
cout << i << "\n";
return 0;
}
sa -= towns[i].first, sb += towns[i].first + towns[i].second;
}
cout << n << "\n";
return 0;
}

AtCoder Beginner Contest 187 题解的更多相关文章
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 151 题解报告
总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...
- AtCoder Beginner Contest 115 题解
题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit ...
随机推荐
- 【uniapp】学习笔记day02 | uniapp搭建
起因:需要做一个小程序,家人们谁懂啊,老师我真的不会做,由于懒得看视频学习,于是只能看博客学习了. uniapp 好处: 1.不用关心适配问题 2.可以发布到各大平台的小程序 3.上手容易,使用vue ...
- 月薪3w的报表工程师要会哪些技能?报表工程师的招聘要求解读
对于月薪3w的报表工程师,通常需要具备以下技能: 1. 数据分析与处理 - 数据仓库:了解数据仓库的设计原则和架构,能够构建和优化数据仓库结构. - SQL语言:熟练掌握SQL查询语言,能够编写复杂的 ...
- 你真的了解HashSet 和HashMap的区别、优缺点、使用场景吗?
HashSet 和 HashMap 是 Java 集合框架中的两个常用类,它们都用于存储和管理数据,但在使用方式.功能和性能上有很大的区别. HashSet 和 HashMap 的区别 区别一:用途不 ...
- lua面向对象(类)和lua协同线程与协同函数、Lua文件I/O
-- create a class Animal={name = "no_name" , age=0 } function Animal:bark(voice) print(sel ...
- springBoot——整合junit
spring整合junit复习 springBoot整合junit package com.example.springboot_04; import com.example.springboot_0 ...
- Vue3节流指令封装
节流指令 import { ObjectDirective } from 'vue' interface ThrottleEl extends HTMLElement { throttleEvent: ...
- 2023.2 IDEA安装激活教程
1.下载安装IntelliJ IDEA 先去官网下载,我这里下载的是最新版本的2023.2,测试过2023最新版本以及2022版本以上的版本没问题. 安装然后打开 提示要输入激活码,先关闭应用,等下再 ...
- 在C#中,如何以编程的方式设置 Excel 单元格样式
前言 在C#开发中,处理Excel文件是一项常见的任务.在处理Excel文件时,经常需要对单元格进行样式设置,以满足特定的需求和美化要求,通过使用Java中的相关库和API,我们可以轻松地操作Exce ...
- 面试官喜欢问Nacos原理?直接把这篇文章甩给他!
大家好,我是三友~~ 今天就应某位小伙伴的要求,来讲一讲Nacos作为服务注册中心底层的实现原理 不知你是否跟我一样,在使用Nacos时有以下几点疑问: 临时实例和永久实例是什么?有什么区别? 服务实 ...
- 劫持最新版 QQNT / QQ / TIM 客户端 ClientKeys
针对 腾讯官网 最新发布的 QQNT 9.9.6 与 QQ 9.7.21 新版本客户端全面更新截取代码 大伙应该都知道自从 QQ 9.7.20 版本起就已经不能通过模拟网页快捷登录来截取 Uin 跟 ...