[2016-02-03][ACM][滚动数组][位运算]

[2016-02-03][ACM][滚动数组][位运算][长度只有2,使用位运算更加快速]

滚动数组,如果长度只有2,使用位运算更加快速

1
2
3
4
5
6
7
8
9
10
11
12
#include<cstdio>
using namespace std;
int main(){
         int a[2];
         //使用cur作下标表示,使用 ^位运算,比使用 %取模运算更快
         int cur = 1;
         while (expression){
                 //do something a[cur] = ???;
                 cur ^= 1;
         }
         return  0;
}


来自为知笔记(Wiz)


你可能感兴趣的:([2016-02-03][ACM][滚动数组][位运算])