Codeforces Round 976 (Div. 2) and Divide By Zero 9.0(A,B,C)

news/2024/9/30 3:47:04

A. Find Minimum Operations

暴力枚举

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
} 
ll ksm(ll x,ll y)
{ll ans=1;while(y){if(y&1)ans*=x;x*=x;y>>=1;}return ans;
}
ll gcd(ll x,ll y)
{if(y==0)return x;elsereturn gcd(y,x%y);
}
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{ll n,k;cin>>n>>k;if(k==1){cout<<n<<endl;continue;}else{ll ans=0;while(n){if(n<k){ans+=n;break;}else{ll cnt=1;for(ll i=1;i<=60;i++){cnt*=k;if(cnt>n){cnt/=k;break;}}n-=cnt;ans++;}}cout<<ans<<endl;}
}
} 

B. Brightness Begins

通过分析可得答案使ans-sqrt(ans)>=n的最小ans值
这里要开srtl,否则怎么写都最多WA8
怎么说,一个sqrtl毁了我的梦(不是)

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef unsigned long long ll;
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
} 
ll ksm(ll x,ll y)
{ll ans=1;while(y){if(y&1)ans*=x;x*=x;y>>=1;}return ans;
}
ll gcd(ll x,ll y)
{if(y==0)return x;elsereturn gcd(y,x%y);
}
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{ll n,k;cin>>n;ll l=1,r=1844674407370955161;while(l<r){ll mid=(l+r)>>1;ll j=sqrtl(mid);if(mid-j>=n){r=mid;}elsel=mid+1;}cout<<r<<endl;
}
} 

C. Bitwise Balancing

直接分析b,c,d对应位置地二进制关系,总共8种可能
随后直接走一遍二进制所有位即可,记得答案能小就尽量小

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1)ans *= x;x *= x;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
int main()
{fio();ll t;cin >> t;while (t--){ll b, c, d;cin >> b >> c >> d;ll ans = 0;ll cnt = 1;ll g = 0;while (b||c){if (cnt > (ll)(1e18))break;ll e1 = (b & cnt);ll e2 = (c & cnt);if (e1)b -= cnt;if (e2)c -= cnt;ll op = (d & cnt);if (e1){if (e2){if (op){d -= cnt;}else{ans += cnt;}}else{if (op == 0){g = 1;}else{d -= cnt;}}}else{if (e2 == 0){if (op){ans += cnt;d -= cnt;}}else{if (op){g = 1;}}}cnt *= 2;}if (d > 0){ll cnt = 1;for (ll i = 0; i <= 62; i++){if (d & cnt){d -= cnt;ans += cnt;}if (d == 0)break;cnt *= 2;}}ll a = ksm(2, 61);//cout << a << endl;if (g==0&&ans<=a){cout << ans << endl;}elsecout << -1 << endl;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/66384.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

重命名工具 Bulk Rename Utility v4.0.0.0 中文版

​重命名工具 Bulk Rename Utility v4.0.0.0 中文版 下载地址;https://pan.quark.cn/s/67fba8bda394 介绍 当发现做一件事情,原本用工具或软件进行批量处理也能达到相同效果,可却花了数倍的时间去处理的时候,会很讨厌自己的愚蠢。当你在电脑上做某个操作时,如果觉得可能会…

开源免费 PDF 工具集 | Stirling-PDF v0.29.0

开源免费 PDF 工具集 | Stirling-PDF v0.29.0 下载地址:https://pan.quark.cn/s/f02c1b332928 介绍 这是一款使用 Docker 的基于本地托管网络的强大 PDF 操作工具。它能让你在 PDF 文件上执行各种操作,包括分割、合并、转换、重组、添加图像、旋转、压缩等。这款本地托管的网络…

jenkins--为普通用户授予指定job权限

安装Role-based Authorization Strategy 插件 我们采用RBAC 基于角色的方式进行授权,需要在jenkins上安装插件,在Jenkins的Manage Jenkins→Plugins→Available Plugins 中安装之后在Jenkins的Manage Jenkins→Security 中开启基于角色的权限策略。然后在jenkins的配置栏里就…

【CodeForces训练记录】Codeforces Round 976 (Div. 2) and Divide By Zero 9.0

https://codeforces.com/contest/2020赛后反思 没有捏,尽力了 A题 给定 \(n,k\) 每次都可以将 \(n\) 减去 \(k\) 的任意次方,想要次数最少,我们显然使用贪心,每次尽可能减去最大,但我们倒过来想,\(k^{x_1}+k^{x_2}+k^{x_3} \cdots = n\) 这东东不就是将 \(n\) 转成 \(k\)…

RocketMQ Offset管理

## Offset管理 ### 1. **Offset 的定义** - **Offset** 表示某个消息在消息队列中的位置。通过 `Offset`,可以准确地找到该消息或者从这个位置开始继续消费消息。- **maxOffset** 表示消息队列中的最大偏移量,是最新消息的 `Offset + 1`。- **minOffset** 是当前消息队列中的…

随书光盘下载使用方法

https://zhujiang.tjufe.edu.cn/tsg/2023/0620/c146a23515/page.htm随书光盘下载使用方法发布时间:2023-06-20浏览次数:3053一、网址访问 1.进入访问链接http://discx.yuntu.io,打开联图云光盘页面(需连接校园网)。 2.在搜索栏输入要搜索的图书isbn或书名。 3.在线使用光…

加入极限科技(INFINI Labs),成为搜索运维工程师!

我们是国内搜索型数据库产品厂商第一梯队的杰出代表,随着业务的快速发展,现开放岗位:搜索运维工程师( Elasticsearch/Easysearch ),如果有兴趣,请直接拉到文末,扫描二维码或将简历投递至 hello@infini.ltd。 如果您还不了解 极限科技(INFINI Labs)是谁,在做什么,需…

Vscode配置Python环境 Pytorch模块和sklearn模块的下载

Vscode配置Python环境 && Pytorch和sklearn模块安装教程 1.下载python解释器首先在python官网下一个Python解释器点击如下的就可以下载了2.python解释器安装 安装过程如下:双击exe文件安装安装成功3.下载VscodeVisual Studio 官网4.配置Vscode点击Vscode来到这个界面V…