<commit_before><!doctype html>
<html class="theme-next   use-motion ">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.4.5.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.4.5.2" />






<meta name="description" content="唯爱与美食不可辜负">
<meta property="og:type" content="website">
<meta property="og:title" content="yield编程实验室">
<meta property="og:url" content="http://trainking.github.io/index.html">
<meta property="og:site_name" content="yield编程实验室">
<meta property="og:description" content="唯爱与美食不可辜负">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="yield编程实验室">
<meta name="twitter:description" content="唯爱与美食不可辜负">



<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post',
    motion: true
  };
</script>

  <title> yield编程实验室 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  






  <div class="container one-column 
   page-home 
">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">yield编程实验室</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">打怪，升级，收小弟，拓后宫</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu ">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-tags fa-fw"></i> <br />
            
            标签
          </a>
        </li>
      

      
      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content">
          
  <section id="posts" class="posts-expand">

    

    
    
      
      
        
        
        
      

      
    

    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-3/" itemprop="url">
                  【算法】分治法(快速排序，归并排序)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:29:48+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
              <p><strong>分治法</strong>，是算法思想里最基础的思想。这也和人的基本思维有关，当我们需要解决一个大的问题时，直觉的就会将这个大问题分成多个小问题来解决。</p>
<p>大量的经典算法，都是基于分治法。比如，快速排序，归并排序。当然，最让人想起来的，就是二分查找了。</p>
<h1 id="u5206_u6CBB_u6CD5_u7684_u6B65_u9AA4"><a href="#u5206_u6CBB_u6CD5_u7684_u6B65_u9AA4" class="headerlink" title="分治法的步骤"></a>分治法的步骤</h1><p>分治，分而治之。分的原因是因为问题的规模太大，需要拆开了解决，目的是为了解决问题，分解只是手段。所以分治的步骤其实很明确:</p>
<ol>
<li><strong>分解</strong>：将大问题的分解成小问题，是这个算法的核心。也是使用分治法的效率保证，如果分解不合理。那么反而会弄巧成拙。</li>
<li><strong>解决</strong>：解决问题，便是分解之后的小问题。他们的解决步骤是相同，至少是相似的。所以，分治法中经常用到递归，就是基于这样的目的。</li>
<li><strong>合并</strong>：前面那么麻烦的两步，最终的目的仍然是为了解决这个问题。所以需要将分解问题得到的解，合并成最终需要的终极答案，便是这个算法的结束过程。譬如，你使用递归的时候，也需要最后退出的条件。分治法结束条件，就是合并步骤的结束。</li>
</ol>
<h1 id="u9012_u5F52_u4E0E_u5206_u6CBB_u6CD5_u7684_u5173_u7CFB"><a href="#u9012_u5F52_u4E0E_u5206_u6CBB_u6CD5_u7684_u5173_u7CFB" class="headerlink" title="递归与分治法的关系"></a>递归与分治法的关系</h1><p>虽然很多的运用分治法的算法，都使用到了递归。但是并不是意味着使用了递归的算法，就是使用了分治法。分治法也可使用迭代来实现呀。可以这么说，一切用尾递归方式的算法，都可以通过一个栈来迭代实现。递归只是算法的实现手段，基于各语言（大部分）都支持在函数内部调用本身特性，可以减少代码的重复。</p>
<p>我之所以特此说明，就是我曾经就有这种错误的认识。</p>
<h1 id="u8FD0_u7528_u5B9E_u4F8B"><a href="#u8FD0_u7528_u5B9E_u4F8B" class="headerlink" title="运用实例"></a>运用实例</h1><p>我前面已经提到的<strong>快速排序</strong>，<strong>归并排序</strong>，<strong>二分查找</strong>。这三种算法都是经典的算法，实现方法已有很多人写了。我就不献丑了，特别引用了维基百科的快排和归并的例子，当然依旧是python的实现。</p>
<p><em>维基百科的快速排序</em>:<br> <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">qsort</span><span class="params">(arr)</span>:</span></span><br><span class="line">    <span class="keyword">if</span> len(arr) &lt;= <span class="number">1</span>:</span><br><span class="line">        <span class="keyword">return</span> arr</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        pivot = arr[<span class="number">0</span>]</span><br><span class="line">        <span class="keyword">return</span> qsort([x <span class="keyword">for</span> x <span class="keyword">in</span> arr[<span class="number">1</span>:] <span class="keyword">if</span> x &lt; pivot]) + \</span><br><span class="line">               [pivot] + \</span><br><span class="line">               qsort([x <span class="keyword">for</span> x <span class="keyword">in</span> arr[<span class="number">1</span>:] <span class="keyword">if</span> x &gt;= pivot])</span><br></pre></td></tr></table></figure></p>
<p><em>维基百科的归并排序</em>：<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> collections <span class="keyword">import</span> deque</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">merge_sort</span><span class="params">(lst)</span>:</span></span><br><span class="line">    <span class="keyword">if</span> len(lst) &lt;= <span class="number">1</span>:</span><br><span class="line">        <span class="keyword">return</span> lst</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">merge</span><span class="params">(left, right)</span>:</span></span><br><span class="line">        merged,left,right = deque(),deque(left),deque(right)</span><br><span class="line">        <span class="keyword">while</span> left <span class="keyword">and</span> right:</span><br><span class="line">            merged.append(left.popleft() <span class="keyword">if</span> left[<span class="number">0</span>] &lt;= right[<span class="number">0</span>] <span class="keyword">else</span> right.popleft())  <span class="comment"># deque popleft is also O(1)</span></span><br><span class="line">        merged.extend(right <span class="keyword">if</span> right <span class="keyword">else</span> left)</span><br><span class="line">        <span class="keyword">return</span> list(merged)</span><br><span class="line"></span><br><span class="line">    middle = int(len(lst) // <span class="number">2</span>)</span><br><span class="line">    left = merge_sort(lst[:middle])</span><br><span class="line">    right = merge_sort(lst[middle:])</span><br><span class="line">    <span class="keyword">return</span> merge(left, right)</span><br></pre></td></tr></table></figure></p>

            
          </span>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-2/" itemprop="url">
                  【算法】贪心算法(0-1背包问题)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:29:34+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
              <h1 id="u4EC0_u4E48_u662F_u8D2A_u5FC3_u7B97_u6CD5_uFF1F"><a href="#u4EC0_u4E48_u662F_u8D2A_u5FC3_u7B97_u6CD5_uFF1F" class="headerlink" title="什么是贪心算法？"></a>什么是贪心算法？</h1><p><strong>贪心算法</strong>并不是一个具体的算法，而是一种算法的思想，或者说是解决问题一种思路。这就有两个关键的点，可以解释贪心算法：</p>
<blockquote>
<ol>
<li>贪心算法解决什么问题？</li>
<li>贪心算法是怎样的一种思路？</li>
</ol>
</blockquote>
<h2 id="1-__u8D2A_u5FC3_u7B97_u6CD5_u89E3_u51B3_u4EC0_u4E48_u95EE_u9898"><a href="#1-__u8D2A_u5FC3_u7B97_u6CD5_u89E3_u51B3_u4EC0_u4E48_u95EE_u9898" class="headerlink" title="1. 贪心算法解决什么问题"></a>1. 贪心算法解决什么问题</h2><p>解决求最优解问题。即此问题的最终的目的，是为了得到一个最优解。比如，从A地到B地之间的最短路径，100块钱可以在一个商场里买到的东西最多，等等之类的。</p>
<h2 id="2-__u8D2A_u5FC3_u7B97_u6CD5_u662F_u600E_u6837_u7684_u4E00_u79CD_u601D_u8DEF"><a href="#2-__u8D2A_u5FC3_u7B97_u6CD5_u662F_u600E_u6837_u7684_u4E00_u79CD_u601D_u8DEF" class="headerlink" title="2. 贪心算法是怎样的一种思路"></a>2. 贪心算法是怎样的一种思路</h2><p>顾名思义，贪心算法，是一种很“贪”的算法。它的整体步骤，可以归纳为：</p>
<blockquote>
<ol>
<li>将问题分解成多个小问题或者多个步骤。</li>
<li>在每个小问题或者步骤中，执行某种最优化策略，得到局部最优解</li>
<li>所有每个步骤得到的最优化解，组合得到全局最优化解，不回溯处理</li>
</ol>
</blockquote>
<p><strong>贪心算法</strong>最大的特点，就是在每一步中取最优化的解，不会回溯处理。这样的策略，自然在执行速度上更快，但是因为这种方法的<strong>短视</strong>。会导致得的解并不是真正的全局最优解，但是<strong>贪心算法</strong>得到的依然是一个近似最优解。</p>
<h1 id="0-1_u80CC_u5305_u95EE_u9898"><a href="#0-1_u80CC_u5305_u95EE_u9898" class="headerlink" title="0-1背包问题"></a>0-1背包问题</h1><p>问题可以描述为：给定一组物品，每种物品都有自己的重量和价格，在限定的总重量内，我们如何选择，才能使得物品的总价格最高。</p>
<p>通俗解释：假如你有一个只能承重100的背包，你往里面装一些重量和价值不等的东西，怎样才可以让你的背包中的价值最大。</p>
<p>这个问题中就是关键在于，每个转入背包的东西，只能是被装入背包和不被装入背包两种状态，可以用0-1表示。所以叫0-1背包问题。其二，就是这个问题的两个限定。第一，背包的边界是明确，它只能承重那么多东西。第二，东西的边界是明确的，你只有那么一些东西可以选择。</p>
<p>故而，这个问题其实有三种策略可以选择：</p>
<blockquote>
<ol>
<li>每次装入的都是价值和重量比率最高的，也就是我们常说的性价比最高的</li>
<li>每次装入的是当前可选择的东西中，价值最高的</li>
<li>每次装入的是当前可选择东西中，重量最轻的</li>
</ol>
</blockquote>
<p>这三种策略中，策略一看起来最好的策略。但是，策略一的模糊化太大，需要根据特殊的情况，做出特殊的改变。</p>
<p>策略二和策略三相同，本身上并没有太多不同。只是二者的视角不同。</p>
<p>我基于第三种策略，给出<strong>python</strong>的实现。（人生苦短，我用python。看不惯来打我呀~~）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-*-coding:utf-8-*-</span></span><br><span class="line"><span class="comment">#0-1背包问题的实现</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Good</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, weight, value, status)</span>:</span></span><br><span class="line">        self.weight = weight</span><br><span class="line">        self.value = value</span><br><span class="line">        self.status = status   <span class="comment"># 0未选中，1已选中</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#@param goods 物品的集合</span></span><br><span class="line"><span class="comment">#@param total 背包的空闲重量</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">greed</span><span class="params">(goods, total)</span>:</span></span><br><span class="line">    result = []</span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span> <span class="keyword">True</span>:</span><br><span class="line">        s=strategy(goods,total)</span><br><span class="line">        <span class="keyword">if</span> s == -<span class="number">1</span>:</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        result.append(goods[s].weight)</span><br><span class="line">        total = total - goods[s].weight</span><br><span class="line">        goods[s].status = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> result</span><br><span class="line"></span><br><span class="line"><span class="comment">#策略</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">strategy</span><span class="params">(goods,total)</span>:</span></span><br><span class="line">    index = -<span class="number">1</span></span><br><span class="line">    minWeight = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">0</span>, len(goods)):</span><br><span class="line">        currentGood = goods[i]</span><br><span class="line">        <span class="keyword">if</span> currentGood.status == <span class="number">0</span> <span class="keyword">and</span> currentGood.weight &lt;= total <span class="keyword">and</span> currentGood.weight &lt;= minWeight :</span><br><span class="line">            index = i</span><br><span class="line">            minWeight = goods[index].weight</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> index</span><br></pre></td></tr></table></figure>

            
          </span>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-1/" itemprop="url">
                  一张图学会python
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:28:00+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
              <p>偶得一图，发现此图是个非常好的python入门教程呀，特此转载，侵删！</p>
<p><img src="http://upload-images.jianshu.io/upload_images/311153-571c7ac8fc5dda46.jpg" alt="一图说python.jpg"></p>
<blockquote>
<p>关于此图，我想说的是，编辑器大家可以用我大sublime!</p>
</blockquote>

            
          </span>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/xijie/" itemprop="url">
                  JavaScript一些细节
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:26:51+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
              <h1 id="u5220_u9664_u6570_u7EC4_u4E2D_u7684_u5143_u7D20"><a href="#u5220_u9664_u6570_u7EC4_u4E2D_u7684_u5143_u7D20" class="headerlink" title="删除数组中的元素"></a>删除数组中的元素</h1><p>你或许已经知道，js中要向数组中增加元素，需要用的是<strong>push</strong>方法。没有和其他语言中类似的<strong>add</strong>方法，是不是很不适应？</p>
<p>但是要是告诉你，从数组中删除元素的方法没有，你是不是简直不敢相信！你如果要说用到<strong>delete</strong>关键字,那么给你看一个吓死你的：<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var s=[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>];</span><br><span class="line"><span class="keyword">delete</span> s[<span class="number">1</span>];</span><br></pre></td></tr></table></figure></p>
<p>这样操作之后，你猜猜操作结果是怎样的？</p>
<p>不买关子，结果是这样的：<br><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>,udefind * <span class="number">1</span>,<span class="number">3</span>,<span class="number">4</span>]</span><br></pre></td></tr></table></figure></p>
<p>被删除的元素，其实只是将这个元素的值删除了，但是并没有改变这个<strong>数组</strong>。即没有把这个数组变成<strong>[1,3,4]</strong>，而如果需要变成这样，则需要用到splice方法:<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">s.splice(<span class="number">1</span>,<span class="number">1</span>);</span><br></pre></td></tr></table></figure></p>
<p>关于更多，请查看 <a href="http://www.w3school.com.cn/jsref/jsref_splice.asp" target="_blank" rel="external">文档</a>。</p>
<blockquote>
<p>注意：splice方法的本意就是拼接，替换元素。这里用到完成删除，只是将拼接的第三个参数为空，达到目的。</p>
</blockquote>
<h1 id="u4E25_u683C_u6A21_u5F0F"><a href="#u4E25_u683C_u6A21_u5F0F" class="headerlink" title="严格模式"></a>严格模式</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="pi">'use strict'</span>;</span><br></pre></td></tr></table></figure>
<p>不知你是否看到别人写带js文件，第一行总是出现这一行匿名的字符串。这其实是ECMAscript  5中引入的严格模式！</p>
<p>传统的js代码执行模式，也就是你不在第一行声明这个匿名字符串时，是正常模式。这个模式中有很多Javascript非常灵活的特性（也非常蛋疼）。比如，如果一个变量没有使用var关键字申明，则是一个全局变量。很让人容易错乱的语法糖。</p>
<p>更多相关内容，<a href="http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html" target="_blank" rel="external">查看</a>。</p>
<h1 id="geter_26amp_3Bseter"><a href="#geter_26amp_3Bseter" class="headerlink" title="geter&amp;seter"></a>geter&amp;seter</h1><p>js的对象也是有geter和seter，这种方式可以灵活的运用到，比如当一个属性只是可读的。这时便可以使用geter方法来取的元素。</p>
<p>下面是一个geter和seter的例子：<br><figure class="highlight sqf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var obj = &#123;</span><br><span class="line">    <span class="built_in">_x</span> : <span class="number">1</span>,</span><br><span class="line">    get getX()&#123;</span><br><span class="line">        return this.<span class="built_in">_x</span>;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="built_in">set</span> setX(x)&#123;</span><br><span class="line">        this.<span class="built_in">_x</span> = x;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>

            
          </span>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    

  </section>

  


        </div>

        


        

      </div>

      
        
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" src="/images/default_avatar.jpg" alt="yield" itemprop="image"/>
          <p class="site-author-name" itemprop="name">yield</p>
        </div>
        <p class="site-description motion-element" itemprop="description">唯爱与美食不可辜负</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">4</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            
              <span class="site-state-item-count">0</span>
              <span class="site-state-item-name">分类</span>
              
          </div>

          <div class="site-state-item site-state-tags">
            <a href="/tags">
              <span class="site-state-item-count">3</span>
              <span class="site-state-item-name">标签</span>
              </a>
          </div>

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/trainking" target="_blank">
                  
                    <i class="fa fa-globe"></i> github
                  
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.jianshu.com/users/3074b798c7d0/latest_articles" target="_blank">
                  
                    <i class="fa fa-globe"></i> jianshu
                  
                </a>
              </span>
            
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      

    </div>
  </aside>


      
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2015</span>
  <span class="with-love">
    <i class="icon-next-heart fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yield</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>



      </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  

  
    
    

  


  

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.2"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.2"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
<script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

<script type="text/javascript" src="/js/motion.js?v=0.4.5.2" id="motion.global"></script>


  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  

  <script type="text/javascript" src="/js/bootstrap.js"></script>

  
  

  
  

</body>
</html>
<commit_msg>增加主页缩略图配置<commit_after><!doctype html>
<html class="theme-next   use-motion ">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.4.5.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.4.5.2" />






<meta name="description" content="唯爱与美食不可辜负">
<meta property="og:type" content="website">
<meta property="og:title" content="yield编程实验室">
<meta property="og:url" content="http://trainking.github.io/index.html">
<meta property="og:site_name" content="yield编程实验室">
<meta property="og:description" content="唯爱与美食不可辜负">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="yield编程实验室">
<meta name="twitter:description" content="唯爱与美食不可辜负">



<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post',
    motion: true
  };
</script>

  <title> yield编程实验室 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  






  <div class="container one-column 
   page-home 
">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">yield编程实验室</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">打怪，升级，收小弟，拓后宫</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu ">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-tags fa-fw"></i> <br />
            
            标签
          </a>
        </li>
      

      
      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content">
          
  <section id="posts" class="posts-expand">

    

    
    
      
      
        
        
        
      

      
    

    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-3/" itemprop="url">
                  【算法】分治法(快速排序，归并排序)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:29:48+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
            分治法，是算法思想里最基础的思想。这也和人的基本思维有关，当我们需要解决一个大的问题时，直觉的就会将这个大问题分成多个小问题来解决。
大量的经典算法，都是基于分治法。比如，快速排序，归并排序。当然，最让人想起来的，就是二分查找了。
分治法的步骤分治，分而治之。分的原因是因为问题的规模太大，需要拆开了
            ...
          </span>
          <div class="post-more-link text-center">
            <a class="btn" href="/2015/12/17/2015-12-17-3/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-2/" itemprop="url">
                  【算法】贪心算法(0-1背包问题)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:29:34+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
            什么是贪心算法？贪心算法并不是一个具体的算法，而是一种算法的思想，或者说是解决问题一种思路。这就有两个关键的点，可以解释贪心算法：


贪心算法解决什么问题？
贪心算法是怎样的一种思路？


1. 贪心算法解决什么问题解决求最优解问题。即此问题的最终的目的，是为了得到一个最优解。比如，从A地到B地之
            ...
          </span>
          <div class="post-more-link text-center">
            <a class="btn" href="/2015/12/17/2015-12-17-2/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/2015-12-17-1/" itemprop="url">
                  一张图学会python
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:28:00+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
            偶得一图，发现此图是个非常好的python入门教程呀，特此转载，侵删！


关于此图，我想说的是，编辑器大家可以用我大sublime!


            
          </span>
          <div class="post-more-link text-center">
            <a class="btn" href="/2015/12/17/2015-12-17-1/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/12/17/xijie/" itemprop="url">
                  JavaScript一些细节
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            发表于
            <time itemprop="dateCreated" datetime="2015-12-17T15:26:51+08:00" content="2015-12-17">
              2015-12-17
            </time>
          </span>

          

          
            
          

          

        </div>
      </header>
    


    <div class="post-body">

      
      

      
        
          <span itemprop="articleBody">
            
            删除数组中的元素你或许已经知道，js中要向数组中增加元素，需要用的是push方法。没有和其他语言中类似的add方法，是不是很不适应？
但是要是告诉你，从数组中删除元素的方法没有，你是不是简直不敢相信！你如果要说用到delete关键字,那么给你看一个吓死你的：12var s=[1,2,3,4];del
            ...
          </span>
          <div class="post-more-link text-center">
            <a class="btn" href="/2015/12/17/xijie/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    

  </section>

  


        </div>

        


        

      </div>

      
        
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" src="/images/default_avatar.jpg" alt="yield" itemprop="image"/>
          <p class="site-author-name" itemprop="name">yield</p>
        </div>
        <p class="site-description motion-element" itemprop="description">唯爱与美食不可辜负</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">4</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            
              <span class="site-state-item-count">0</span>
              <span class="site-state-item-name">分类</span>
              
          </div>

          <div class="site-state-item site-state-tags">
            <a href="/tags">
              <span class="site-state-item-count">3</span>
              <span class="site-state-item-name">标签</span>
              </a>
          </div>

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/trainking" target="_blank">
                  
                    <i class="fa fa-globe"></i> github
                  
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.jianshu.com/users/3074b798c7d0/latest_articles" target="_blank">
                  
                    <i class="fa fa-globe"></i> jianshu
                  
                </a>
              </span>
            
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      

    </div>
  </aside>


      
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2015</span>
  <span class="with-love">
    <i class="icon-next-heart fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yield</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>



      </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  

  
    
    

  


  

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.2"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.2"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
<script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

<script type="text/javascript" src="/js/motion.js?v=0.4.5.2" id="motion.global"></script>


  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  

  <script type="text/javascript" src="/js/bootstrap.js"></script>

  
  

  
  

</body>
</html>

{'fraction_non_alphanumeric': 0.19326739217676636, 'fraction_numerical': 0.02934302778499091, 'mean_word_length': 2.5316381825760734, 'pattern_counts': {'":': 0, '<': 1586, '<?xml version=': 0, '>': 1586, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6130709', 'n_tokens_mistral': 17118, 'n_tokens_neox': 16639, 'n_words': 1866}