为什么,加了一个计数的变量,运算速度反而变的快一些?
#include <iostream>
#include<ctime>
using namespace std;
typedef struct Line{
unsigned long long arg[32];
} Line;
Line map[2000];
Line a,b;
int lineTemp[2000];
int M,N;
int res,range,max;
unsigned long long flag;
void init(){
res = 0;
range = N%64? N/64 + 1 : N/64;
int i,j,t,x;
for(i = 0; i < M; ++i){
for(j = 0; j < N; ++j){
scanf("%d",&lineTemp[j]);
}
for(j = 0,x = 0; j < range && x<N; ++j){
flag = 0;
for(t = 0; t<64 && x<N; t++){
if(lineTemp[x])
flag += ((unsigned long long)1<<t);
++x;
}
map[i].arg[j] = flag;
}
}
}
void aYUb(){
for(int i = 0; i < range; ++i){
a.arg[i] = a.arg[i] & b.arg[i];
}
}
int getOne(){
int max = 0,col = 0,i,j;
for(i = range-1; i >= 0; --i){
for(j = 63; j >= 0; --j){
if ( (a.arg[i] & ((unsigned long long)1<<j ))){
++col;
}
else{
if(max < col) max = col;
col = 0;
}
}
}
if(max < col) max = col;
return max;
}
void nextLine(int nowLine){
a = map[nowLine];
int n = 1,max = 0;
while(n <= M){
max = getOne() * n;
if(max == 0)
return ;
if(res < max){
res = max;
}
if ( (max = nowLine + n) < M )
b = map[max];
else{
break;
}
aYUb();
++n;
}
}
int main(){
clock_t start,finish;
start=clock();
freopen("a.txt","r",stdin);
freopen("b.txt","w",stdout);
int count = 0; //***********************就是这里,
while(scanf("%d%d",&M,&N)!=EOF){
++count; //*************************加了,变的快,不加,反而变的慢了
init();
for(int i = 0; i < M; ++i)
nextLine(i);
printf("%d\n",res);
}
finish=clock();
cout << finish-start << "/" << CLOCKS_PER_SEC << " (s) "<< endl;
}