题解 CF630L Cracking the Code】的更多相关文章

前言 为什么没有人暴力快速幂啊,Ta不香嘛/kel 题意 设读入为 \(abcde\) ,求 \(acedb^5\mod{10^5}\) 的结果. \(\sf {Solution}\) 显然暴力啊. 先把每一位求好然后把新数算出来. 快速幂就行了. \(\sf {P.S.}\) 输出格式:一行,5个数字,没有间隔符. 若结果为 \(0\) 得输出00000. \(\sf {Code}\) #include<iostream> using namespace std; #define ll lo…
推荐一本书<Cracking the code interview> Now in the 5th edition, Cracking the Coding Interview gives you the interview preparation you need to get the top software developer jobs. This is a deeply technical book and focuses on the software engineering ski…
导语 所有的编程练习都在牛客网OJ提交,链接: https://www.nowcoder.com/ta/cracking-the-coding-interview 第八章 面试考题 8.1 数组与字符串 1.1 实现一个算法,确定一个字符串的所有字符是否全都不相同.假设不允许使用额外的数据结构,又该如何处理? 题解:应该先clarify上面的字符串是 ASCII 还是 unicode,假设是 ASCII,我们可以直接用256个字母表来统计.用个vector<int> st(256, 0)即可.…
Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height. 1.Divide the array equally into left part and right part, the mid value will be the root. 2.Recall the function to the left and right part of the…
1.题目描述 2.题目分析 将words 中的每一个string  直接翻译成对应的Morse 码,然后将其放入 set 中,最后返回set的大小即可,此处利用的set 中元素不重复的性质. 3.代码 vector<string> Morse = {".-","-...","-.-.","-..",".","..-.","--.","....&q…
链表结点类型定义: class Node { public: ; Node *next = nullptr; Node(int d) { data = d; } }; 快行指针(runner)技巧: 同时使用两个指针来迭代访问链表,其中一个比另一个超前一些.快指针比慢指针先行几步或者快指针与慢指针的速度呈一定的关系. dummy元素技巧: 在链表头部添加一个哑结点,通常可以简化首部或尾部的特殊情况的处理. 2.1 编写代码,移除未排序链表中的重复结点. 进阶:如果不得使用临时缓冲区,该怎么解决?…
1.1 实现一个算法,确定一个字符串的所有字符是否全都不同.不允许使用额外的数据结构. 解答:这里假定字符集为ASCII码,可以与面试官沟通确认字符串使用的字符集.由于字符集是有限的,建立一个数组模拟的Hash表记录每个字符是否出现,线性扫描一次字符串即可,复杂度O(len(s)).如果字符集较大,需要考虑空间开销,则可以用bitset来实现. bool isUnique(string s) { ]; memset(record, , sizeof(record)); size_t size =…
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format…
CSP2019 题解 D1T1 格雷码(code) 题目传送门 https://loj.ac/problem/3208 题解 按照题意模拟就可以了. 对于第 \(i\) 位,如果 \(k \geq 2^i\) 那么这一位就是 \(1\),然后把 \(k\) 变成 \(2^{i + 1} - k - 1\).否则这一位为 \(0\),\(k\) 不变. 代码 https://loj.ac/submission/687508 D1T2 括号树(brackets) 题目传送门 https://loj.…
3696: 化合物 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 165  Solved: 85[Submit][Status][Discuss] Description 首长NOI惨跪,于是去念文化课了.现在,他面对一道化学题.    这题的来源是因为在一个奇怪的学校两个化竞党在玩一个奇怪的博弈论游戏.这个游戏很蛋疼,我相信你们也没有兴趣听.    由于这个游戏涉及博弈论,因此化竞的同学就要求首长求一个类似SG函数的值.    他们手中有一种非…