Day Six -- no deer in the forest

Keywords: C++

catalogue

Computer composition principle:

Data representation

Database part:

leetcode daily question:

Java learning:

Computer composition principle:

Data representation

1. Basic concepts

  • Truth: + 0101, - 0100
  • Number of machines: [x] original = 0101

2. Number of several machines

  • Original code: x = -0101, [x] original = 1101
  • Inverse code: x = -0101, [x] inverse = 1010
  • Complement: x = -0101, [x] complement = 1011
  • Code shift: x = -0101, [x] shift = 2^n + x = 0011
PS: here is my understanding of complement and shift. Complement is to convert subtraction into addition to facilitate computer design and operation, and code shift is to facilitate size comparison, which is used in the order code of floating-point numbers.
Complement—— In any modular system, subtraction can be represented by adding its complement. The simplest example is a clock with a model of 12, For example, if it's 3 o'clock now, then - 5 hours is equal to + 7 hours, both of which are 10 o'clock. Here 7 is the complement of 5.
Code shift - move the position of the data correspondence once, so that the true value of the seemingly small number is also small. For example, 0000 originally represents 0, now represents - 128, then 0001 represents - 127, until 1111 represents + 127, which is convenient for comparison.

3. Fixed point number and floating point number

Fixed point number: the decimal point is fixed x.xxxxxx, which means that the range is limited. Forget it

Floating point number: the range and precision of the number are expressed respectively.

         General format  : EEEE......EMMM.......M, Part E is the order code (range i of the number), and part m is the mantissa (precision of the number). Disadvantages: the order code and mantissa digit are not fixed, which is too flexible (there may be errors)

IEEE754 format: recite it with me----

32-bit Yes (single precision): 1-bit sign bit S + 8-bit partial index E + 23 bit effective mantissa M, and the offset value is 127.

64 bit Yes (double precision): 1-bit sign bit S + 11 bit partial index E + 52 bit effective mantissa M, and the offset value is 1023.

The true value is (for example, 32 bits) N = (-1)^S * 2^(E-127) * 1.M

Special cases of floating point numbers:

E=0,M=0: machine zero

E=255,M=0: infinity, corresponding to x/0

E=255,M!=0: non numeric NaN, corresponding to 0 / 0

ps: attach an IEEE754 document: https://files.cnblogs.com/files/flashsun/7542008-2008.pdf

4. Data verification

Basic principle: add redundancy code

Code distance: the minimum value of different binary digits between legal codes

Code distance and error detection and correction capability:

    • Code distance d > = e + 1: check e errors
    • Code distance d > = 2T + 1: correct t errors
    • Code distance d > = e + T + 1: check e errors at the same time and correct t errors. (E > = t)

PS: in my understanding, increasing the code distance is to increase the number of illegal codes. If you see an illegal code, you will find an error, and if the illegal code distance is better than the legal code, you will think what should be correct (for a simple understanding, please refer to the following figure), that is, you can correct the error. I have seen a good geometric understanding figure here, and have a careful taste of it:

For example, if there are 8 bits in total and the code spacing is 1, no error can be detected because all codes are legal codes. If the code spacing is 2, the legal code should be like 0000000000000000000110000001111. If there is an illegal code such as 00000001, an error will occur. Check one dislocation, but if two bits are wrong at the same time, it may jump to another Two dislocations cannot be detected when a legal code is applied.

If the code distance is 3, the legal code should be like 0000000000000111100111000000111111. If one dislocation 00000001 or two dislocations 00000011 are illegal codes, the error can be checked. At this time, 00000001 can be corrected to 00000000 and 00000011 can be corrected to 00000111. However, three simultaneous errors cannot be checked.

Common verification strategies: parity, CRC, Hamming

ps: the strongest video demonstration tutorial of Hamming coding: https://www.youtube.com/watch?

This part is reproduced in: [re learning computer] computer composition principle - Flash sun - blog Park

Database part:

--in the light of bookshop Database:

--1, Create a view cust_view,This view only contains the customer information of the recipient's surname Zhang. (10 points)

create view cust_view
as
select *
from customer
where receiver like 'Zhang%'

--2, utilize cust_view Add a piece of customer data with and without surname Zhang to the view. (Note: view it separately customer Table and the results of this view.) (15 points)

insert into cust_view values('ab','Zhang Qiang',1,'')
insert into cust_view values('abc','Not Zhang',1,'')

--3, Create a view cust_view1,This view only contains the customer information of the recipient's surname Zhang, with with check option Clause. (10 points)

create view cust_view1
as
select *
from customer
where receiver like 'Zhang%'
with check option

--4, utilize cust_view1 Add a piece of customer data with and without surname Zhang to the view. (Note: view it separately customer Table and the results of this view.) (15 points)

insert into cust_view1 values('abcd','Zhang Qiang',1,'')
insert into cust_view1 values('abccde','Not Zhang',1,'')

--5, Through view cust_view Delete the customer data of all recipients whose surname is Zhang and whose name is 2 Chinese characters. (10 points)

delete
from cust_view
where receiver like 'Zhang_'

--6, Through view cust_view Modify the name of a customer in the table (please give the following conditions for testing: 1 customer A customer that does not exist in the table; 2 customer A customer with no sales record in the table; 3 customer A customer with sales records in the table.) (15 points)

update cust_view
set cust_name = 'Zhang'
where cust_name = 'x'

update cust_view
set cust_name = 'Zhang'
where cust_name = 'zhangtao'

update cust_view
set cust_name = 'Zhang'
where cust_name = 'zbowen'

--7, From basic table employee and sales,Create a view sales_view,This view contains the number, name and total sales amount of the salesman. (10 points)

create view sales_view(Salesman No , full name , Total sales)
as
select emp_no , emp_name , sum(total_amt)
from employee , sales
where employee.emp_no = sales.sale_id
group by emp_no , emp_name

--8, Place in the above view E0017 The total sales amount of the salesman is changed to 6000 yuan. Can it succeed? If it fails, explain the reason. (10 points)

update sales_view
set Total sales = 6000
where Salesman No = 'E0017'
--Can't succeed , Modifying a view is actually modifying the base table , However, there is no such category as total sales amount in the basic table
--For views or functions 'sales_view' The update or insert of failed because it contains derived or constant fields.

--9, Delete all the created views above. (5 points)

drop view cust_view , cust_view1 , sales_view

leetcode daily question:

Dimensional gate

A dp dynamic programming problem of how to look and how to look. But the key is how to carry out state transition

         I need to save the princess, and I can't die, and I have to spend the minimum amount of blood. In each coordinate, I want the "path and sum from the starting point to the current point" to be as large as possible (so that I can spend the least amount of blood later to save the princess), and "the minimum initial value required from the starting point to the current point" As small as possible. The general dp is difficult to meet the transfer of two state quantities. So the princess doesn't save it, and it's rotten

        At this time, the princess shouted: silly x, wait, I'll find you. If you think backwards, you only need to get "the minimum amount of blood needed to survive at this point". Why not "the maximum path and from the starting point"? Because it's enough to go backward to this point. I can save the princess with my current HP (in short, this is the minimum weight from this point to the princess's location, so I don't need the maximum path of this point to minimize the cost of HP, because I already spend the least). In addition, because my HP is at least 1 to survive. So, There is a state transition -- DP [i] [J] = max (1, min (DP [i + 1] [J], DP [i] [J + 1]) - dungeon [i] [J]). The reason for taking max(1) is that when the amount of blood I need is negative, that is, I pick up a lot of blood, so I only need negative blood to reach the princess when I change the node. This is obviously unreasonable, because our minimum amount of blood is 1

        So the princess succeeded in finding me

class Solution {
public:
    int calculateMinimumHP(vector<vector<int>>& dungeon) {
        int n = dungeon.size() , m = dungeon[0].size();

        vector<vector<int>>dp(n + 1 , vector<int>(m + 1 , INT_MAX));
        
        dp[n][m - 1] = 1 , dp[n - 1][m] = 1;

        for(int i = n - 1;i >= 0;i --){
            for(int j = m - 1;j >= 0;j --){
                dp[i][j] = max(1 , min(dp[i][j + 1] , dp[i + 1][j]) - dungeon[i][j]);
            }
        }

        return dp[0][0];
    }
};

Java learning:

ArrayList array:

1.statement ArrayList array
ArrayList<auto> arrayList = new ArrayList<auto>();
//auto : Boolean Byte Short Integer Long Float Double Character

2.Add element
arrayList.add(int , auto);
//Int - > position, auto - > Data

3.Add all the data in one array to another
arrayList.addAll(int , ArrayList);
//Int - > position, ArrayList - > array of the same type

4.Array emptying
arrayList.clear();

5.Copy
ArrayList<String> cloneSites = (ArrayList<String>)sites.clone();
//Class C + + vector < int > b = a;

6.Determine whether the array exists x
boolean bo = arrayList.contains(x);

7.Delete qualified array elements
sites.removeIf(e -> e.contains("Tao"));
numbers.removeIf(e -> (e % 2) == 0);;


8.assignment
auto array = arrayList.get(n) <=> (c ++)auto array = array[n];

9.length,Is it empty
arraylist.size() , arraylist.isEmpty();

10.Find the first matching character , Find the last matching character
arraylist.indexOf(auto) , arraylist.lastindexOf(auto);

11.Delete an equivalent element
arraylist.remove(auto);

12.Keep overlaps
arraylist.retainAll(sites);

13.Modify element
arraylist.set(int , auto);
//int indicates subscript

I have a pot of wine to soothe the wind and dust

Posted by Desertwar on Thu, 28 Oct 2021 12:21:11 -0700