Codeforces Round #643 (Div. 2) 题解 (ABCDE)
https://codeforces.com/contest/1355
打一半和室友开黑去了哈哈哈哈哈哈反正不计分(不要学我)
A. Sequence with Digits
这题我会证!首先对于百位来说,不可能从x跳到x+2,只能从x变成x+1或者不变(因为最大变化量为 \(9\times9=81\))
这样的话大约1000次内,百位不可避免地从9变成0,这样min的值是0,变化量min*max就是一直是0了
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
const int N=200010; typedef long long ll;
#define int ll
int a,k;
string s;
signed main(){
int T; cin>>T;
while(T--){
cin>>a>>k;
while(--k){
s=to_string(a);
int x=*min_element(s.begin(),s.end())-48;
int y=*max_element(s.begin(),s.end())-48;
if(x==0)break;
a+=x*y;
}
cout<<a<<endl;
}
return 0;
}
B. Young Explorers
比赛中我自始至终都以为所有探险者都要组队,然后emmm...
贪心,尽量组规模小的队,所以排个序就好了
感谢zkx巨佬提供的代码(没错,我懒了补题)
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
int n;
int a[N];
inline void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a+1, a+n+1);
int res = 0;
for (int i = 1, cnt = 0; i <= n; ++i) {
++cnt;
if (cnt >= a[i]) {
++res;
cnt = 0;
}
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int T = 1;
cin >> T;
for (int t = 1; t <= T; ++t) {
solve();
}
return 0;
}
C. Count Triangles
先讲一下我的思路
\(A≤x≤B≤y≤C≤z≤D\)
因为 \(x\) 范围不大,考虑枚举 \(x\) 的值。这样对于任意满足要求的 \(y\),都有 \(C\le z\le \min(D,x+y-1)\),或者说,\(z\) 的方案数为 \(\max(0,\min(D,x+y-1)-C+1)\)。令这个东西为 \(f(y)=\max(0,\min(D,x+y-1)-C+1)\),函数图像大概长这样

先一次函数上升,然后变成常函数。此时就能成两段讨论(一次函数和常函数),求出两个转折点什么的,太过于数学,逃了
然后放个没人能看懂的代码(经刘老师提醒,2020-5-17 11:45之前放的是错误代码,现已更正)
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
const int N=200010; typedef long long ll;
#define int ll
int a,b,c,d;
signed main(){
cin>>a>>b>>c>>d;
int ans=0;
repeat(i,a,b+1){
int x=max(c,i+b-1); //第一个转折点
int y=min(i+c-1,d); //第二个转折点
int l=x-c+1,r=y-c+1;
if(x<=y)ans+=(l+r)*(r-l+1)/2; //一次函数(等差数列求和)
if(i+c-1>max(x-1,y))ans+=(i+c-1-max(x-1,y))*(d-c+1); //常函数
}
cout<<ans<<endl;
return 0;
}
等会补个别人家的代码(雾,我作业来不及了,不补了)
D. Game With Array
这题就一sb题。如果 \(2N> S\),这意味着序列中至少存在一个1,然后。。就NO了(还没证明)
如果 \(2N\le S\),那就构造一个序列:\([2,2,2,...,2,(S-2(N-1))]\),所有数都大于等于 \(2\),所以这个序列的任意子序列之和都不可能是 \(1\),也不可能是 \(S-1\)(因为存在子序列和为 \(S-1\) 就必然存在子序列和为 \(1\))。而子串又是一种特殊的子序列,所以完全ojbk
更:看了一下官方题解,来证明一波 \(2N>S\) 的情况
先假定 \(K\le \dfrac S 2\)。对序列求个前缀和 \(sum[i]=\sum\limits_{j=1}^{i}a[j]\),\(sum[0]=0\)。我们知道区间和相当于两个前缀和的差值,而这个差值不能等于 \(K\) 或者 \(S-K\),这意味着对于每个 \(sum[i]\) 都不能出现另一个 \(sum[j]=(sum[i]+K)\%S\)(非常巧妙,如果 \(sum[i]+K\ge S\),取模后正好等于 \(sum[i]-(S-K)\),差值为 \(S-K\),太牛逼了)
也就是,对每个 \(sum[i]\),我们认为它占用了两个位置 \(sum[i]\) 和 \((sum[i]+K)\%S\)。总共 \(S\) 个座位,要坐 \(2N\) 个人,还有 \(2N>S\) 的限制,想想都不可能
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
const int N=200010; typedef long long ll;
#define int ll
int n,s;
signed main(){
cin>>n>>s;
if(2*n<=s){
cout<<"YES"<<endl;
repeat(i,0,n-1)cout<<2<<' ';
cout<<s-(n-1)*2<<endl;
cout<<1<<endl;
}
else
cout<<"NO"<<endl;
return 0;
}
E. Restorer Distance
我们可以很轻松地算出,如果最终状态为每个位置高度为 \(H\) 的代价是多少。因此 \(H\) 的选取就成为本题的关键
大佬们就能一眼看出,代价对 \(H\) 存在单峰(随 \(H\) 先递减后递增),因此三分。那么为什么存在单峰呢?太难顶了,留作习题答案略(qwq)
我的三分其实就是二分,感觉能加一点速(?)感觉最快的可能是1.618优选法,但是我写不来(?)
我的方法是 \(O(n\log n\)),标程是 \((\log^2n)\) 因为处理了前缀和,get_cost() 里只要 lowerbound 一下就能算答案了,真是妙啊
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
const int N=100010; typedef long long ll;
#define int ll
int n,A,B,C;
int a[N];
int get_cost(int h){
int up=0,down=0;
repeat(i,0,n)
(h>a[i]?up:down)+=abs(a[i]-h);
int t=min(up,down);
return (up-t)*A+t*B+(down-t)*C;
}
signed main(){
cin>>n>>A>>C>>B; B=min(B,A+C);
repeat(i,0,n)
cin>>a[i];
int l=0,r=1e9+1;
while(l<r){
int x=(l+r)/2,y=x+1;
if(get_cost(x)<get_cost(y))r=y-1;
else l=x+1;
}
cout<<get_cost(l)<<endl;
return 0;
}
Codeforces Round #643 (Div. 2) 题解 (ABCDE)的更多相关文章
- Codeforces Round #646 (Div. 2) 题解 (ABCDE)
目录 A. Odd Selection B. Subsequence Hate C. Game On Leaves D. Guess The Maximums E. Tree Shuffling ht ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
随机推荐
- 实验一-最小生成树Kruskal算法
实验名称 最小生成树算法-Kruskal算法 实验目的 1.掌握并查集的合并优化和查询优化: 2.掌握Kruskal算法. 3.能够针对实际问题,能够正确选择贪心策略. 4.能够针对选择的贪心策略,证 ...
- mmall商城分类模块总结
后台分类model的开发具体功能有:添加分类名称,修改分类名称,查询所有子分类,查询父分类以及它下面的子分类(递归) 需要注意的是,在后台管理进行操作的时候,都需要验证当前用户是否是管理员的角色,不管 ...
- MySQL多版本并发控制——MVCC机制分析
MVCC,即多版本并发控制(Multi-Version Concurrency Control)指的是,通过版本链维护一个数据的多个版本,使得读写操作没有冲突,可保证不同事务读写.写读操作并发执行,提 ...
- PHP MySQLi extension is not loaded
PHP MySQLi extension is not loaded 如何解决呢? yum -y install mysqli.so huozhe yum -y install php-mysql
- HATEOAS的简单认识
HATEOAS: 超媒体作为应用程序状态引擎(HATEOAS)是REST应用程序体系结构的一个组件,它将其与其他网络应用程序体系结构区分开来. 使用HATEOAS,客户端与网络应用程序交互,其应用程序 ...
- 目标检测的评价指标(TP、TN、FP、FN、Precision、Recall、IoU、mIoU、AP、mAP)
1. TP TN FP FN GroundTruth 预测结果 TP(True Positives): 真的正样本 = [正样本 被正确分为 正样本] TN(True Negatives): 真的 ...
- Linux安装Oracle数据库SQLPlus客户端
安装 RPM包下载地址:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html ...
- CTO也糊涂的常用术语:功能模块、业务架构、用户需求、文档……
功能模块.业务架构.需求分析.用户需求.系统分析.功能设计.详细设计.文档.业务.技术--很多被随口使用的名词,其实是含糊甚至错误的. 到底含糊在哪里,错误在哪里,不仅仅是新手软件开发人员糊涂,许多入 ...
- 为失败设计,大量引入对SRE的理解,鲁棒性高
https://go-kratos.dev/#/ Principles 简单:不过度设计,代码平实简单 通用:通用业务开发所需要的基础库的功能 高效:提高业务迭代的效率 稳定:基础库可测试性高,覆盖率 ...
- python 11 模块
模块 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较 ...