[区块链]Let's talk about Bitcoin

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://lekkoliu.blog.csdn.net/article/details/79978134

1.Who is Satoshi Nakomoto

In October 2008, Satoshi Nakamoto published the paper named”Bitcoin: Peer-to-peer Electronic Cash System”.As of May 2017, Nakomoto has approximately 1 million bitcoins. As of December 2017, the estimated value is $15 billion.

2.Paper of Bitcoin

A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work, forming a record that cannot be changed without redoing the proof-of-work.Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending.So we provide a solution to the double-spending problem using a peer-to-peer network.

3.Bitcoin Encryption Mechanism

Some existing encryption mechanisms:
Public and private key multiple encryption.
And dual SHA-256 encryption.
这里写图片描述
Traditional signatures and verification
这里写图片描述

4. Detail about Transaction in Blockchain

We define an electronic coin as a chain of digital signatures. Each owner transfers the coin to the next by digitally signing a hash of the previous transaction and the public key of the next owner and adding these to the end of the coin. A payee can verify the signatures to verify the chain of ownership.Using its characteristics, we can form a chain of transfer records that can be traced back to the earliest transactions.
这里写图片描述

5.The double flower problem that had to be solved

The problem is that the payee cannot verify that one of the owners did not spend the second coin in another place.A common solution is to introduce a trustworthy central authority or use miners to check the double expenses of each transaction.

6.Time recorder: Timestamp Server

A timestamp server works by taking a hash of a block of items to be timestamped and widely publishing the hash. The timestamp proves that the data must have existed at the time, obviously, in order to get into the hash. Each timestamp includes the previous timestamp in its hash, forming a chain, with each additional timestamp reinforcing the ones before it.In simple terms, blockchain is not just a value chain but also a timeline.
这里写图片描述

7.Bitcoin Consensus Mechanism:PoW

Bitcoin uses the consensus mechanism PoW.
For a detailed explanation of the consensus mechanism, please refer to this article《[区块链]共识算法(POW,POS,DPOS,PBFT)介绍和心得

In fact,Trust by majority decision making.
The majority decision is represented by the longest chain, which has the greatest proof-of-work effort invested in it. If a majority of CPU power is controlled by honest nodes, the honest chain will grow the fastest and outpace any competing chains.
Protection:To modify a past block, an attacker would have to redo the proof-of-work of the block and all blocks after it and then catch up with and surpass the work of the honest nodes.

8.Blockchain Network and Logical Nodes Workflow

Nodes always consider the longest chain to be the correct one and will keep working on extending it. If two nodes broadcast different versions of the next block simultaneously, some nodes may receive one or the other first.
In that case, they work on the first one they received, but save the other branch in case it becomes longer. The tie will be broken when the next proof of-work is found and one branch becomes longer; the nodes that were working on the other branch will then switch to the longer one.

The following is the network propagation execution logic:
1) New transactions are broadcast to all nodes.
2) Each node collects new transactions into a block.
3) Each node works on finding a difficult proof-of-work for its block.
4) When a node finds a proof-of-work, it broadcasts the block to all nodes.
5) Nodes accept the block only if all transactions in it are valid and not already spent.
6) Nodes express their acceptance of the block by working on creating the next block in the chain, using the hash of the accepted block as the previous hash.

9.How to motivate miners to mine to maintain the overall blockchain network?

By convention, the first transaction in a block is a special transaction that starts a new coin owned by the creator of the block.
(50BTC @2008-2012, 25BTC@2012-2016, 12.5BTC@2016-2020)
This adds an incentive for nodes to support the network, and provides a way to initially distribute coins into circulation, since there is no central authority to issue them.The steady addition of a constant of amount of new coins is analogous to gold miners expending resources to add gold to circulation. In our case, it is CPU time and electricity that is expended.

10.What are the SPV often spoken by geeks? There is a winding Merkle tree

SPV is short for Simplified Payment Verification.
A user only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he’s convinced he has the longest chain. He can’t check the transaction for himself, but by linking it to a place in the chain, he can see that a network node has accepted it, and blocks added after it further confirm the network has accepted it.

The main structure is as follows:
这里写图片描述

In simple words, the mechanism and structure of SPV or Merkel tree ensure that the node determines the longest chain when the network spreads, and the consensus of the entire blockchain can be maintained. (Seemingly still winding?)

11.How about Privacy?

for blockchain, the necessity to announce all transactions publicly precludes this method, but privacy can still be maintained by breaking the flow of information in another place: by keeping public keys anonymous.

12.Bitcoin Dilemma

As complexity of mining operation increases – the mining profits will drop or become negative even for large Bitcoin mining farms. Please refer 13.1.

New faster mining hardware comes out before you can barely pay off your existing mining hardware.Once Bitcoin price stops growing or drops combined with complexity increases will drive miners to switch to a different coin mining or stop operations.Gradually as miners leave the network – the security of the network will decrease making 51% attack more likely. 

Alternatively ever increasing transaction costs are making Bitcoin impractical for micro-payments.
That’s why BCC want to change this situation.


13.Some charts

Latest Bitcoin Mining Difficulty (Difficulties Increasing)
这里写图片描述

Bitcoin Market Value Chart (Investment Risk, Volatility Over Stock Market)
这里写图片描述

展开阅读全文

Let's play UNO

08-25

Problem DescriptionnUno is a famous card game played with a specially printed deck. It's verynpopular as a funny game in a party. nA so-called "official rules" is presented at the Wikipedia, but there are a lot of different extended rules all over the nworld according to their specific needs. nnnn In this problem, you are required to obey our rules introduced below:n The Uno deck consists of cards of 4 colors: red(R), green(G), blue(B), and yellow(Y). nEach color has two kinds of cards, number cards and action cards. nThe ranks in number cards are 0-9. There are 3 "action" cards in each color, labeled "skip"(S), "draw two"(D), and "reverse"(R). nThe functions of the actions will be described afterwards. nFor each color, there are two copies of each positive number card and action card, but only one zero card, producing 25 cards in total.n Besides, there are also special black action cards called "wild cards", "wild"(WC) and "wild draw four"(WF). nThere are four "wild" and "wild draw four" cards each. Hence, there are 108 cards in total.n In this problem, a card is marked with an ID of two characters length, the first is the color (R, G, B, Y, W) while the second is the rank (0-9, S, D, R, C, F). nFor example, the ID of red 2 is R2, the yellow reverse is YR, the wild cards are WC and WF.n Supposed there are n players numbered from 1 to n clockwise. nBefore playing, players take turns(in the order of 1, 2, ... n) to pick seven successive cards from the stock. nThe top card of the remaining stock is exposed to start the game, treated as if player 1 dropped that card. nThe exposed card will never be WC or WF in this problem. nThen the game begins clockwise (next player is 2), or counter-clockwise (next player is n) if the top exposed card is a reverse. n At each turn, a player may drop a card from their hand that matches the color or rank of the top exposed card (e.g., if the top card is R3, you can drop R5 or G3; nif the top card is RD, you can drop R3 or GD) or play a WC. nWhat's more, if the player has a WF and no other legal cards to drop, he can drop the WF. nThen the card dropped just now becomes the top exposed card.n If a player has no legal cards, he must draw the top card of the stock and place it in his hand. nAfter dropping a single card or drawing, the next player clockwise takes a turn, or counter-clockwise when the reverse is in effect.n When a player drops down to only one card, that player is required to say "uno" to warn other players. nThe game ends when a player drops all his/her cards, or the stock is emptied but the current player has to draw a card. nIf the last card is an action card, the special effect still occurs.n When the game ends, all players count the number of points pertaining to the values of the cards in their hands. nNumber cards worth the face value on them, colored special cards worth twenty, and wilds worth fifty, e.g., R2 worth 2, G0 worth 0, BD and YS worth 20, WC and WF worth 50.n The descriptions of the action cards:nnnn Now here comes the problem. nThere are N people playing Uno under the rules mentioned above. Given the sequence of the 108 cards of the stock, you are asked to simulate a Uno game. n At each turn, the player will always drop a card if permitted. nIf there are more than one choices, the player will drop the card with the largest point. nIf still a tie, he will choose the one whose ID is the smallest alphabetical order.n When a player drops WC or WF, he has to name a color. nThe first time he will name red, the second time he will name green, the third time blue, the fourth time yellow, the fifth time red again, and so on.n When the game ends, you should output the final score of each player, and we also want to know how many times each player calls "Uno". n nnInputnThe first line of the input file contains a single number: the number of test ncases to follow. Each test case has two lines:nThe first line contains the number of players N , with 2<=N<=10.nThe second line contains 108 IDs of the Uno cards, separated by one space. nEach ID is two characters long as introduced in the description above.n nnOutputnFor each test case, output two lines:nThe first line are N integers, the ith integer is the final score of player i.nThe second lines are also N integers, the ith integer shows how many timesnplayer i calls "Uno".n nnSample Inputn1n2nR9 RD RD RS RS RR RR nB0 B1 B1 B2 B2 B3 B3 nG0 GD GD GS GS GR GR G9 G9 G8 G8 G7 G7 G6 G6 G5 G5 G4 G4 G3 G3 G2 G2 G1 G1 nY0 Y9 Y9 Y8 Y8 Y7 Y7 Y6 Y6 Y5 Y5 Y4 Y4 Y3 Y3 Y2 Y2 Y1 Y1 YD YD YS YS YR YR nR9 R8 R8 R7 R7 R6 R6 R5 R5 R4 R4 R3 R3 R2 R2 R1 R1 R0 nB4 B4 B5 B5 B6 B6 B7 B7 B8 B8 B9 B9 BD BD BS BS BR BR nWC WC WC WC WF WF WF WFn nnSample Outputn249 0n0 1 问答

Let's Go to the Movies

12-31

DescriptionnnA favorite pastime for big families in Acmestan is going to the movies. It is quite common to see a number of these multi-generation families going together to watch a movie. Movie theaters in Acmestan have two types of tickets: A single ticket is for exactly one person while a family ticket allows a parent and their children to enter the theater. Needless to say, a family ticket is always priced higher than a single ticket, sometimes as high as five times the price of a single ticket.nnIt is quite challenging for families to decide which ticket arrangement is most economical to buy. For example, the family depicted in the figure on the right has four ticket arrangements to choose from: Seven single tickets; Two family tickets; One family ticket (for adam, bob, cindy) plus four single tickets for the rest; Or, one family ticket (for bob and his four children) plus single tickets for the remaining two.nnWrite a program to determine which ticket arrangement has the least price. If there are more than one such arrangement, print the arrangement that has the least number of tickets.nnInputnnYour program will be tested on one or more test cases. The first line of each test case includes two positive integers (S and F) where S is the price of a single ticket and F is the price of a family ticket. The remaining lines of the test case are either the name of a person going by him/herself, or of the form:nnN1 N2 N3 … Nknnwhere N1 is the name of a parent, with N2… Nk being his/her children. Names are all lower-case letters, and no longer than 1000 characters. No parent will be taking more than 1000 of their children to the movies :-). Names are unique, the name of a particular person will appear at most twice: Once as a parent, and once as a child. There will be at least one person and at most 100,000 people in any test case.nnThe end of a test case is identified by the beginning of the following test case (a line made of two integers.) The end of the last test case is identified by two zeros.nnOutputnnFor each test case, write the result using the following format:nnk. NS NF TnnWhere k is the test case number (starting at 1), NS is the number of single tickets, NF is the number of family tickets, and T is the total cost of tickets.nnSample Inputnn1 3nadam bob cindynbob dima edie fairuz garyn1 2njohnnpaulngeorgenringon1 3na b cn0 0nSample Outputnn1. 2 1 5n2. 4 0 4n3. 0 1 3 问答

Let’s Hit Our Head!

03-10

问题描述 :nnnKingdom LHOH is celebrating its annual carnival again!This time another crazy game is now on show.N*N piles of brick here lying on the ground in a straight line, and N brave fellows have attended.nFirst they should each choose a distinct piles brick to stand behind, forming a line parrelling to the brick, and facing the same side, watching at his piles of brick.nThen their captain can yelled out 3 commands, described below:nA "LEFT!" Every one should move so that he is behind the left piles of the original one. nB "RIGHT!" Every one should move so that he is behind the right piles of the original one. nC "HIT!" Every one should break all the piles of brick before him with only his head slamming them.nnA little constraints are showed below:nIn every step, when command A or B have been yelled out, no one should move outside, that is, for everyone after his moving, brick(even breaked up) is there before him,and when command C is to be yelled out, intact piles of brick must be there before every one, so that he cannot slamming brick that it already breaked up, and only that is fair to everyone.nNot until all piles of brick have been successfully breaked up with the brave fellows’ heads, this game is successfully finished.nNow the question is,the crazy captain wants to know how many initial options are there,satisfying for each initial option he always chooses the first piles, other members choose their own distinct ones,and the game can be finished successfully at the same time?nWe assume the other members except the captain cannot be told out. nn输入:nnnFirst there’s an integer T(T<=15000) indicating the scenary numbers.nThen there’s T lines represented for the scenaries, with an integer N(1<=N<=10^12) in each line. n输出:nnnFirst there’s an integer T(T<=15000) indicating the scenary numbers.nThen there’s T lines represented for the scenaries, with an integer N(1<=N<=10^12) in each line.n样例输入:nn10n1n2n3n4n8n16n6469693228n6469693229n6469693230n1024n样例输出:nn1n2n2n6n20n70n84n14n8787513806478134n184756 问答

没有更多推荐了,返回首页