当前位置:网站首页>L1-071 前世档案 (20 分) (类似二分)
L1-071 前世档案 (20 分) (类似二分)
2022-04-22 06:17:00 【S atur】
题目描述:

思路: 照我以前可能就会傻傻的去想怎么实现二叉树…也许是现在思维成熟了点,便能看出其实这就是类似于二分原理的水题。首先能够知道结论的总数,每次"y"和"n"的选择就像二分一样对半砍的操作,所以简单模拟下就行啦!
AC代码:
#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://blog.csdn.net/Satur9/article/details/123677146
边栏推荐
- [DRC 23-20] Rule violation (REQP-1712) Input clock driver - Unsupported PLLE2_ ADV connectivity.
- LeetCode - 6 - (字符串相乘、下一个更大元素<ⅠⅡⅢ>、k个一组翻转链表)
- blog同步更新通知
- 384 · 最长无重复字符的子串
- Precautions for using feign to make remote calls
- 浅谈时间复杂度与空间复杂度
- 详解冒泡序列与数组名
- SQL Server quick start
- Singleton pool, singleton bean, singleton mode
- 面试官常问的,对象分配的一般过程及特殊情况
猜你喜欢

278 · 绘制填充

顺序表之高速缓存命中率

最强操作符学习之路(C语言详解)

顺序表 增删查(找)

E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )

LeetCode - 7 - (二叉树的最近公共祖先、轮转数组、二叉树的直接、下一个排列、组合总和)

Complete a student information management system and systematically practice object-oriented, function, string and other knowledge. Realize the comprehensive application of knowledge. Use classes, fun

八大排序的思想及其代码

Cannot find interface mapping after updating HDF

Redis Advanced
随机推荐
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)
Hand tearing algorithm -- LRU cache elimination strategy, asked so often
Relationship between A5 transceiver signal VOD and pre emphasis adjustment
Codeforces Round #610 (Div. 2)
CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes)
76 · 最长上升子序列
Codeforces Round #623
C language | quick sorting
C language | bitwise operator
332 · 恢复数组
手撕算法---LRU缓存淘汰策略,问的这么频繁
Binary tree chain structure operation leetcode + Niuke (detailed explanation)
Redis進階
blog同步更新通知
LeetCode - 7 - (二叉树的最近公共祖先、轮转数组、二叉树的直接、下一个排列、组合总和)
L1-064 估值一亿的AI核心代码 (20 分) 格式错误
Precautions for using feign to make remote calls
384 · 最长无重复字符的子串
L2-005 集合相似度(set判重)