(intXintchain) { intk=0; SZ++; POS[X]=sz;//assigning the number of X nodes in the segment treebelong[x]=chain; for(intI=HEAD[X]; I I=e[i].next)if(deep[e[i].to]>deep[x]size[e[i].to]>Size[k]) k=e[i].to;//Select subtree Max son inherit heavy chain if(k==0)return; DFS2 (K,chain); for(intI=HEAD[X]; I I=e[i].next)if(deep[e[i].to]>deep[x]k!=e[i].to) DFS2 (e[i].to,e[i].to);//The rest of the sons new open heavy chain}intLcaintXintY//Seeking LCA{ if(deep[x]Deep[y]) swap (x, y); intt=deep[x]
Advanced Data StructuresOne, left bias tree oblique heapMerge, INSERT, deleteHit MarkstructNode {intFA,L,R,W,DEP} TREE[MX];intMerge (intK1,intK2)//The return value is the root node{ if(k1==0|| k2==0)returnk1+K2; if(k1.valk2.val) Swap (K1,K2); TREE[K1].R=Merge (TREE[K1].R
straight line and used as the other two sides of the rectangle.
5. traverse all adjacent two points of the convex hull and run the new two ~ 4. Use the rectangle with the smallest area as the result.
Normally, the rectangle goes through five random points.
The result is as follows:
The Matlab code is as follows:
Clear all; close all; clc; n = 30; P = rand (n, 2); ind = convhull (P (:, 1), P (:, 2 )); L = length (IND); hull = P (IND, :); % random dot Convex Hull area = inf; for I = 2: l p1 = hu
]) print (obj) ########## Result:counter ({22:2, 33:1, 11:1}) Counter ({22:3, 11:2, 33:1, 44:1}) Counter ({22:2, 33:1, 11:1, 44:0})Second, ordered dictionary (ordereddict)An ordered dictionary (ordereddict) is a subclass of a dictionary that records the order in which elements are added, based on a dictionary#导入collections模块import Collectionsdic = collections. Ordereddict () dic[' k1 '] = ' v1 ' dic[' k2 '] = ' v2 ' dic[' K3 '] = ' v3 ' Print (DIC) ##
1.hash type OperationImport Redispool = Redis. ConnectionPool (host= "192.168.48.131", port=6379, db=0) R = Redis. Redis (Connection_pool=pool)#hash类型操作: is a name corresponding to a dictionary#语法 Hset (name, key, value)A key-value pair is set #name the corresponding hash (does not exist, the key-value pair is created; otherwise, the key-value pair is modified)# syntax parameter explanation:Name:redis's hash nameKey:key1 corresponding to the key in the hashValue:value1 value in the corresponding
1, the following variables (TU is a tuple), please implement the required functionsTu = ("Alex", [One, one, 11, {"K1": ' V1 ', "K2": ["Age", "name"], "K3": (, 22, 33)}, 44])0 10 1 20 1 2A. Describing the attributes of a tuplePrint ("Tuples are immutable lists, which can put data of any data type, can be queried, can be looped, can be sliced, but cannot be changed.")B. Can you tell me if the first element in the TU variable, "Alex", could be modified?P
and then enters the United States from the Great Lakes area, arrive in Detroit, the city of cars.
The number of domestic flights for international flights is larger. Most of the domestic flights are 6 in each row, while the number of international flights is 9 in each row, and the size of large flights is also stable. However, 12 hours of sitting is indeed quite miserable, and this time is still the time for Chinese people to go to bed, the situation can be imagined. After arriving in Detroit,
According to foreign media reports, the United States Colorado State Denver Police said in Thursday, the United States "spam King" Edward Davidson (Edward Davidson) in Sunday after the successful escape, has been in Thursday near the Denver first shot his wife and three-year-old daughter, and then shot himself.
Denver prosecutor Troy Eder (Troy Eid) said police
A dictionary is another mutable container model and can store any type of object. Each key value of the dictionary (Key=>value) is split with a colon (:), each pair is separated by a comma (,), and the entire dictionary is enclosed in curly braces ({}) , as shown in the following format:1. Basic institutionsinfo = { "K1""v1"# Key-value pairs " K2 " " v2 " # Key-value pairs }2, the dictionary value can be any value#!/usr/bin/env pythoninfo = {
Orderddict is a supplement to the dictionary type, and he remembers the order in which the dictionary elements were addedNote: The dictionary default loop only outputs key1 ImportCollections2DIC =collections. Ordereddict ()3dic["K1"] ="v1"4dic["K2"] ="v2"5dic["K3"] ="v3"6 Print(DIC)7 #the principle of implementation: equivalent to a list (ordered) to maintain the dictionary (unordered) ordering, the following is only for understanding8 #dic = {"
type. It remembers the order in which dictionary elements are added.>>> From collections import OrderedDict>>> Dic = OrderedDict ()>>> Dic ['k1 '] = 'v1'>>> Dic ['k2'] = 'v2'>>> Dic ['k3'] = 'v3'>>> Print (dic)OrderedDict ([('k1 ', 'v1'), ('k2', 'v2'), ('k3 ', 'v3')])Basic operation method: 1. Get all keys of the dictionary >>> Dic. keys ()2. Retrieve all dictionary values >>> Dic. values ()3. The items ()
dictionary list_of_pairs = c. items () # convert to (elem, cnt) format list Counter (dict (list_of_pairs) # convert from (elem, cnt) format list to Counter Class Object c. most_common () [:-5:-1] # retrieve the minimum count of five elements c ++ = Counter () # Remove 0 and negative values
4. OrderedDict-dict subclass that remembers the order entries were added
The OrderedDict type is an ordered dictionary, which is actually an order more than a common dictionary.
Import collectionsdic = c
This is a creation in
Article, where the information may have evolved or changed.
Often people think that iota is 0, but that is not the case.
To be exact, when Iota appears in the first line following the keyword const, the iota is 0, when the second row appears, the Iota is 1, and so on, and when Iota encounters the const again, it resets to 0.
Description of Golang spec about Iota: Http://golang.org/ref/spec#Iota
Let's look at a few pieces of code.
1, Example 1
Package Mainimport "FMT" Const
Ural 1780 test Instructions:Input a binary number and the binary number of the gray code, but there are some positions are not sure, write the program to restore it, unable to restore output impossible, multi-solution output ambiguity.Ideas:In fact, it is a common problem to be confused.Definition of gray code:
G i =B i 1 ? B i , G 0 = B 0
(The I-bit gray code equals the XOR value of the first-bit binary code and the I-1 binary code)And then according to the def
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.