zoukankan      html  css  js  c++  java
  • 程序员的数学基础课 1 append

    数学学霸半年逆袭托福?每天只要两小时,从77分到102分,超简单

    public class Lesson1_append1 {
    	
    	public static void main(String[] args) {
    		//偶数,奇数 count
    		int even_cnt = 0, odd_cnt = 0;
    		//开始,技术时间
    		long start = 0, end = 0;
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			//i与1
    			/**
    			 * 请记住“&”是一个按位操作.您可能已经意识到这一点,但根据您提出问题的方式,我并不完全清楚.
    			 * 话虽这么说,理论上的想法是你有一些int,可以通过一些1和0的系列来表示.例如:
    			 *
    			 * ...10110110
    			 * 复制代码
    			 * 在二进制中,因为它是基数2,只要数字的按位版本以0结尾,它就是偶数,当它以1结尾时它是奇数.
    			 *
    			 * 因此,做一个按位&以上为1是:
    			 */
    			if((i & 1) == 0){
    			    even_cnt ++;
    			}else{
    			    odd_cnt ++;
    			}
    			
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		System.out.println(even_cnt + " " + odd_cnt);
    		
    		even_cnt = 0;
    		odd_cnt = 0;
    		start = 0;
    		end = 0;
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			/**
    			 * 取余2==0为偶数
    			 */
    			if((i % 2) == 0){
    			    even_cnt ++;
    			}else{
    			    odd_cnt ++;
    			}
    			
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		System.out.println(even_cnt + " " + odd_cnt);
    		
    		
    		start = System.currentTimeMillis();
    		/**
    		 * 交换数字
    		 */
    		for (int i = 0; i < 100000000; i++) {
    			int x = 3, y = 5;
    			x = (x ^ y);
    			y = x ^ y;
    			x = x ^ y;
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			int x = 3, y = 5, t = 0;
    			t = y;
    			y = x;
    			x = t;
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		
    //		System.out.println(x + " " + y);
    
    	}
    
    }
    
    
  • 相关阅读:
    树分治 poj 1741
    堆 poj 2010
    堆 poj 2442
    堆的基本操作
    状态压缩codeforces 11 D
    状态压缩 CSU1129 送货到家
    炮兵阵地 POJ 1185
    状态压缩 HDU4539 郑厂长系列故事——排兵布阵
    状态压缩 HDU 3182
    android手势创建及识别
  • 原文地址:https://www.cnblogs.com/ukzq/p/13373982.html
Copyright © 2011-2022 走看看