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 题解的更多相关文章

  1. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  2. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  5. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  6. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

  7. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  8. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  9. AtCoder Beginner Contest 151 题解报告

    总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...

  10. AtCoder Beginner Contest 115 题解

    题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit ...

随机推荐

  1. Aignize第一期完善产品逻辑+类图说明书

    Aiganize产品说明+拟类图(第一期) ·附图: 此应用由: 前端:微信小程序前端+vue3后台管理系统后端:Springboot+Mysql 服务器:后端服务器+AI交互服务器 整个应用流程大致 ...

  2. [ABC262B] Triangle (Easier)

    Problem Statement You are given a simple undirected graph with $N$ vertices and $M$ edges. The verti ...

  3. CompletableFuture进阶

    CompletableFuture进阶 1.异步任务的交互 异步任务交互指将异步任务获取结果的速度相比较,按一定的规则( 先到先用 )进行下一步处理. 1.1 applyToEither applyT ...

  4. DVWA File Inclusion(文件包含)全等级

    File Inclusion(文件包含) 目录: File Inclusion(文件包含) 前言 PHP伪协议 1.Low get webshell 本地文件包含 远程文件包含 2.Medium 3. ...

  5. SQL注入Fuzzing字典

    需要的自取 ' " # - -- ' -- --'; ' ; = ' = ; = -- \x23 \x27 \x3D \x3B' \x3D \x27 \x27\x4F\x52 SELECT ...

  6. 对比Spring Boot中的JdbcClient与JdbcTemplate

    本文我们一起看看Spring Boot中 JdbcClient 和 JdbcTemplate 之间的差异. 以下内容使用的Java和Spring Boot版本为: Java 21 Spring Boo ...

  7. Winform PictureBox图片旋转

    Image img = this.pictureBox1.Image; img.RotateFlip(RotateFlipType.Rotate90FlipNone); this.pictureBox ...

  8. Spring事务状态处理

    Spring事务提交后执行:深入理解和实践 在Java开发中,Spring框架的事务管理是一个核心概念,尤其是在企业级应用中.理解和正确使用Spring事务对于保证应用的数据一致性和稳定性至关重要.本 ...

  9. hystrix的熔断降级

    hystrix的熔断降级 结合Feign使用 1.A服务通过B服务的唯-标识,从Nacos获取到可调用列表. 2.使用feigh中的Http发起远程请求. 3.超过默认配置的时限,抛出异常,结束该线程 ...

  10. Java 获取Excel中的表单控件

    Excel中可通过[开发工具]菜单栏下插入表单控件,如文本框.单选按钮.复选框.组合框等等,插入后的控件可执行设置控件格式,如大小.是否锁定.位置.可选文字.数据源区域.单元格链接等.当Excel中已 ...