Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁能解释这个问题?up = (up<<(sub_col-1)) -1;改成:up = (1 <<(sub_col-1)) -1;就超时,怎么可能?

Posted by angeldespace at 2008-10-26 16:38:15 on Problem 3690
#include<cstdio>


using namespace std;
int ans;
int row,col,num,sub_row,sub_col;
char stars[1001][1001];
__int64 standard[1000][1000];
__int64 subst[101][51];

__int64 convert(char *str){
     __int64 VAL = 0;
     for(int j = 0; j < sub_col; j++){
        VAL <<= 1;
        VAL +=   str[j] == '*' ? 1 : 0 ;
     }
    return VAL;
}
void initial(){
   __int64 up = 1,VAL = 0;

   up = (up<<(sub_col-1)) -1;
   /////改成:up = (1 <<(sub_col-1)) -1;就超时///怎么可能?


   for(int i = 0; i < row ; i++){
      VAL = 0;
     for(int j = 0; j < col ; j++){
        VAL <<= 1;
        VAL += stars[i][j] == '*' ? 1: 0;
        if(j >= sub_col-1){
           standard[i][j - sub_col + 1] = VAL;
           VAL &= up;
        }
     }
   }
   col = col - sub_col + 1;
   row = row - sub_row + 1;
}

void intput(){
   for(int i = 0; i < row; i++)
     scanf("%s",stars[i]);
   char str[61];
   for(int i = 0; i < num; i++){
        getchar();
        for(int j = 0; j < sub_row; j++){
           scanf("%s",str);
           subst[i][j] = convert(str);
        }
   }
}

void slove(){
    ans = 0;
    int que[100];
    int size = num,tmp;
    for(int i = 0; i < num;  i++)
       que[i] = i;
    for(int i = 0; i < row; i++){

      for(int j = 0; j < col; j++){
      
            tmp = 0;
            for(int k = 0; k < size;  k++)
            {
                int tt = 0;
                for(tt ; tt < sub_row; tt++) {
                    if(standard[i+tt][j] != subst[que[k]][tt]){
                     break;
                    }
                }
                if(tt >= sub_row){
                    ans ++;
                }
                else que[tmp++] = que[k];
             }
             size = tmp;
     }
    }

}
int main(){
   int c_nt = 0;
   while(scanf("%d %d %d %d %d",&row,&col,&num,&sub_row,&sub_col)){
       if(!row&&!col&&!num&&!sub_row&&!sub_col)  return 0;
       intput();
       initial();
       slove();
       printf("Case %d: %d\n",++c_nt, ans);

   }
   return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator