前言:这套cf我感觉出的很不错,AB就不说了,唯一有点欠缺的就是C和D的位置应该换一下,C出的挺不错,反正我当时没有想出来(赛后补题的时候其实也不难。。听朋友说还可以FFT优化,然而我是个图论手并不会数论)。D就是个一眼构造题,也没什么意思。E也是个不错的三分题,至少加强了我对三分的认知。F过的人太少,不补了叭

A:Sequence with Digits

签到题不详细讲了,直接上代码吧...

#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long ll a, b; int main()
{
int t;
cin >> t;
while (t--)
{
cin >> a >> b;
int cnt = ;
while ()
{
if (cnt == b)
break;
int ma = , mi = ;
ll tmp = a;
while (tmp > )
{
int now = tmp % ;
ma = max(ma, now), mi = min(mi, now);
tmp /= ;
}
if (mi == )
break;
cnt++;
a += mi * ma;
}
cout << a << "\n";
}
}

B:Young Explorers

这个题也没什么意思,签到

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+;
const int maxn=1e6+;
int a[maxn];
int main(){
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
sort(a+,a+n+);
int res=;int sum=;
for(int i=;i<=n;i++)
{
sum++;
if(a[i]<=sum)
{
sum=;res++;
}
}
cout<<res<<endl;
}
}

C:Count Triangles

解法:很显然,这个题2层for循环肯定爆TLE,那么就需要优化了。众所周知,构成三角形的条件是:x+y>z,那么我可以进行枚举x+y来优化,令m=x+y,算出当x+y和为m的时候,有几种可行的构造数量s2,然后去乘s1=max(m-1,d)-c+1就可以了,前提是s1和s2均非0

∵x+y=m, ∴y=m-x, 又∵B≤y=m-x≤C,∴m-C≤x≤m-B,又因为A≤x≤B,所以取交集,该组数目等于右界-左界+1

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+;
const int maxn=5e5+;
int main(){
int a,b,c,d;cin>>a>>b>>c>>d;
ll ans=;
for(int i=a+b;i<=b+c;i++){
int s1=min(d,i-)-c+;
int s2=min(i-b,b)-max(i-c,a)+;
if(s1<||s2<) continue;
else ans+=1LL*s1*s2;
}
cout<<ans<<endl;
}

D. Game With Array

解法:构造n-1个1和1个s-n+1,判断s-n+1>n的情况是否存在,存在就输出yes,反之输出no

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+;
const int maxn=1e6+;
int a[maxn];
int main(){
int n,s;cin>>n>>s;
if(s<=*n-) puts("NO");
else{
puts("YES");
for(int i=;i<n;i++){
cout<<<<" ";
}
cout<<s-n+<<endl;
cout<<s-n<<endl;
}
}

E. Restorer Distance

解法:三分高度,因为这个题是求最小花费,所以图像是与y=x^2很类似,针对曲线求最小值就是三分。另外up就是需要增加的砖块数,down就是需要减少的砖块数。显然总花费=ans=A*up+R*down;倘若A+R>M,那么就需要减少总花费了,此时x=min(up,down),ans+=M*x-x*A-x*R;

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+;
const int maxn=1e5+;
int N,A,R,M,a[maxn];
ll check(int mid){
ll ans=,up=,down=;
rep(i,,N){
if(a[i]<mid)up+=mid-a[i];
else down+=a[i]-mid;
}
ans=A*up+R*down;
ll x=min(up,down);
if(A+R>M) ans+=M*x-x*A-x*R;
return ans;
}
int main(){
cin>>N>>A>>R>>M;
rep(i,,N) cin>>a[i];
int l=,r=1e9;
while(l<r){
int midl=(r-l)/+l,midr=r-(r-l)/;
ll suml=check(midl),sumr=check(midr);
if(suml>sumr) l=midl+;
else r=midr-;
}
ll ans=check(l);
cout<<ans<<endl;
}

Codeforces Round #643 (Div.2)的更多相关文章

  1. Codeforces Round #643 (Div. 2)(C ~ E)

    C. Count Triangles 题目链接 : https://codeforces.com/contest/1355/problem/C 题目大意 : 给你 A , B , C , D 问有多少 ...

  2. Codeforces Round #643 (Div. 2) 题解 (ABCDE)

    目录 A. Sequence with Digits B. Young Explorers C. Count Triangles D. Game With Array E. Restorer Dist ...

  3. Codeforces Round #643 (Div. 2) B. Young Explorers (思维,贪心)

    题意:给你一组人\(a\),现在要将这些人进行分组,对于\(i\),只有某一组的人数\(\ge a_{i}\)时,\(i\)才可以加入这个组,问最多能够有多少组,(不必将所有人都选用). 题解:我们将 ...

  4. Codeforces Round #643 (Div. 2) E. Restorer Distance (贪心,三分)

    题意:给你\(n\)个数,每次可以使某个数++,--,或使某个数--另一个++,分别消耗\(a,r,m\).求使所有数相同最少的消耗. 题解:因为答案不是单调的,所以不能二分,但不难发现,答案只有一个 ...

  5. Codeforces Round #643 (Div. 2) C. Count Triangles (数学公式)

    题意:给你四个正整数\(A,B,C,D\),且\(A\le B\le C \le D\),有\(A\le x\le B\le y\le C \le z\le D\),求最多有多少组\((x,y,z)\ ...

  6. Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)

    题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. windows下部署.netcore+docker系列四 (部署程序,重点就要来了)

    前面的都是为这章做准备,加油把骚年们 PS:C# 项目可以按照流程一步步来,java 偶然其他的可以找下其他的网上资源 1.在 VS2019中 添加docker 支持 (其实也就是追加一个Docker ...

  2. jquery动态live绑定toggle事件

    $(".btn").live("click",function(){ $(this).toggle( function () { //事件 1 console. ...

  3. php 数据库备份(可用作定时任务)

    参考: https://blog.csdn.net/weixin_37616043/article/details/87721181 https://blog.csdn.net/stpeace/art ...

  4. Python 替换文本中的某些词语

    https://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python from tempfil ...

  5. ip-端口-协议等基本概念

    互联网上的计算机,都会有一个唯一的32位的地址——ip地址.我们访问服务器,就必须通过这个ip地址.   局域网里也有预留的ip地址:192/10/172开头.局域网里的ip地址也是唯一的.   NA ...

  6. 【linux三剑客】grep命令

    grep, egrep, fgrep - print lines matching a pattern grep 命令用于查找文件里符合条件的字符串. grep 指令用于查找内容包含指定的范本样式的文 ...

  7. mysql查询连接数

    最近公司的测试服务器数据库经常是连接爆满,几次加大了依旧满了. 明明只有几个人在用这个数据库,但是连接数到了三四百.于是就想是谁一直开着连接不释放,于是写了个SQL查了下连接使用情况. SQL如下: ...

  8. FastReport.Net中使用列表和数组作为报表数据源

    大多数现代报告工具允许您使用几乎任何数据库,然而,并不是所有报表工具都能以一个数据源的列表或数组来工作.本文中将展示如何使用FastReport .Net报表工具来实现. 请注意以下重要几点: 清单中 ...

  9. Vue.js中scoped引发的CSS作用域探讨

    前言 在Vue.js的组件化开发中,常常会对某个组件的style标签加上scoped属性,如<style lang='less' scoped>,这样做的目的在于使这个组件的样式不能轻易在 ...

  10. 获得CCNA和CCNP及CCIE认证的必备条件和有效期绍

    CCNA认证培训介绍 CCNA认证(CCNA-思科网络安装和支持认证助理)是整个Cisco认证体系中最初级的认证,同时它也是获得CCNP认证.CCDP认证和CCSP认证的必要条件(CCIP认证.CCI ...