当前位置:网站首页>L1-071 previous life files (20 points) (similar two points)
L1-071 previous life files (20 points) (similar two points)
2022-04-22 07:31:00 【S atur】
Title Description :

Ideas : As before, I might be silly to think about how to realize binary tree … Maybe it's a little mature now , It can be seen that this is actually a water problem similar to the dichotomy principle . First, you can know the total number of conclusions , Every time "y" and "n" The choice of is like the operation of cutting half and half , So just a simple simulation !
AC Code :
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5+10;
int n, m, sum;
string s;
signed main()
{
cin >> n >> m;
sum = pow(2, n);
// cout << "sum: " << sum << endl;
while(m --){
cin >> s;
int l = 1, r = sum;
for(int i = 0; i < n; i ++){
int mid = (l+r)/2;
if(s[i]=='y') r = mid-1;
else l = mid+1;
}
cout << l << endl;
}
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220616059843.html
边栏推荐
- L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)
- 189. Rotation array
- LeetCode - 1 - (树的子结构、组合、螺旋矩阵、全排列<ⅠⅢ>)
- 843 · 数字翻转
- LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
- [solution] Luogu p6186 [noi online 1 improvement group] bubble sorting: [bubble sorting] and [reverse order pair] problems
- Why is the data stored in the leaf node of the non primary key index the primary key value
- E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )
- D. Determine the Photo Position (简单找子串)(2021牛客暑期多校训练营1)
- 437. Path sum III
猜你喜欢

363 · 接雨水

最小圆覆盖(计算几何基础)

This关键字详细概述

L2-004 is this a binary search tree? (first order input & judgment search Binary Tree & second order output)

Redis advanced

Relationship between A5 transceiver signal VOD and pre emphasis adjustment

H.Happy Number (进制转换/第n个特殊数)(2021牛客暑期多校训练营9 )

B. Ball Dropping (简单几何计算 / 相似三角形) (2021牛客暑期多校训练营1)

二叉树链式结构操作LeetCode+牛客(详解)

Beyond compare solution to "authorization key has been revoked"
随机推荐
Leetcode - 7 - (nearest common ancestor of binary tree, rotation array, direct of binary tree, next permutation, combined sum)
树+二叉树 详解 详解 +Top-k问题
L2-001 紧急救援 (最短路Dijkstra的扩展 - 最短路径数&路径最大权值)
详解冒泡序列与数组名
838 · 子数组和为K
队列(详解)——手撕队列习题
CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes)
Error: (vlog-2892) Net type of 'i_ yc422' must be explicitly declared.
接口的讲解以及使用
浅谈时间复杂度与空间复杂度
332 · recovery array
A. Alice and Bob (博弈?思维&暴力)(2021牛客暑期多校训练营1)
LeetCode - 6 - (字符串相乘、下一個更大元素<ⅠⅡⅢ>、k個一組翻轉鏈錶)
A. Weird Flecks, But OK (计算几何&三维最小圆覆盖)(2021年度训练联盟热身训练赛第一场)
Two algorithm questions for Microsoft intern interview -- 20220119
1232 · 爆破气球的最小箭头数
Idea does not display the run dashboard view window
384 · 最长无重复字符的子串
Codeforces Round #588 (Div. 2) C D
Codeforces Round #774 (Div. 2)