简单的梯度下降代码实践

2018CCPC网络预选赛1010/hdu6447 离散化/DP/线段树

http://acm.hdu.edu.cn/showproblem.php?pid=6447

题意:
从(0,0)(0,0)走到(10^9,10^9)(10^9,10^9),其中每次只能往(x+1,y),(x+1,y+1),(x,y+1)三个目标走,期间有n个村庄,但每个村庄只能从其(x-1,y)或(x,y-1)走到其上才能获得该村庄的金钱vk,问最后可以获得的最大金钱

分析:
最大值规划问题很自然的会想到用DP做,但此处单纯对每个城镇进行DP的话每次需要遍历所有城镇,复杂度是O(n^2),难以解决.
另一个想法是以坐标作为基准进行DP,这样的话我们需要先将城镇坐标进行离散化,然后用dp[n]储存到达第n列时达到的最大金钱,并将城镇按照从上到下,从右到左进行排序.
之后迭代遍历每个城镇,对于第n列的某城镇k,dp[n]=max(dp[n],max(dp[1~n-1)+vk),城镇的排列顺序保证了迭代完成后dp[]能计算出到达每一列时的最大金钱,而区间查询可以使用线段树或树状数组进行优化,
最终达到的复杂度为O(nlogn)

代码如下:(事实上由于这个线段树写的特别渣,导致最终通过时间大概是990ms左右,也有TLE的可能…)

素数筛法/Sieve out prime number

埃拉托斯特尼筛法(sieve of Eratosthenes)简称埃氏筛,是一种比较简单且也”相对”高效的素数筛法.
这个筛法的核心是通过遍历每个素数的倍数并将其标记为合数以获取最终的素数表.
step:
1.创建一个数组用来保存信息,先假设所有数字都是素数(except 1).
2.遍历2(首个素数)的所有倍数直到数组末尾,将这些数标记为合数.
3.在数组中找到下一个素数并重复第2步的操作,只到没有更大的素数为止.
当该算法结束时,数组中剩余的素数即是最终的素数表了.

Sieve of Eratosthenes,from Wikipedia
image from Wikipedia

code:

这个算法的复杂度大概是O(nlglgn),在大部分情况下效果也不差了.

 

欧拉筛法(Sieve of Euler)
//TODO

如何制作一种替代币/how to make an altcoin

translated form http://dillingers.com/blog/2015/04/18/how-to-make-an-altcoin/
supported by earthledger

Okay, I’m going to preface this article by asking you two things:
Okay, 让我问您两件事来开始这篇文章.

First, WHY do you want to create an altcoin?
首先,为什么您想创建一种替代币

This is a starting point.  If you don’t have some original ideas, and the ability to actually read and write C++ code to implement them, then you’re going to create something that can’t do anything Bitcoin can’t do, and in that case there’s no point in releasing it.  So don’t.
这是一切的出发点.如果您没有一些原创的想法,或者没有能力去实际的阅读和编写C++代码去实现它们,那么您制作的东西不会超过比特币所能做的,在这种情况下发行您自己的币就没有意义了,所以 别这么做.

If you want to release an altcoin, pump it, get a lot of suckers to invest their money, bribe a cryptocurrency exchange to put up a trading market in it, and then dump a bunch of premined coins on the inflated market and leave all the suckers holding the bag, then “don’t” isn’t quite all the advice I want to give you.  Additionally, “go die in a fire”.
如果您想发行一种替代币,让蠢货们投资他们的钱,通过贿赂上一个交易所,然后在膨胀的市场里留下一堆预付币并让那群蠢货留着他们的钱包.那么”不要这么做”并不是我要给您的全部建议,此外,我还建议您去”死在火中(go die in a fire)”

So. If you have a reason to create an altcoin – something you’ve thought of a way to do that won’t ever get into Bitcoin itself and which would enable your ideal cryptocurrency to function in ways Bitcoin can’t – then I have a second question for you.
所以.如果您有理由去创建一种替代币–您想到了一些方法去做比特币本身做不到的事并且这将让您的理想加密货币去以和比特币不同的方法运作–那么,让我问来您一个问题.

Can you commit yourself to maintaining a release?
您能向您自己承诺去维护一个发行版吗?

This is serious. If you’re going to release an altcoin, you’re going to have a forty-hour-a-week job supporting it. You’re going to have to spend time every day just reading the code to make sure you know what every part of it does. And you’ll need that knowledge, because you’re going to have to figure out technical problems and make technical fixes, in emergency situations, when some joker attacks your block chain. Bitcoin has some stability because Bitcoin has a majority of the hashing power on the planet devoted to it. Your altcoin isn’t even a fart in a hurricane yet, and your proof-of-work block chain will be subject to attacks that you’re going to have to either anticipate or counter in real time. Reading code every day is preparation. The only way you can find your way around it fast enough to make fixes is if you know it inside and out. Anyway, you can have a full time job, or a social and family life, and maintain a released altcoin – but probably not both, unless you’re one of those people who regards sleep as a wholly inadequate time-wasting substitute for caffeine.
这是一个很严肃的事.如果您要发行一种替代币,您将需要去做一份每周四十个小时(全职)的工作去维护它.您将需要每天都花费时间去阅读代码以确定您知道它每部分的工作流程.并且您也需要这些知识,因为在未来一些joker攻击您的区块链的时候,您将不得不在紧急情况下找出技术问题并进行技术修复.比特币具有一定的稳定性因为比特币有这个星球上主要的hashing算力去维持它.但您自己的替代币在风暴中甚至不算一个屁,并且您的POW区块链可能会遭受您必须要实时预测或反击的攻击.每天阅读代码甚至只是一个准备工作.想要快速找到解决方法的唯一办法是了解它内外的每个部分.无论如何,您将有一份全职工作/良好的社交和家庭生活/维护一个发行的替代币,但您可能只能在其中选一个,除非您是那些认为睡眠是完全不适合浪费时间的咖啡因替代品的人之一(也既完全不睡觉?).

Now, with all that said, this article will cover only the beginning of the process: shamelessly cloning an existing coin. Whatever innovations you intend to make, I can’t anticipate them, so there’s no guide here to making them. You have to read the code until you understand it well enough to make them yourself. For purposes of this article, we’re going to use Bitcoin’s 0.10 source code, we’re going to make a near-clone of it named “Newcoin”, and I’m going to be working with Debian Jessie.
现在,尽管如此,本文仅仅只涉及这个过程的开始:无耻地克隆现有的数字货币.我无法预料到您打算做什么创新,所以这里没有指导这些事.您必须阅读代码,直到您完全理解它为止.出于本文的目的,我们将使用比特币的0.10源代码,我们将对其进行近乎克隆,命名为“Newcoin”,在此我将与Debian Jessie合作.

Get the Source Code
Open up a command line shell. Make a new directory in your home directory named src. It’s where you’ll be working. So your first three command lines are
获取源代码
打开一个命令行shell,在你的home目录中创建一个新文件夹并命名为src.这是你的工作目录.所以你的first三个命令是

Now use your web browser to go to https://bitcoin.org/en/download, find the button in the lower right corner of the box that says “source code”, and get the archive. Its name should bebitcoin-0.10.0(1).tar.gz. Copy it into your new directory and unpack it using the commands:
现在,使用你的浏览器打开 https://bitcoin.org/en/download, 找到右下角显示”source code”的按钮,然后获取这个档案.它的名字应该会是bitcoin-0.10.0(1).tar.gz.
comment:这部分的链接已经改变了,现在可以在这个链接下载到0.10.0版的源码 https://github.com/bitcoin/bitcoin/archive/v0.10.0.tar.gz
comment2:似乎…v0.10.0的版本无法在某些版本的boost库下正常编译,也许可以选择使用v0,10.3版的源码https://github.com/bitcoin/bitcoin/archive/v0.10.3.tar.gz
ref:https://github.com/bitcoin/bitcoin/issues/6113
把它复制到你的新工作文件夹内并且用下面的命令解压它:

In the above two commands, the backslashes before the parens are because there are actual parentheses in the filename, and if you just type them, your shell will try to interpret the command differently. And the directory ~/Downloads is where stuff lands on my system when I download it with my web browser. If you’ve got yours set up differently, you should adjust the command to use your download directory instead, whatever it’s named.
在上面两个命令中,括号之前的反斜杠是因为文件名中有真正使用的括号,如果你只是直接输入文件名,你的shell将尝试以不同的方式解释命令.目录~/ Downloads是我用我的网络浏览器下载文件后存放的地方.如果您的设置不同,则应调整命令以使用您的下载目录.

And the last command makes a clone of the bitcoin-0.10.0 directory named newcoin – with its own copies of all the files you just extracted. You should use whatever you want thename of your new altcoin to be for the name of this directory.
最后一个命令克隆了这个bitcoin-0.10.0目录并将其命名为newcoin – 它拥有你刚刚提取的所有文件的副本.您应该使用您想要的任何新的替代币名字作为此目录的名称.

Get the stuff the code depends on
Next, you need to get all the stuff that building Bitcoin depends on. Here’s a sequence of commands to do that.
获取代码依赖的内容
接下来,您需要获得构建比特币所依赖的所有内容.下面这系列命令可以帮助你解决依赖问题.

Now, I cheated a little bit here. Debian has a Bitcoin package available in its ‘sid’ distribution, but it doesn’t use the same version of the source code we want to work with. The first line makes you root, because root has the permission to modify sources.list and install packages. It’ll ask for the root password and you need to enter it. The second line changes sources.list to add the sid sources to what’s available to your apt command. The third line tells Debian to download all the meta-information about those sources, so it knows what the build process for these packages require. The fourth and fifth lines tell it to download and install all the stuff you would need to build the sid Bitcoin source code package. But you didn’t download the sid source code package, you downloaded the new source code directly from the site instead. The cheat is that the dependencies are the same, so this is an easy way to get everything you need to build. And the last line is to quit being root.
现在,我在这里作了一点欺骗.Debian在其’sid’发行版中有一个Bitcoin包,但它不使用我们想要使用的相同版本的源代码.第一行使您成为root用户,因为root具有修改sources.list和安装包的权限.它会询问root密码,您需要输入密码.第二行更改sources.list以将sid源添加到apt命令可用的内容中.第三行告诉Debian下载有关这些源的所有元信息,因此它将知道这些包的构建过程需要什么,第四行和第五行告诉它下载并安装构建sid比特币源代码包所需的所有东西.但是你没有下载sid源代码包,而是直接从网站下载了新的源代码.这个hack是因为它们的依赖关系是相同的,所以这是一个简单的方法去获得构建所需的一切.最后一行是退出root.
comment:显然,在非debian的系统上不能这么用,也许可以尝试使用该命令代替 apt-get build-dep libbitcoin-dev

Test build to make sure your setup works
The next step is build Bitcoin just to make sure you got everything. So let’s do that. Here are some more command lines. Some of these may take a few minutes to run to completion; this is normal.
测试构建以确保你的设置正常工作
下一步是尝试构建Bitcoin,以确保你能得到一切.So let’s do that. 这里有一些命令行.其中一些可能需要几分钟才能完成;这是正常的.

How all That Worked (The Automake System)
aclocal generates a file called ‘aclocal.m4′ which is a bunch of macro definitions and so on that automake works with. There was already an aclocal.m4 in the directory, but it is for a version of automake that probably isn’t the one installed on your Jessie system.
这些东西是如何工作的(Automake系统)
aclocal生成一个名为’aclocal.m4’的文件,这是一组宏定义并且接下来automake将和它你起工作.这里已经有了一个aclocal.m4在这个文件夹内,但它可能不适用于您现在所使用的系统.

automake –add-missing invokes automake, which uses those macros and the file Makefile.am, which is already there, to create another file named Makefile.in. The –add-missing argument tells it to create a couple of standard macro packages that automake uses, because the Bitcoin sources didn’t provide them; it didn’t need to provide them, because it uses the defaults provided by –add-missing.
automake –add-missing调用automake,它使用那些宏和已存在的Makefile.am文件来创建另一个名为Makefile.in的文件. –add-missing参数告诉它创建一些自动使用的标准宏包,因为比特币源码没有提供它们; 它也不需要提供这些东西,因为它使用-add-missing提供的默认值.

Makefile.in specifies what configuration needs to know and do and saves that in a shell script named configure. Then ./configure runs that shell script, which tests a lot of things on your system, finds what’s available to build with and link against, and generally figures out in detail how to build the Bitcoin sources it’s looking at, saving that information in a makefile. The –with-incompatible-bdb argument says it’s okay with you to use a version of the Berkeley database later than the one the original Bitcoin client was built with.
Makefile.in指定什么是configure所需要知道和要做的,并将其保存在名为configure的shell脚本中.然后./configure运行那个shell脚本,它会测试你系统上的很多东西,找到可以构建和链接的东西,并且通常会详细说明如何构建它正在查看的比特币源码,将这些信息保存在makefile文件里.-with-incompatible-bdb参数说你可以使用Berkeley数据库的版本,而不是原始比特币客户端的版本.
comment:事实上,Automake系统似乎已经被弃用了,如果遇到了别的问题可以尝试使用./authgen.sh来解决配置问题

Finally make actually uses the makefile that you just built using ./configure, to build the Bitcoin project.
最后make实际上是使用你刚刚使用./configure构建的makefile来构建比特币项目.

And if you got all the stuff you needed to build with, the whole process should finish without an error.
如果你得到了所有你需要用来构建的东西,整个过程应该能没有error地完成.

Make sure your build worked
Here’s a couple more command lines to make sure that the build worked, by checking to make sure the executable files it was supposed to build are actually there.
确保您的构建工作
这里有几个命令行来确保构建工作,通过检查以确保它应该构建的可执行文件实际存在.

Got ’em? Excellent! That means your build environment has everything you need to work with to make an altcoin. So, now that the smoke test is over, it’s time to actually go to the newcoin directory and start making your altcoin.
成功了吗?Excellent!这意味着您的构建环境具有制作替代币所需的一切. 所以,既然冒烟测试(smoke test)已经结束,那么现在是时候去新币目录并开始制作您自己的替代币了.

Make Your Altcoin Use Its Own Name
So here are some more command lines:
让你的替代币使用自己的名字
所以这里有一些命令行:

The first four commands change every occurrence of the string ‘bitcoin’ in four capitalizations to the string ‘newcoin’ in all the files in this directory or under it, in three different capitalizations. The second three commands do the same thing to the string ‘btc’, transforming every instance of it into all-caps.
前四个命令将这个目录内的所有文件中出现的字符串’bitcoin’的每次出现更改为字符串’newcoin’,以三种不同的大小写形式. 后三个命令对字符串’btc’执行相同的操作,将其每个实例转换为全部大写字母.

Rename ‘bitcoin’ filenames to your altcoin’s name
Now, because this also affected makefiles which contain filenames, and affected source files which have filenames in their include statements, you’ve got to change all the filenames that have the string ‘bitcoin’ in them to match what’s now in the include statements and makefiles. Fortunately, this is just as easy.
将’比特币’文件名重命名为您的替代币名称
现在,因为这也影响了包含文件名的makefile,以及在include语句中包含文件名的源文件,你必须更改所有包含字符串’bitcoin’的文件名,以匹配include语句中现在的文件名和makefile文件.幸运的是,这也很简单.

Will rename every file that has ‘bitcoin’ or ‘btc’ in the name, recursing into subdirectories as needed. So now your filenames match up with your changed makefiles and include statements.
这将重命名名称中包含“bitcoin”或“btc”的每个文件,并根据需要递归到子目录中. 所以现在你的文件名将会与你改变的makefile和include语句相匹配.

Check For Stuff Your Auto-edits Missed Because It Was Misspelled
Now look for misspellings of it.
检查是否因为拼写错误而错过了自动编辑
现在寻找它的拼写错误.

Aside from uncovering a bunch of references in source code to nDebitCached and a few similarly named variables, reveals that in Arabic translations ‘Bitcoin’ was rendered as ‘Bitcion’ in two translated sentences. In a language I don’t recognize at all but which may be Estonian, it became ‘Bitconi’ once, and the Dutch translation mentions a “bitcon:-URI.’
除了在源代码中发现一堆引用到nDebitCached和一些类似命名的变量之外,还揭示了在阿拉伯语翻译中’Bitcoin’在两个翻译句子中呈现为’Bitcion’. 在一种我根本不认识但可能是爱沙尼亚语的语言中,它写成了’Bitconi’一次,荷兰(应该是丹麦)语翻译提到了’bitcon:-URI’.

The last is certainly a misspelling, because URI’s are spelled the same regardless of language. So
最后一个肯定是拼写错误,因为无论时什么语言,URI的拼写都应该是相同的.所以

sorts that.

I remember about Arabic that it inflects words using patterns of triple vowels, and ‘bitcion’ is used more than once, so my first thought is that it might not be a misspelling. A quick check on Google, however, reveals a lot of instances of ‘Bitcoin’ misspelled in English, and no Arabic pages. So with more evidence, I think I’ll conclude that it probably is a misspelling – about which, again, there’s a chance I’m wrong, and you should write on your list of things to do asking someone who actually speaks Arabic about it. But for now patch it using
我记得阿拉伯语是用三元音的模式翻译单词,而’bitcion’这个词也不止一次被使用,所以我首先想到的是它可能不是拼写错误.然而,我通过使用谷歌进行的快速搜索揭示了很多英语里’Bitcoin’的拼写错误,而且没有找到阿拉伯语页面.有了更多的证据,我想我会得出结论,这可能还是一个拼写错误.当然也有可能是我错了,你应该把这件事写在你的TODO清单上,问一个真正说阿拉伯语的人.但现在让我们用补丁修复这件事吧.

And then there’s the Estonian-or-whatever-it-is. I haven’t heard of any languages outside the middle east that inflect by modifying vowel sequences, and ‘Bitconi’ seems likely to be a misspelling, so once more I’ll just make a possibly-dumb assumption and patch it.

Fix The Copyright Notices
Now, the license under which you have access to this code mentions, among other things, leaving copyright notices intact – and you mangled ’em when you switched ‘Bitcoin’ to ‘Newcoin’ because the boilerplate line there refers to the ‘Bitcoin Development Team’. So you need to change ‘Newcoin’ back to ‘Bitcoin’ but only on the lines where it’s part of a copyright statement.
修正版权声明
现在,您可以访问此代码的许可,或者说,您需要保留版权声明的完整性 – 您可能已经损坏了它们在您将’Bitcoin’改变为’Newcoin’时,因为那里的引用线引用的是是’Bitcoin Development Team’.因此,您需要将’Newcoin’更改回’Bitcoin’,但仅限于版权声明中的这一行.

sorts that. I left the first letter off of ‘Copyright’ because I didn’t want it to care about the capitalization. You’ll be adding your own copyright notices to these files, but only when you do significant edits.
完成了.我留下了’Copyright’的第一个字母因为我不想它去关心大小写(这在说什么…).你将可以在这些文件里加入自己的版权声明,但仅限于你做了有意义的修改时.

There were also a lot of references to Bitcoin in the release-notes files, and it would be an outright lie to pretend that those earlier releases were releases of your alt rather than releases of Bitcoin, so those need changed back, too.
这里也有很多关于比特币的引用在release-notes文件中,假装那些早期的发行是你自己的发行而不是比特币的那将是一个彻头彻尾的谎言,所以这些东西也需要改回来.(绝了,能不能不浪费时间了)

handles that.

Change the Ports
Bitcoin uses ports 8332 and 18332 on its main net and 8333 and 18333 on its test net. You want newcoin to use different ports, just to make it handy for people to run both clients at the same time.
比特币在其主网上使用端口8332和18332,在其测试网络上使用8333和18333.您希望newcoin使用不同的端口,只是为了让人们可以同时运行两个客户端.

will switch newcoin to using ports 9443 and 19443 on mainnet and 9444 and 19444 on testnet. Once again, you should provide your own values. But don’t change any of the port numbers to anything below 1000, or nobody except root will be able to run it. I should mention here that in addition to the port numbers, you just changed a couple of hex strings in the testing directory that the test framework feeds to the RPC interface. But you were going to fail those tests anyway, because other edits you’re making will make Newcoin keys different from Bitcoin keys.
这将把改变newcoin所使用的端口为9443和19443在主网以及9444和19444在测试网络.再一次,您应该提供自己的数值.然而不要将任何端口号更改为1000以下,否则就只能由root用户才能运行它了.另一个我要在这里提到的是,除了端口号之外,你刚刚在测试目录中更改了几个十六进制字符串,测试框架将这些字符串提供给RPC接口.但是无论如何那些测试你都会失败,因为你将要做的的其他修改将使Newcoin的keys与Bitcoin的keys完全不同.

Change the Graphics
You don’t really want to show Bitcoin’s icons and images every time you start up, so you need to go and edit some graphics in the directory src/qt/res. When editing, be sure to save new images that are exactly the same size and file format as the old ones. When you want to change the sizes and/or file formats, you need to understand the QT framework first.
你不想在每次启动时都显示比特币的图标和图片,所以你需要去编辑一些图形在目录src/qt/res中.编辑时,请务必保存与旧图像大小和文件格式完全相同的新图像. 如果你想更改大小和/或文件格式,首先你得需要了解QT框架.

I don’t have any nifty command lines that can help you make good art, so you’re on your own here. At the very least, you’re going to want to edit newcoin.ico, newcoin.png, newcoin_testnet.ico, newcoin_testnet.png, and newcoin.icns. I suggest using GIMP for all of these edits; it speaks all those graphics formats. The ico and icns files are particularly annoying to deal with because you have to make similar (but not identical) changes on many different layers of the saved image.

Build Your Altcoin For The First Time
Now we’re done with wholesale edits. It’s time to see whether you broke anything yet. So type

and wait a few minutes.
首次构建您的替代币
现在我们已完成批量修改.现在是时候看看你是否弄坏了任何东西.所以输入

然后等几分钟(屁嘞).

Did it build? You now have newcoind, newcoin-cli, and newcoin-qt? Awesome! So now that we managed to get the wholesale edits right, it’s time to actually look at source code and start doing some very specific edits.
它构建成功了吗?你现在有一个newcoind,newcoin-cli和newcoin-qt?Awesome! 所以现在我们的批量编辑成功了,现在是时候实际查看源代码并开始做一些非常具体的编辑了.

In chainparams.cpp, Edit The Checkpoints
Get your favorite programming editor, go to the newcoin/src/ directory, and open up chainparams.cpp.
在chainparams.cpp中,编辑检查点
使用您喜欢的程序编辑器,转到newcoin/src/目录,然后打开chainparams.cpp.

Search for the string ‘mapCheckpoints’ and it will take you immediately to line 55, which sets a static variable named mapCheckpoints to a list of pairs – the first member of each pair is the block height, and the second is the hash of that block. The Bitcoin client uses these as it verifies the Bitcoin block chain. So if you leave those in, the newcoin client will be looking for blocks that don’t exist in the newcoin block chain. So get rid of ’em, and put a place holder for your genesis block in instead. This place holder will be wrong, but we can’t fix it until after we mine a genesis block. After your edit, it should look like this:
搜索字符串’mapCheckpoints’,它会立即转到第55行,它会把名为mapCheckpoints的静态变量初始化为一个pair list – 每对的第一个成员是块高度,第二个是该块的哈希值. 比特币客户端使用这些来验证比特币区块链.因此,如果你留下这些,newcoin客户将寻找newcoin的区块链中不存在的块.所以让我们摆脱他们,并为您的创世块放一个占位符. 这个占位符是错误的,但在我们挖到了一个创世区块我们无法修复它. 编辑后,它应如下所示:

Zero is the block height of the genesis block, and uint256(“0x001″) is a wildly wrong guess about what the hash is going to be.
零是创世区块的块高度,而uint256(“0x001”)是关于创世区块的哈希将会是什么一个错误的猜测.

Make the same edit at the locations where it sets ‘mapCheckpointsTestnet’ and ‘mapCheckpointsRegtest’.
在设置’mapCheckpointsTestnet’和’mapCheckpointsRegtest’的位置进行相同的编辑.

Edit The Checkpoint Data
Right under each of these edited checkpoint lists, there are blocks that initialize a corresponding variable. These variables are named data (for the main network), dataTestnet (for the test network), and dataRegtest (for regression testing). Go to the command line and type
编辑检查点数据
在每个编辑的检查点列表的下面,都有一些块初始化相应的变量.这些变量是date(用于主网络),dataTestnet(用于测试网络)和dataRegtest(用于回归测试).
转到命令行并键入

to find out what the current unix epoch date is, then overwrite the first number in each of these blocks with the current date. You’ll have to do this again (and mine new genesis blocks) right before launch. The second number in each block is a transaction count as of the most recent checkpoint; it should be replaced by zero, because there are no transactions before the genesis block. The third number is the number of transactions per day you expect after the last checkpoint. It doesn’t matter as much, but for now I suggest 500 for the main network, 250 for the test network, and zero for the regtest. Updating these numbers as the amount of traffic on your coin’s block chain changes is one of the things you do as dev, if you want your clients to make accurate estimates of their progress as they reindex or verify the block chain.
去找出当前的unix纪元日期,然后使用当前日期覆盖每个块中的第一个数字. 你必须在launch之前(和挖出新的创世区块时)再次这么做. 每个块中的第二个数字是总计的交易计数; 它应该被零替换,因为在创世区块之前没有交易. 第三个数字是您在最后一个检查点之后预期的每日交易数. 这并不重要,但是现在我建议500用于主网络,250用于测试网络,零用于regtest. 如果您希望客户在重新索引或验证区块链时准确估计其进度,则更新这些数字作为您的区块链上的交易量变化是您作为开发人员所需要做的事情之一.

Change The Protocol ‘Magic’ Bytes
The next block after dataRegtest is setting another variable named CMainParams. And you have a lot of things to change here. The first four lines of code set values in an array calledpchMessageStart. These are the network ‘magic bytes’; They’re a series of four bytes that identify messages as belonging to a particular protocol. 0xf9, 0xbe, 0xb4, and 0xd9 are the ones Bitcoin uses. You want to use something else, so that nobody can ever trick your newcoin client into connecting to the Bitcoin network, or vice versa. It doesn’t matter what these are except that they shouldn’t match the ones used in other protocols (particularly other cryptocurrency block chains). They have to be values between 0 and 255. I suggest going back to the shell and using
更改协议的’Magic’Bytes
dataRegtest之后的下一个部分是设置另一个名为CMainParams的变量. 而且你在这里要改变很多东西.前四行代码在名为pchMessageStart的数组中设置值.这些是网络的’magic bytes’;它们是一系列四个字节,用于将消息标识为属于特定协议. 0xf9,0xbe,0xb4和0xd9是比特币所使用的. 你应该想要使用一些不一样的,这样就没有人可以欺骗你的newcoin客户端连接到比特币网络,反之亦然.除了它们不应该与其他协议(特别是其他加密货币区块链)中使用的那些匹配之外,它们无关紧要.它们必须是0到255之间的值.我建议回到shell并使用

Just repeat the command, and write down the last three digits whenever they’re under 255. When you’ve got four of them, set the pchMessageStart values in CMainParams. When you’ve got four more, set the pchMessageStart values in CTestNetParams. And when you’ve got four more, set the pchMessageStart values in CRegTestParams.
只需重复这个命令,并在它们低于255时记下最后三位数字.当你有四个数字时,在CMainParams中设置 pchMessageStart 值. 当你得到另外四个,请在CTestNetParams中设置 pchMessageStart 值.最后四个,在CRegTestParams中设置 pchMessageStart 值.

Make New Alert And Genesis Coinbase Keys
The next line (in the first two params objects) sets vAlertPubKey values. So go back to the command line to get some.
制作新警报和创世纪Coinbase密钥
下一行(在前两个params对象中)设置vAlertPubKey的值.所以回到命令行来获取一些.

Will create private keys and drop them into files named alertkey.pem, testnetalert.pem, and genesiscoinbase.pem, then expand them into key pairs and drop the key pairs in hex format into files named alertkey.hex, testnetalert.hex, and genesiscoinbase.hex.
这将将创建私钥并将其放入名为alertkey.pem,testnetalert.pem和genesiscoinbase.pem的文件中,然后将它们扩展为密钥对.并将十六进制格式的密钥对放入名为alertkey.hex,testnetalert.hex和genesiscoinbase.hex的文件中.

Insert Your New Alert Keys

插入新的提醒密钥

Will show the contents of alertkey.hex. Copy the four lines that appear between ‘pub’ and ‘ASN1 OID: secp256k1′ and paste them into the source code file replacing the string contents in the line that says vAlertPubKey = ParseHex(“…”);

将显示alertkey.hex的内容.复制’pub’和’ASN1 OID:secp256k1’之间出现的四行,并将它们粘贴到源代码文件中,替换vAlertPubKey = ParseHex(“…”);这行中的字符串内容

Then edit to strip the colon characters and linefeeds out of it, and you’ve got an alert key. If you ever need to send an alert out over the network, you can use the corresponding private key.

然后编辑以从中删除冒号字符和换行符,这样您就得到了一个警报秘钥. 如果您需要通过网络发送警报,您就能够使用相应的私钥了.

will show you a key for testnet, so you can set the vAlertPubKey for the CTestNetParams block. The CRegTest block doesn’t have one of its own; if it ever needs one, it uses the testnet key.

将显示testnet的密钥,因此您可以为CTestNetParams块设置vAlertPubKey. CRegTest块没有自己的警告秘钥;如果它需要一个,它将会使用testnet的密钥.

Edit The Timestamp String
Now we skip down to the famous timestamp string, at the line

编辑时间戳字符串
现在我们跳到famous timestamp字符串

It’s traditional to pick a newspaper headline for the day of launch, but you don’t have to. Whatever you use, keep it short. If it’s over 90 characters or so the block will fail a length check that’s supposed to prevent denial-of-service attacks from people attaching big data to transactions.

传统是选择发布当天的报纸头条,但您也并不一定要这样做.但无论您用什么,都要保持简短. 如果它超过90个字符左右,则该块将无法进行长度检查,以防止将大数据附加到交易的人进行的DOS攻击.

Set The Genesis Coinbase Key

设置Genesis Coinbase密钥

will show you a key for the genesis coinbase transaction, so you can paste that into the CMainParams block replacing the string contents in the line

将显示genesis coinbase交易的密钥,因此您可以将其粘贴到CMainParams块中,替换该行中的字符串内容

Set the Genesis Time
Going down a little more, change the line in the CMainParams block that sets genesis.nTime so that it sets it to the same Unix epoch date you got using the ‘date’ command above. Repeat that edit in the CTestNetParams block.

设置Genesis时间
更进一步,更改CMainParams中的genesis.nTime,以便将其设置为使用上面的’date’命令获得的相同Unix纪元日期.在CTestNetParams中重复该编辑.

Delete References To Bitcoin’s Seed Nodes
Skipping down past the hashGenesisBlock stuff, you’ll see a series of lines that set values for a list named vSeeds. These are network addresses where long-lived Bitcoin nodes are supposed to be found, so that people can always connect to the Bitcoin network. Which, as you’re establishing now, is not your network. Until you put up servers to do that for your new network, replace these lines (in both CMainParams and CTestNetParams) with the simple statements:
删除对比特币种子节点的引用
跳过hashGenesisBlock的东西,你会看到一系列为名为vSeeds的列表设置值的行. 这些是应该找到长期比特币节点的网络地址,这样人们就可以随时连接到比特币网络. 正如您现在所建立的那样,这不是您的网络. 在您为新网络安装服务器之前,请使用简单语句替换这些行(在CMainParams和CTestNetParams中):

Change The Key Prefixes
Moving on down, we get to a block of statements that set values in an array of lists named base58Prefixes. These are prefix bytes that are added to the keys. By setting them to different values, you can assure that keys for coins on Newcoin’s network will never be valid Bitcoin keys and vice versa. To a certain extent, setting these numbers also determines what characters the base58 form of the keys that users see starts with. The chances of a random collision in keys are ridiculous, but “chances” and “random” are quaint old-fashioned ideas here; you’re working on code that somebody is going to deliberately attack. So change the values. You can use echo $RANDOM at the command line again if you want. If you care about what initial characters your choices will result in for the base58 form of the keys, consult thelist at the Bitcoin wiki.
更改密钥前缀
继续向下,我们看到了一个语句块,在名为base58Prefixes的列表数组中设置值. 这些是添加到密钥的前缀字节. 通过将它们设置为不同的值,您可以确保Newcoin网络上的货币密钥永远不会是有效的比特币密钥,反之亦然. 在某种程度上,设置这些数字还可以确定用户看到的键的base58形式的起始字符. 钥匙随机碰撞的可能性是荒谬的,但”机会”和”随机”是古怪的老式想法; 你正在研究可能有人会故意攻击的代码.所以改变这些值. 如果需要,可以再次在命令行中使用echo $RANDOM . 如果你关心你的选择将导致key的base58形式的初始字符是什么,请参考list at the Bitcoin wiki.

There is one important constraint here: none of the lists can be identical, because the clients look at the initial bytes to figure out what kind of key they’re dealing with. Also, don’t change the length of any list until you’ve read the code enough to know everything that will affect.
这里有一个重要的约束:没有一个列表可以是相同的,因为客户端查看初始字节以确定它们正在处理什么类型的密钥. 此外,在您阅读足够的代码以了解将影响的所有内容之前,请不要更改任何列表的长度.

base58Prefixes(PUBKEY_ADDRESS) is the value prefixed to addresses that consist of public keys – these are the public half of a pubkey/private key pair that respectively represent a txOut and the ability to spend it. base58Prefixes(SECRET_KEY), predictably, are the prefixes for the private half of the pair. This is the key your client keeps in its wallet to spend a txOut. base58Prefixes(SCRIPT_ADDRESS) is affixed to addresses that are the hashes of scripts; looking for the difference between the initial bytes is how the client knows which of the two “default” spend scripts to apply. Finally, base58Prefixes(EXT_PUBLIC_KEY) and base58Prefixes(EXT_SECRET_KEY) are four-byte prefixes for the so-called “stealth addresses” that got introduced in Bitcoin version 0.9, which allow fun things like addresses that can be used to generate new keys that can receive payments but not spend them. These two should have the same first byte but must differ in the other three bytes.
base58Prefixes(PUBKEY_ADDRESS)是以公钥组成的地址为前缀的值 – 这些是公钥/私钥对的公共一半,分别代表txOut和花费它的能力. 可预测的是,base58Prefixes(SECRET_KEY)是该对的私有一半的前缀. 这是您的客户在钱包中花费txOut的关键. base58Prefixes(SCRIPT_ADDRESS)被附加到作为脚本哈希的地址上; 寻找初始字节之间的差异是客户端如何知道要应用的两个”默认”花费脚本中的哪一个. 最后,base58Prefixes(EXT_PUBLIC_KEY)和base58Prefixes(EXT_SECRET_KEY)是比特币版本0.9中引入的所谓”隐形地址”的四字节前缀,它允许有趣的东西,例如可用于生成可以接收付款但不能花费它们的的新密钥的地址.这两个字节应该具有相同的firstbyte,但在其他三个字节中必须不同.

Aaaanyway, it doesn’t matter what you change them to, it just matters that they don’t match anything they might ever be confused with, like Bitcoin keys or each other. So give them new values in CMainParams, CTestNetParams, and CRegTestParams.
无论如何,你把它们改成了什么并不重要,重要的是它们与任何它们可能会混淆的东西不匹配,比如比特币的秘钥或彼此之间. 因此,在CMainParams,CTestNetParams和CRegTestParams中为它们提供新的值.

Add Code To Mine A Genesis Block
Finally, we’re just about ready to mine a Genesis block. But the code to actually mine a Genesis block hasn’t been in Bitcoin for a long time; that block is already mined. Its parameters are there to check against, but there’s no code to establish what some of them ought to be. You need to fix that. So in the CMainParams initializer, right after
添加代码以挖掘创世纪块
最后,我们准备开采一个创世区块了. 但实际挖掘Genesis块的代码已经很长时间没有在比特币中使用了. 那块已经在很久以前就被开采了. 它的参数可供检查,但没有代码可以确定它们应该是什么.你需要解决这个问题. 所以在CMainParams初始化器中,right after

and before

复制这些代码

然后把这句放到文件头部

comment:原版的这段代码有一坨坑.

Use the same code in the CTestNetParams initializer, except change ‘mainnet’ into ‘testnet.’ Likewise the CRegTestParams initializer, except change ‘mainnet’ into ‘regtest’.
在CTestNetParams初始化器中使用相同的代码,除了将’mainnet’更改为’testnet’.同样是CRegTestParams初始化器,除了将’mainnet’更改为’regtest’.

Now build again. This time you have already done all the autoconf stuff, so you just need to type

现在再构建一次.这次你已经完成了所有autoconf的东西,所以你只需要输入

and you only changed one file, which isn’t included anywhere else. So it should be built in a few seconds.

并且您只是更改了一个没有被其他任何位置的文件include的文件, 所以它应该在几秒钟内构建完成.

Now Mine Your Genesis Blocks
Got all that? Now run newcoin-qt.
现在挖掘你的创世区块
一切都按完成了?现在运行newcoin-qt.
comment:似乎…还没有安装呢,而且在没有qt库的情况下安装后并不能使用qt版.
comment2:qt编译有问题的可以试试这个https://github.com/dogecoin/dogecoin/issues/1422

It will throw up a dialog box asking where to install. Let it have the default it wants, which will be a new subdirectory of your home directory named ~/.newcoin.
它会弹出一个对话框,询问安装位置. 让它具有它想要的默认值,它将是你的主目录的一个名为~/.newcoin的新子目录.
comment:据我认为,这部分根本不像他说的那样工作,LogPrintf在某些初始化完成前似乎完全不工作,我尝试对util.cpp中的LogPrintStr函数进行了某些改动才达到目标.

Then Nothing will happen, maybe for up to an hour. Maybe longer than an hour, depending on your dumb luck and the speed of your computer. If your computer’s slow, this may be a good time to go get a sandwich.
然后什么都不会发生,可能长达一个小时,也可能超过一个小时,这取决于你的运气如何和电脑的速度.如果你的电脑很慢,这可能是去吃三明治的好时机.

Here’s what’s going on. The program set the nonce, hashed the genesis block, noticed that the new hash didn’t match 0x01, and is now living in that tight little empty for loop, incrementing the nonce, hashing the block, and checking to see whether the new hash is low enough to meet proof-of-work requirements.
这是正在发生的事.程序设置了nonce,哈希这个创世区块,注意到新的哈希与0x01不匹配,现在运行在那个紧密的小的for循环空间里,递增nonce,再次哈希块,并检查新的哈希 是否足够低以可以满足POW的要求.

After a while, it will die. Meaning, it found a nonce that gave the genesis block a hash low enough to pass proof-of-work, got out of the for loop, logged the new hash and nonce and the Merkle tree value, and then hit the assert that still insists on the hash value being Bitcoin’s genesis block hash value. You need the new values it logged. Type

过了一会儿,它会终止. 意思是,它发现了一个nonce,这个nonce给了创世区块一个足够低的哈希值来传递工作证明,离开了for循环,记录了新的hash和nonce以及Merkle树的值,然后打击仍然坚持的断言 哈希值是比特币的创世区块哈希值.您需要这个记录的新值,输入

and you’ll see the last few lines of logfile output.

你会在日志文件输出的最后几行看到它.

Now you have a nonce and a hash and a Merkle root so go change the necessary lines in the CMainNet initializer.
现在你有一个nonce和一个hash和一个Merkle root,所以让我们去修改CMainNet初始化程序中的必要行.

In the code you pasted in, you’ve initialized hashGenesisBlock to be uint256(“0x01″). Replace the string value with the new genesis hash.
在您粘贴的代码中,您已将hashGenesisBlock初始化为uint256(“0x01”). 用新的genesis hash替换字符串值.

另外,可能还要把genesis.hashMerkleRoot改成您新计算出来的值.

Right above the code you pasted in, you’ll see a line that sets a value for genesis.nNonce. Change it to your new nonce value.
在您粘贴的代码正上方,您将看到一行为genesis.nNonce设置了值.将其更改为新的nonce值.

Right below the code you pasted in, you’ll find assert() statements that check the value of the Merkle root and the hash. Change those to assert your new Merkle root and genesis Hash values.
在您粘贴的代码的正下方,您将找到assert()语句,用于检查Merkle根和散列的值. 更改那些assert以新的Merkle根和genesis Hash值.

Near the top of the file, there’s your mapCheckpoints list, claiming that the hash of the genesis block is 0x01. Change that to your new hash value.
在文件顶部附近,有你的mapCheckpoints列表,声称创世块的哈希值是0x01.将其更改为新的哈希值.

Once you’ve made these edits, recompile and run it again. The same thing will happen all over again, but this time for testnet. And you change the same things in the CTestNetParams initializer, etc, that you changed in the CMainParams initializer.
完成这些编辑后,重新编译并再次运行. 同样的事情将再次发生,但这次是针对testnet的. 然后您可以在CTestNetParams初始化程序中做同样的修改.

Recompile and run it again, and it will trip on the regtest values. Fortunately these won’t take any time because the regtest proof-of-work is much easier. Change the same things in the CRegTestParams initializer.
重新编译并再次运行它,它将在regtest值上运算. 幸运的是,这些不会花费任何时间,因为regtest工作证明要容易得多. 在CRegTestParams初始化程序中更改相同的内容.

Now STOP Mining Genesis Blocks
Okay? Now you have mined your new genesis blocks. Now, in the code you pasted in, see where the stupid-looking if condition checks for
现在停止挖掘创世区块
完成了?现在你已经开采了新的创世区块. 现在,在您粘贴的代码中,查看愚蠢的if条件检查的位置

?
Change those three ‘true’s to ‘false’s. The purpose of this ‘true/false’ business is to make it easy for you to switch back and forth from mining genesis blocks to not mining genesis blocks. You’ll need to mine a new genesis block right before launch, and may need several more during testing and development depending on whether you do anything that changes the block headers or initial coinbase transaction (like changing the number of coins in it). But in the client you actually test and release, you don’t want genesis block mining turned on. If it sees a wrong genesis block, you want it to bomb out immediately, not sit there trying to create a new one.
将这三个‘true’改为‘false’. 这种’true/false’业务的目的是让您轻松地从开采创世区块切换到不挖掘创世区块. 你需要在发布之前挖掘一个新的创世区块,并且在测试和开发过程中可能还需要几个,这取决于你是否做了任何改变块标题或初始coinbase事务的事情(比如更改其中的硬币数量). 但是在您实际测试和发布的客户端中,您不希望启用创世区块挖掘的功能. 如果它看到一个错误的创世块,你希望它立即爆炸,而不是坐在那里试图创建一个新的.

Whenever you need to mine new genesis blocks because you changed something that invalidated the old one during development, you will come back to chainparams.cpp, update the date parameters and timestamp string, make the three true/false edits, recompile, do

每当你需要去挖出一个新的创世区块因为你在开发中改变了一些东西使之前的创世区块无效时,你将需要回到chainparams.cpp,更新日期参数和时间戳字符串,进行那三个true/false编辑,重新编译,do

so it doesn’t see the (now) wrong former genesis block in the data there, and run it.

所以它不会再去关心(现在)无效的创世区块了,然后我们可以运行它.

What You’ve Got Now
At this point you have created a complete, and completely simple, clone of Bitcoin version 0.10. If this is all you’re doing, then it’s been a nice learning experience but don’t launch this coin. Unless doing something new, there is no point.
你现在有了什么
此时,您已经创建了比特币版本0.10的完整且完全简单的克隆.如果这就是你所做的一切,那么这是一个很好的学习经历,但不要发行这种货币.除非你要做一些新的事情,否则发行这种币是没有意义的.

Problems You Still Need To Solve
This thing you have created cannot yet possibly survive as an altcoin; its difficulty adjustment algorithm will not respond quickly enough to prevent your block chain from getting instamined, and then stuck. Mining whales will scoop up two weeks of coins while processing almost no transactions, in less than an hour while your block chain is profitable, then when the difficulty adjustment for that two weeks hits they’ll leave your chain high and dry. You won’t get a block for days and nobody will be able to use your alt to make any kind of transaction because of it. The result is a block chain that can handle transactions for maybe two hours out of every year, which is useless to everyone.
您仍需要解决的问题
你创造的这个东西还不能像替代币一样存活下来;它的难度调整算法不会足够快地响应,以防止你的块链被瞬挖,然后卡住.在你的区块链盈利的不到一个小时内,采矿鲸会收集两周的硬币,同时几乎不处理交易,然后当两周的难度调整到达时,它们会让你的链条变得高而干燥.你好几天都不会得到一个块,也没有人能够使用你的替代币进行任何类型的交易.结果是这个链,每年可以处理两个小时的交易,这对每个人都没用.

So the next thing you need to do is go fix that. And when you’ve fixed it, your new alt still won’t be capable of surviving; First, you don’t have any network seeds up, and second everybody has one fix or another for the difficulty problem that a cloned coin creates. Once again, you either have a new idea and the ability to develop and support it, or you don’t have anything that’s worthwhile to launch. What I have shown you here are the first few steps on a long road.
所以你需要做的下一件事就是解决这个问题.当你修复它时,你的新替代币仍然无法生存;首先,你没有任何网络种子,第二,每个人都在克隆货币时解决了不少问题.再一次,你要么有新想法,要么有能力开发和支持它,或者你没有任何值得推出的东西.我在这里向您展示的只是漫长道路上的前几步.

I’ll talk about one way to fix it in the next installment.
我将在下一期中谈论一种方法来修复这个问题.

真是又臭又长,怎么还有下一期,再也不翻译这种东西了(*`皿´*)ノ

使用pip-review升级所有python包

pip默认并不提供升级所有包的功能,而一个一个升级显然是太麻烦了,与此同时,一些应用shell脚本拼接字符串而升级所有包的办法并不能跨平台(windows平台下不能用).

查询StackOverflow发现已经有人做了一个包来解决这个问题

使用方法:


$ pip install pip-review
$ pip-review --local --interactive

https://github.com/jgonggrijp/pip-review

similarly, iptables的保存也可以用某个专门的包来解决这些问题(在很多不同的发行版中iptables的保存位置不同)

Usage:

sudo apt-get install iptables-persistent
sudo netfilter-persistent save
sudo netfilter-persistent reload

daily

秒回信息意味着什么呢,是在乎别人所以才迅速?还是根本不care以至于无需整理措辞?

无所谓,若从来不在乎,就永远不伤心//又在催眠自己了

为了避免别人看出这事还找了个理由把全部推送都关了,真有意思呢

似乎上帝也不是那么不眷顾我啊,但很多机会出现时我都缺乏能力
当我没说 敲里妈

It is true that if you don’t record you emotion immediately, you very quickly forget them even if you think impossible.

阶级滑落怎么办啊…
难道怪原生家庭??

又想人文,又想geek,又想academic,还想做hardcore gamer还想现充,不看看自己配吗

其实也是,放弃一些不想再追求的方面从而更好的集中精力,这也挺好的.
青春啊,果然有失亦有得,可能只有我一样迷茫的人才是真的失败吧
如果真是这样,曾嘲笑过的人,以后都会明白的,不过也可能不会,哈哈哈哈
甚至,连她都优越于我啊
被拒了好友申请可还行…

真的无解啊,gamemaker的梦,但怎么可能呢,还这样玩游戏的话什么都不可能实现的,更别提什么hardcore玩家了,确实只有天才才能做到吗?
难道这就算是忘了初心了.

又想起了那段时光,…原来我也做过这种傻逼事情,故事里的事原来我身上也发生过?   //again…

Three creeds, do interesting things, stay elegance, and…limited social/personal responsibility, but could I truly keep all of these?

如果把这当成一个task的话,这表现确实可说是粗糙了,即使我并不喜欢完全宠溺着的立场,但至少…足够的同理心是得应当要表明出来的,之后还有机会的话,至少不能像这次这样了吧.

灵魂的深度真的和性别显著相关吗?(社会环境影响/偏见/事实)

生命活力丧失ing…

最爱的,真的还是我自己吗

是都一样啊

我在他眼里又是怎样呢

我也知道以后会后悔啊,但人生怎么能一次都不追逐梦想呢?     //5天后马上就后悔了…

男人…男人都是这样

真的是懦弱啊    游戏人生,游戏nmlgb  12/18

感悟:人生病的时候似乎很脆弱+多情+迷茫(不确定是否是普遍现象),如果在这个时候给与关心…

usercf这么牛逼,这帮人怎么就知道做推荐系统呢?社交什么的不做起来?