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

  1. Codeforces Round #646 (Div. 2) 题解 (ABCDE)

    目录 A. Odd Selection B. Subsequence Hate C. Game On Leaves D. Guess The Maximums E. Tree Shuffling ht ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. 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 题解 直接 ...

随机推荐

  1. 魔法方法推开Python进阶学习大门

    热爱Python Python是Guido van Rossum设计出来的让使用者觉得如沐春风的一门编程语言.2020年11月12日,64岁的Python之父宣布由于退休生活太无聊,自己决定加入Mic ...

  2. 聊聊 g0

    很多时候,当我们跟着源码去理解某种事物时,基本上可以认为是以时间顺序展开,这是编年体的逻辑.还有另一种逻辑,纪传体,它以人物为中心编排史事,使得读者更聚焦于某个人物.以一种新的视角,把所有的事情串连起 ...

  3. MBAir下安装httprunner2.5.7 har2case 出现zsh: command not found解决方案

    MBAir下python3.8安装httprunner2.5.7 出现zsh: command not found find / -name hrun查找到路径为: /Users/w550856/Li ...

  4. mysql .sock丢时候如何链接数据库

    在mysql服务器本机上链接mysql数据库时,经常会噢出现mysql.sock不存在,导致无法链接的问题,这是因为如果指定localhost作为一个主机名,则mysqladmin默认使用unix套接 ...

  5. Linux设置开机自动挂载镜像文件

    1.将文件上传到服务器上(本例上传到/Data/software下) 2.挂载 mount -o loop /Data/software/rhel-server-7.6-x86_64-dvd.iso ...

  6. Windows安全加固

    Windows安全加固 # 账户管理和认证授权 # 1.1 账户 # 默认账户安全 # 禁用Guest账户. 禁用或删除其他无用账户(建议先禁用账户三个月,待确认没有问题后删除.) 操作步骤 本地用户 ...

  7. css全站变灰

    2020年4月4日全国哀悼日这一天,我发现不少网址都变灰了,我第一想法就是怎么做到的?不可能换素材整个网址重做一遍吧?后面发现是用的其实是css的filter滤镜: grayscale可以将图像转化为 ...

  8. 登陆到 SAP 系统后的用户出口

    增强类型:smod 增强名称:SUSR0001 组件(退出功能模块):EXIT_SAPLSUSF_001 功能:用户每次登陆SAP系统后都会调用这个SUSR0001增强,可以在FUNCTION EXI ...

  9. ABP vNext 实现租户Id自动赋值插入

    背景 在使用ABP vNext过程中,因为我们的用户体系庞大,所以一直与其他业务同时开发,在开发其他业务模块时,我们一直存在着误区:认为ABP vNext 自动处理了数据新增时的租户Id(Tenant ...

  10. java实现Excel定制导出(基于POI的工具类)

    我的需求: 项目中有一些工程表格需要导出,设计到行列合并,定制样式,原有工具类冗余,内聚性强.所以想写一个可以随意定制excel的工具类,工具类满足需求: 对于常用的工程表格有模板格式,可以任意插拔. ...