Codeforces Round #590

题目链接:Round #590
题目答案:官方EditorialMy Solution

A. Equalize Prices Again

签到题还WA了一发,向上取整有点问题:

//my wrong code, 1.0 * sum返回double
ceil(1.0 * sum / n);

//right code
(int)ceil(1.0 * sum / n);

//ceil()原型
double ceil(double x);

float能保证6位精度(有效数字),double能保证15位精度。但是floatdouble默认都只显示6位有效数字,所以一旦1.0 * sum / n大于6位,函数返回的double就显示不全,造成精度损失(比如结果应该是5336844,但返回5.33684e+006),故进行强制类型转换。

B1. Social Network (easy version)

题意:屏幕可以容纳\(k\)条短信,有若干朋友发来\(n\)条短信。如果某个朋友已经在屏幕上,不做改变;否则将其他朋友下移,新收到的朋友置顶。求最终自顶向下显示在屏幕上的朋友。
思路:按照题意模拟,我搞得有些繁琐(用queue + set来考虑是否将新来的短信放入屏幕,再用queue.size()和\(k\)判断是否需要将旧短信pop(),最后将队列中的元素逆序输出)。

B2. Social Network (hard version)

数据量变到了\(10^5\)级别,官方题解和我在B1中的思路一致。不过最后输出我是先压栈,题解是先存入vector,再用reverse()函数逆序,复杂度\(O(nlogk)\)。

C. Pipes

原文地址:https://www.cnblogs.com/EIMadrigal/p/11617248.html

时间: 2024-11-13 06:47:58

Codeforces Round #590的相关文章

Codeforces Round #590 (Div. 3) Editorial

Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同的价格,找出一个最小的可能值price,使得price * n >= sum,sum指的是原来商品价格的总和. 知识点:模拟 思路:求出sum/n向上取整即可,有两种方法.一是使用ceil()函数,但注意ceil()返回的是向上取整后的浮点数,所以要进行强制类型转换:二是直接向下取整,然后用if语句

Codeforces Round #590 (Div. 3)

D. Distinct Characters Queries Description You are given a string ss consisting of lowercase Latin letters and qq queries for this string. Recall that the substring s[l;r]s[l;r] of the string ss is the string slsl+1…srslsl+1…sr. For example, the subs

Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most

Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l;r] of the string s is the string slsl+1-sr. For example, the substrings

Codeforces Round #590 (Div. 3) C. Pipes

链接: https://codeforces.com/contest/1234/problem/C 题意: You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1,1) and the bottom right - (2,n). There are six types of pipes: two

Codeforces Round #590 (Div. 3)(e、f待补

https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main(){ 5 int n,a; 6 int t; 7 cin>>t; 8 ll sum = 0,ans; 9 while(t--){ 10 cin>>n;sum = 0

Codeforces Round #590 (Div. 3) F

传送门 题意: 给出一个只含前\(20\)个字符的字符串,现在可以选择一段区间进行翻转,问区间中字符各不相同时,最长长度为多少. 思路: 首先,容易将题意转换为选择两个字符各不相同的区间,然后长度相加取最大: 注意到字符串中满足条件的区间长度不超过\(20*n\),那么处理出所有区间,现在任务即为找到两个区间,其字符各不想同,且长度和最大: 因为最多\(20\)个字符,将满足条件的区间转换为二进制数,任务转换为找到两个数\(a_i,a_j\)满足\(a_i\&a_j=0\)且二进制为\(1\)的

Codeforces Round #590 (Div. 3)补题

要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ? √ 解 E 待定 F 传送门 第一次接触状态压缩dp的题.这道题转换问题的思路非常巧妙. 原问题: 已知: 一个字符串,可进行不超过一次操作 操作限定: 选择某个子串,使其在原串中翻转 目的:使原串的特征值最大 串的特征值:串任意没有重复字符的子串,其包含字符的种类数 问题的转换: 首先选定一个子串a,之后再找到另一个子串b,使得a

Codeforces Round #590 (Div. 3) C——1234C Pipes

D. Distinct Characters Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a system of pipes. It consists of two rows, each row consists of nn pipes. The top left pipe ha