


由此可以推导出来,当s[i]=='L'时,下一个编号=当前编号*2-1;当s[i]=='R'时,下一个编号=当前编号*2;
- #include
- #define endl '\n'
- #define int long long
- #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- using namespace std;
- const int N=2e5+10;
- const int inf=0x3f3f3f3f;
- int n,q;
- void solve()
- {
- cin>>n>>q;
- while(q--)
- {
- int ans=1;
- string s;
- cin>>s;
- for(int i=0;i
size();i++) - {
- if(s[i]=='R')
- {
- ans=ans*2;
- }
- else
- {
- ans=ans*2-1;
- }
- }
- cout<
- }
- }
- signed main()
- {
- int t=1;
- while(t--)
- {
- solve();
- }
- return 0;
- }
3-分组【算法赛】(二分)
一、题目要求

二、 思路
三、代码
- #include
- #include
- using namespace std;
- int a[100010],k,n;
- bool check(int x)
- {
- int l=1,r=1,s=1;
- while(r<=n&&l<=n)
- {
- if(a[r]-a[l]<=x) r++;
- else
- {
- s++;
- l=r;
- }
- }
- if(s<=k) return true;
- else return false;
- }
- int main()
- {
- int t,i,x;
- cin>>n>>k;
- for(i=1;i<=n;i++)
- cin>>a[i];
- sort(a+1,a+1+n);
- int l=0,r=1e9;
- while(l
- {
- int mid=(l+r)/2;
- if(check(mid)) r=mid;
- else l=mid+1;
- }
- cout<
- return 0;
- }
-
相关阅读:
fcitx5 中文输入在 chrome/vscode 等应用中的问题及解决
自动控制原理8.2---常见非线性特性及其对系统运动的影响
1200*A. Flipping Game(前缀和)
leetcode.2401. 最长优雅子数组
机器学习入门教学——过拟合、欠拟合、模型验证、样本拆分
clion安装C++远程linux开发并调试 从装centos虚拟机到完美开发调试
什么,这年头还有人不知道404
打开、读取以及关闭目录[ opendir()、 readdir()和 closedir() ]
用Python自动生成 图文并茂的数据分析 报告
【趣味实践】Stable Diffusion绘制中秋美景
-
原文地址:https://blog.csdn.net/m0_73557680/article/details/134051537