当前位置: 首页 > 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.dtcms.com/a/323423.html

相关文章:

  • LLVM编译器入门
  • 力扣面试150(51/100)
  • 【Python 工具人快餐 · 第 2 份】
  • 使用SPM进行核磁数据预处理
  • 【无标题】六边形结构在二维拓扑量子色动力学模型中确实具有独特优势,并构建完整的二维拓扑量子色动力学模型。
  • Redis三种特殊数据类型
  • 【深度学习2】logistic回归以及梯度下降
  • synchronized和RentrantLock用哪个?
  • Datawhale AI夏令营第三期,多模态RAG方向 Task2
  • 小白成长之路-Docker部署
  • 第二十八天(cookiesessiontokeny验证)
  • JVM性能调优的原则有哪些?
  • 深入理解C++构造函数与初始化列表
  • P1025 [NOIP 2001 提高组] 数的划分 题解
  • 【嵌入式DIY实例-Arduino篇】-水质检测系统
  • SQL面试题及详细答案150道(01-20) --- 基础概念与语法篇
  • python踩坑之识别错误...
  • 如何分析需求的可行性
  • Spring——Spring懒加载设计使用场景
  • 深入解析进程创建与终止机制
  • Linux 信号处理标志sa_flags详解
  • MPU-6050 超实用入门
  • 一文详解 C++ 继承体系
  • [C/C++线程安全]_[中级]_[多线程如何使用共享锁提升性能]
  • EP06:【DL 第二弹】动态计算图与梯度下降入门
  • 【C/C++】具有C风格的强制类型转换:显式类型转换、隐式类型转换,C语言强制类型转换
  • 第六章:【springboot】框架springboot原理、springboot父子工程与Swagger
  • 算法题(183):质量检测
  • 《答客难》东方朔
  • 网络原理-初识