Dashboard - Cces Round #701 (Div. 2) - Codeforces

Dashboard - Cces Round #701 (Div. 2) - Codeforces

1.Problem - A - Codeforces

题意是存在两个操作,一个是a/b,另外一个是b+1,找到最小的操作次数使得a=0

这个很明显是一个贪心思想,第二个操作很明显执行多了是不划算的,所以我考虑减少第二次操作的次数(很明显1e9以内任何一个数除以10最多就是9次)。然后再执行第一次操做,看那个数次数少一些。

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,char> PII;
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf 0x3fffffff
#define endl "\n"
#define ll long long
int a,b;
void slove(){
cin>>a>>b;
int flag=0;
if(b>a){
cout<<1<<endl;
return;
}
if(b==a){
cout<<2<<endl;
return;
}
if(b==1){
b=2;
flag=1;
}
int ans=inf;
for(int i=b;i<=b+10;i++){
for(int j=1;pow(i,j)<=1e9;j++){
if(pow(i*1.0,j)<=a&&pow(i*1.0,j+1)>a){
//cout<<i<<j<<endl;
ans=min(ans,i-b+j+1);
//cout<<ans<<endl;
break;
}
}
}
if(flag) ans++;
cout<<ans<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
slove();
}
return 0;
}

 

2.Problem - B - Codeforces

题意就是选取a数组的一个区间吗,然后一个b数组的个数。b数组应该满足四个条件

1.严格增加

2.和a的子数组有相同长度

3.所有元素都在[1,k]之间

4.和a的子数组只能有一个不同

写法已经很明显了,就是考虑每个数字可以变成哪些数。

考虑左边缘值是可以取小于a[l+1]的所有值,右边缘值差不多。

然后中间任何一个数是可以取[a[l-r], a[l+1]]

然后是区间求和,还得用前缀和维护一下。还注意一点就是不能和原数组一模一样

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,char> PII;
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf 0x3fffffff
#define endl "\n"
#define ll long long
const int N=1e5+100;
int n,q,k;
int a[N],s[N];
void slove(){
cin>>n>>q>>k;
fel(i,1,n) cin>>a[i];
for(int j=2;j<n;j++){
s[j]=(a[j+1]-a[j-1]-2);
//cout<<s[j]<<endl;
s[j]+=s[j-1];
}
fel(i,1,q){
int l,r;
cin>>l>>r;
if(l==r){
cout<<k-1<<endl;
continue;
}
ll ans=0;
ans+=a[l+1]-2;
ans+=(k-a[r-1]-1);
if(r-l>1){
ans+=(s[r-1]-s[l]);
}
cout<<ans<<endl;
}
}
int main(){
int t=1;
//cin>>t;
while(t--){
slove();
}
return 0;
}

 

3.Problem - C - Codeforces

这个题是给定一个x,y看有多少对a,b满足a%b=a/b。比如b=5可以是 1x5+1 2x5+2 3x5+3 4x5+4 这规律就明显了.

就是看每个数b的[1,b-1]倍+倍数是否在a区间内,但是这样写很明显会超时。那我就换考虑a,看a最大能表示某个数多少的倍数加上倍数,然后比这个数小的肯定也都是可以表示的。但是还是的注意只能表示一个数的[1,x-1]倍,因为如果是大于等于x倍,那a/b大于a%b是恒成立的,因为a%b的最大值是b-1。然后我就遍历倍数,2倍可以的值是从3开始。3倍从4开始,以此类推。

看程序,比如说拿20,10.举个列子。首先先把1倍+1的加上,有2-10,然后两倍的3-9,三倍的4-5。四倍时很明显(20-4)/4<=4了,就break了。

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,char> PII;
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf 0x3fffffff
#define endl "\n"
#define ll long long
#define int long long
ll x,y;
//看错题前期,裂开
void slove(){
cin>>x>>y;
ll ans=0;
if(x==1||y==1){
cout<<0<<endl;
return;
}
   //先把倍数是一的情况考虑掉
if(x<=y){
ans+=(x-2);
}
if(x>y){
ans+=(y-1);
}
for(int i=2;i<=x;i++){//这个是倍数
if((x-i)/i<=i){//如果x已经小于这个倍数下的最小值即i*(i+1)+i,那就没有希望了,后续也不需要继续遍历了。
break;
}
if(i>=y) break;//如果i已经大于y了,那根据前面最多是[1,y-1]倍,也可一break了
ans+=(min((x-i)/i,y)-i);//最多是到y,所以加个min
}
cout<<ans<<endl;
}
signed main(){
int t;
cin>>t;
while(t--){
slove();
}
return 0;
}

4.Problem - D - Codeforces

先看下题目题目的意思是是能否b矩阵的每个数都是a矩阵对于位置的倍数。然后b矩阵种每两个相邻的点差值是k^4

a矩阵的取值范围是1-16,那我考虑先把b中的每个数先变成1-16的最小公倍数,然后再考虑间隔加上k^4就好了,每个点在加上值后仍需要保证是a矩阵对应位置的倍数。这就加上对应位置的四次方不就好了!!!

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,char> PII;
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf 0x3fffffff
#define endl "\n"
#define ll long long
const int N=510;
int n,m;
int a[N][N];
void slove(){
cin>>n>>m;
int res=1;
for(int i=2;i<=16;i++){
res=res*i/__gcd(res,i);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if((i+j)&1) cout<<res<<" ";
else cout<<res+pow(a[i][j],4)<<" ";
}
cout<<endl;
}
}
int main(){
IOS
int t=1;
//cin>>t;
while(t--){
slove();
}
return 0;
}
 
posted @   silky__player  阅读(45)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示