Getting Zero
#include <iostream>
using namespace std;
/** Getting Zero
* either set v=(v+1) mod 32768
* or set v=(2*v) mod 32768
* 输入:第一行输入n - 表示有n个整数;
* 第二行 - 输入n个整数
* 使ai等价于0的最少步骤
*/
int n; //输入n个整数
int a[32778]; //储存整数的数组
/**< 考虑使用bfs或dfs 秉承能用b不用d的原则先试试bfs */
struct node{ //新建队列
int data;
};
int bfs(int ai)
{
struct node que[32778];
int book[32778] = {};
int head = 1,tail = 1; //首、尾指针
que[tail++].data = ai; //将需要处理的原数字入队
book[ai] = 1;
while(head < tail)
{
int x = que[head].data;
int new_x1 = (x+1) % 32768; //第一种每次加1
int new_x2 = (2*x) % 32768; //第二种每次乘2
if(!x)
break;
if(!book[new_x1])
{
que[tail++].data = new_x1;
book[new_x1] = book[x] + 1;
}
if(!book[new_x2])
{
que[tail++].data = new_x2;
book[new_x2] = book[x] + 1;
}
head++;
}
return book[0] - 1;
}
int main()
{
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
cout << bfs(a[i]) << " ";
}
return 0;
}
相关推荐
Getting Started with Raspberry Pi Zero.pdf
Key Features Get started with Raspberry Pi Zero and put all of its exciting features to use Create fun games and programs with little or no programming experience Learn to use this super-tiny PC to control hardware and software for work, play, and everything else Book Description Raspberry Pi Zero is half the size of Raspberry Pi A, only with twice the utility. At just three centimeters wide, it packs in every utility required for full-fledged computing tasks. This practical tutorial will help you quickly get up and running with Raspberry Pi Zero to control hardware and software and write simple programs and games. You will learn to build creative programs and exciting games with little or no programming experience. We cover all the features of Raspberry Pi Zero as you discover how to configure software and hardware, and control external devices. You will find out how to navigate your way in Raspbian, write simple Python scripts, and create simple DIY programs. What you will learn Understand how to initially download the operating system and set up Raspberry Pi Zero Find out how to control the GPIO pins of Raspberry Pi Zero to control LED circuits Get to grips with adding hardware to the GPIO to control more complex hardware such as motors Add USB control hardware to control a complex robot with 12 servos Include speech recognition so that projects can receive commands Enable the robot to communicate with the world around it by adding speech output Control the robot from a distance and see what the robot is seeing by adding wireless communication Discover how to build a Robotic hand and a Quadcopter About the Author Richard Grimmett has always been fascinated by computers and electronics since his very first programming project that used Fortran on punch cards. He has a bachelor's and master's degree in electrical engineering and a PhD in leadership studies. He also has 26 years of experience in the radar and telecommunications industries, and even has one of the original brick phones. He now teaches computer science and electrical engineering at the Brigham Young University, Idaho, where his office is filled with his numerous robotics projects. Table of Contents Getting Started with Raspberry Pi Zero Programming Raspberry Pi Zero Accessing the GPIO Pins on Raspberry Pi Zero Building and Controlling a Simple Wheeled Robot Building a Robot That Can Walk Adding Voice Recognition and Speech – A Voice Activated Robot Adding Raspberry Pi Zero to an RC Vehicle Playing Rock, Paper, or Scissors with Raspberry Pi Zero Adding Raspberry Pi Zero to a Quadcopter
万卷书 - 重归于好 [Getting to Zero]
重归于好 如何解决高利害关系中的裂痕 作者:Jayson Gaddis 内容提要 《Getting to Zero》(2021年)是一本处理亲密的和高利害关系中的裂痕的指南--那些与你的家人、好朋友和合作伙伴的关系。它描述了一个在关系裂痕后如何实现"重归于好 "的过程,包括获取解决方法和达成裂痕消失。 它适用于谁? * 不希望出现关系裂痕的人 * 那些受童年经历影响到人际关系的人 * 希望解决人际关系中的裂痕的所有人 关于作者 杰森-加迪斯是人际关系裂痕和解决的有关方...
Getting started with Raspberry Pi
For many years, robots and other advanced electronic wonders could only be seen on the television, movies, or in university or military labs. In recent years, however, the availability of new and inexpensive hardware and also free and open source software, has provided the opportunity for almost anyone with a little technical knowledge and imagination to build these technical wonders. The first wave of projects were fueled by Arduino, an inexpensive and simple-to-program microcontroller. The next wave was carried further by the introduction of the Raspberry Pi, an even more capable processor powered by the Linux operating system. Now there is an even less expensive, powerful microprocessor: the Raspberry Pi Zero. This little processor packs a processor powerful enough to run Linux into a small and even less expensive package. This capability, coupled with some additional power, inexpensive hardware, and free open source software provides a platform for projects that range from simple wheeled robots to advanced flying machines.
信息安全_数据安全_Getting started with AWS security.pdf
信息安全_数据安全_Getting started with AWS security 金融安全 安全 安全开发 数据恢复 系统安全
PyTorch中model.zero_grad()和optimizer.zero_grad()用法
主要介绍了PyTorch中model.zero_grad()和optimizer.zero_grad()用法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


