当前位置: 首页 > news >正文

AtCoder Beginner Contest 418

文章目录

    • A I'm a teapot
    • B You're a teapot
    • C Flush
    • D XNOR Operation
    • E Trapezium
    • F We're teapots
    • G Binary Operation

AtCoder Beginner Contest 418

A I’m a teapot

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;void solve() {int n; string s; cin >> n >> s;bool f = (n > 2 && s.substr(n - 3, 3) == "tea");cout << (f ? "Yes" : "No") << "\n";
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}

B You’re a teapot

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;void solve() {string s; cin >> s;int x = 0, n = s.size();double ans = 0;for (int i = 0; i < n; i++)for (int j = i + 1; j < n; j++)if (s[i] == 't' && s[j] == 't') {int x = 0, len = j - i + 1;for (int k = i; k <= j; k++)x += (s[k] == 't');ans = max(ans, (x - 2.0) / (len - 2.0));}cout << fixed << setprecision(12) << ans << "\n";
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}

C Flush

On the poker table, there are tea bags of NNN different flavors. The flavors are numbered from 1 through NNN, and there are AiA_iAi tea bags of flavor iii (1≤i≤N1 \leq i \leq N1iN).

You will play a game using these tea bags. The game has a parameter called difficulty between 1 and A1+⋯+ANA_1 + \cdots + A_NA1++AN, inclusive. A game of difficulty bbb proceeds as follows:

  1. You declare an integer xxx. Here, it must satisfy b≤x≤A1+⋯+ANb \leq x \leq A_1 + \cdots + A_NbxA1++AN.
  2. The dealer chooses exactly xxx tea bags from among those on the table and gives them to you.
  3. You check the flavors of the xxx tea bags you received, and choose bbb tea bags from them.
  4. If all bbb tea bags you chose are of the same flavor, you win. Otherwise, you lose.

The dealer will do their best to make you lose.

You are given QQQ queries, so answer each of them. The jjj-th query is as follows:

  • For a game of difficulty BjB_jBj, report the minimum integer xxx you must declare at the start to guarantee a win. If it is impossible to win, report −1-11 instead.

Constraints

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^51N3×105
  • 1≤Q≤3×1051 \leq Q \leq 3 \times 10^51Q3×105
  • 1≤Ai≤1061 \leq A_i \leq 10^61Ai106 (1≤i≤N1 \leq i \leq N1iN)
  • 1≤Bj≤min⁡(109,A1+⋯+AN)1 \leq B_j \leq \min(10^9, A_1 + \cdots + A_N)1Bjmin(109,A1++AN) (1≤j≤Q1 \leq j \leq Q1jQ)
  • All input values are integers.

翻译:
在扑克桌上,有不同口味的茶包。口味从 111NNN 编号,有 AiA_iAi 个茶包口味 iii1≤i≤N1\leq i\leq N1iN)。
你将用这些茶包玩游戏。游戏有一个名为难度的参数,介于 111a1+⋯+aNa_1+\cdots+a_Na1++aN 之间。难度游戏 bbb 的收益如下:

  1. 声明一个整数 xxx。这里,它必须满足 b≤x≤A1+⋯+ANb\leq x\leq A_1+\cdots+A_NbxA1++AN
  2. 经销商从桌上的茶包中准确地选择 xxx 个茶包,并将其送给您。
  3. 您检查收到的 xxx 个茶包,并从中选择 bbb 个茶包。
  4. 如果你选择的 bbb 个茶包都是相同的味道,你就赢了。否则,你输了。

经销商会尽最大努力让你输。

您会收到 QQQ 的查询,请逐一回答。第 jjj 个查询如下:

  • 对于难度为 BjB_jBj 的游戏,报告您必须在开始时声明的最小整数 xxx,以确保获胜。如果不可能获胜,则报告 −1-11

约束条件

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^51N3×105
  • 1≤Q≤3×1051 \leq Q \leq 3 \times 10^51Q3×105
  • 1≤Ai≤1061 \leq A_i \leq 10^61Ai106 (1≤i≤N1 \leq i \leq N1iN)
  • 1≤Bj≤min⁡(109,A1+⋯+AN)1 \leq B_j \leq \min(10^9, A_1 + \cdots + A_N)1Bjmin(109,A1++AN) (1≤j≤Q1 \leq j \leq Q1jQ)
  • 所有输入值都是整数。

分析:

本题目要模拟样例,找到题目所求:当相同元素的数量至少为 bbb 的需要最少有解数量 xxx

解法:考虑对原数组 aia_iai 排序,求出前缀和 sis_isi,二分查询第一个≥b\ge bb 的元素位置 ididid,如果答案存在,则 ans=sid−1+(b−1)×(n−id+1)+1ans=s_{id-1} + (b-1) \times (n-id+1) +1ans=sid1+(b1)×(nid+1)+1;否则 ans=−1ans=-1ans=1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;
int n, q, a[N], b;
ll s[N];void solve() {cin >> n >> q;for (int i = 1; i <= n; i++) cin >> a[i];sort(a + 1, a + 1 + n);for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];while (q--) {cin >> b;int id = lower_bound(a + 1, a + 1 + n, b) - a;ll ans = -1;if (id <= n && a[id] >= b)ans = s[id - 1] + 1ll * (b - 1) * (n - id + 1) + 1;cout << ans << "\n";}
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}

D XNOR Operation

E Trapezium

F We’re teapots

G Binary Operation

http://www.xdnf.cn/news/1271971.html

相关文章:

  • 嵌入式知识日常问题记录及用法总结(一)
  • Level-MC 11“天空”
  • 【动态数据源】⭐️@DS注解实现项目中多数据源的配置
  • 动态规划(三维)直接按照题目条件
  • windows上LM-Studio下载安装教程
  • 衰减器的计算
  • Java 时间和空间复杂度
  • 推荐系统学习笔记(十)多目标排序模型
  • 《软件测试与质量控制》实验报告五 功能自动化测试
  • SpringSecurity过滤器链全解析
  • 学习:JS[8]本地存储+正则表达式
  • 心灵笔记:思考三部曲
  • 谷歌搜索 sg_ss 逆向分析
  • 计算机网络:深入了解CIDR地址块如何利用VLSM进行子网划分的过程
  • 算法_python_牛客华为机试笔记_01
  • C++算法练习:单词识别
  • 应急响应复现
  • 传输线模拟经验谈
  • 新手入门:Git 初次配置与 Gitee 仓库操作全指南 —— 从环境搭建到代码推送一步到位
  • 编辑距离-二维动态规划
  • Kotlin初体验
  • git命令详解
  • 百度网盘如何做到下载速度最快?OpenSpeedy绿色安装版下载,开源免费网盘加速
  • react 常用组件库
  • Day37--动态规划--52. 携带研究材料(卡码网),518. 零钱兑换 II,377. 组合总和 Ⅳ,57. 爬楼梯(卡码网)
  • Poetry与UV——现代Python依赖管理的革新者
  • Linux 安装 JDK 8u291 教程(jdk-8u291-linux-x64.tar.gz 解压配置详细步骤)​
  • 深入理解 Gin 框架的路由机制:从基础使用到核心原理
  • 蓝牙技术概览
  • imx6ull-驱动开发篇16——信号量与互斥体