tags: data structure algorithm Signing algorithm Find algorithm

Basic ideas of the drawing algorithm
The lottery is the folk custom of China, which is one of the forms of divination. Then, the form of a lottery can be randomly identified in the sequence. If the luck is good enough, then no matter how much element, it only needs to be aligned once, this is the most mysterious place of this algorithm, and looks with Yang Shou.
step
Process demonstration
In the sequence [ 3 , 44 , 38 , 5 , 47 , 15 , 36 , 26 , 1 , 2 ] [3,44,38,5,47,15,36,26,1,2] [3,44,38,5,47,15,36,26,1,2] Find 2
First result: Find 1 time

The second result: Find 18 times

The third result: Find 3 times

Algorithm code
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// Dump algorithm
void DrawAlgorithm(int nums[],int num,int n){
SRAND ((int) time (0)); // Generate random seeds
int count=0,randNum,bound=n*n;
While (True && Count <bound) {// Stop when the number of findings arrive in Bound
count++;
RandNum = rand ()% n; // Generate random number
if(nums[randNum]==num){
Break; // If you find Num, Break exits the loop.
}
}
Cout << "has found" << Num << ", looking for count:" << count;
}
// Print an array
void printNum(int numbers[],int n){
for(int i=0;i<n;i++){
cout<<numbers[i]<<" ";
}
cout<<endl;
}
int main()
{
int numbers[10]={3,44,38,5,47,15,36,26,1,2};
INT n = sizeof (numbers) / sizeof (NumBers [0]); // array length
Cout << "sequence is:";
Printnum (NumBers, N); // Print an array
Drawalgorithm (NumBers, 2, N); // Call the DrawAlgorithm function to perform a lottery in the NumBers sequence 2
return 0;
}
Algorithm performance analysis
I tell you with CSS, how do I spend it every day ~ code show as below...
4.3 MapReduce Through HBase's related JavaAPI, we can implement the MapReduce process accompanying HBase operations, such as using MapReduce to import data from the local file system into HBase tables...
1.1 What is Hive Hive: Data statistics tool open sourced by Facebook for solving massive structured logs. Hive is a Hadoop-based data warehouse tool that can map structured data files into a table and...
Chapter 5 NameNode and SecondaryNameNode (Interview Development Focus) 5.1 NN and 2NN working mechanism NN and 2NN working mechanism, as shown in Figure 3-14. The first stage: NameNode start (1) After...
Chapter 1 HDFS Overview 1.1 HDFS output background and definition 1.2 Advantages and disadvantages of HDFS 1.4 HDFS file block size (interview focus) Chapter 2 Shell Operation of HFDS (Development Foc...
I. Overview 1.1 What is Azkaban Azkaban is a batch workflow task scheduler launched by Linkedin. It is mainly used to run a group of jobs and processes in a specific order within a workflow. Its confi...
Chapter 1 Introduction to Sqoop Sqoop is an open source tool, mainly used for data transfer between Hadoop (Hive) and traditional databases (mysql, oracle...), which can be a relational database ( For...
Chapter 1 Introduction to HBase 1.1 HBase definition HBase is a distributed, scalable, NoSQL database that supports massive data storage and can perform real-time calculations. 1.2 HBase data model Lo...
Chapter 1 Overview of Kafka 1.2 Message Queue 1.2.1 Application scenario of traditional message queue 1.2.2 Two modes of message queue (1) Point-to-point mode (one-to-one, consumers take the initiativ...
Chapter 1 Overview of Flume 1.1 Flume definition Flume is a highly available, highly reliable, distributed mass log collection, aggregation and transmission system provided by Cloudera. Flume is based...