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

wa...

Posted by veryl at 2014-06-28 22:16:45 on Problem 1022
#include <stdio.h>
#include <string.h>
#include <stdio.h>
int m_block=0;
bool used[101]={0};
int block[101][9];
int idx[20000];
int zuobiao[101][4];
int bb=0;
int weizhi[8][4]={
    {1,0,0,0},
    {-1,0,0,0},
    {0,1,0,0},
    {0,-1,0,0},
    {0,0,1,0},
    {0,0,-1,0},
    {0,0,0,1},
    {0,0,0,-1}};
int check_n(int n){        
    if (bb==1) return 0;
    int index=idx[n];
    used[n]=true;
    for (int i=1;i<=8;++i){
        int test=block[index][i];
        if (test!=0 && used[test]==false) {
            int shoud_be=i^1;
            if (block[idx[test]][shoud_be]!=n) return bb=1;   
            else {
                for (int j=0;j<4;++j){
                    zuobiao[test][j] = zuobiao[n][j]+weizhi[i-1][j];
                }
                check_n(test);
            }
        }
    }
    return 0;
}
int calc_v(){
    int v=1;
    for (int j=0;j<4;++j){
    int min=4000,max=0;
       for (int i=0;i<m_block;++i){
           int index = block[i][0];
           if (zuobiao[index][j]<min) min=zuobiao[index][j];
           if (zuobiao[index][j]>max) max=zuobiao[index][j];
       }
       v = v*(max-min+1);
    }
    return v;
}
bool Inconsistent() {
    if (bb==1) return true;
    for (int i=0;i<m_block;++i) {
        int index = block[i][0];
        if (used[index]==false) return true;
    }
    return false;
}   
int main () {
    int m_case=0;
    scanf("%d",&m_case);
    while (m_case--) {
          scanf("%d",&m_block);
          memset(used,0,sizeof(used));
          memset(block,0,sizeof(block));
          memset(zuobiao,0,sizeof(zuobiao));
          memset(idx,-1,sizeof(idx));
          bb=0;
          for (int i=0;i<m_block;++i) {
              for (int j=0;j<=8;++j){
                  scanf("%d",&block[i][j]);
              }
              idx[block[i][0]]=i;
          }
          int first_id = block[0][0];
          for (int i=0;i<4;++i){
              zuobiao[first_id][i]=2000;
          }
          check_n(first_id);
          if (Inconsistent()) {
              printf("Inconsistent\n");
          } else {
              printf("%d\n",calc_v());
          }
    }
}

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