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

I just can't figure out why ALWAYS WA...

Posted by razrlele at 2014-11-07 16:06:47 on Problem 3251
/*************************************************************************
* File Name: poj3251.cpp
* Author: razrLeLe
* Mail: razrlele@outlook.com
* Homepage: http://razrlele.com
* Created Time: 2014年11月06日 星期四 15时29分02秒
************************************************************************/


#include "vector"
#include "set"
#include "deque"
#include "queue"
#include "algorithm"
#include "functional"
#include "iostream"
#include "cstdio"
#include "cmath"
#include "cstdlib"
#include "string"
#include "cstring"
#include "string.h"

using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 110;
char grid[maxn][maxn];
int gridnum;
int maxarea;

int main()
{
    #ifdef LOCAL
    freopen("/home/razrlele//build/data.txt", "r", stdin);
    freopen("/home/razrlele/build/out.txt", "w", stdout);
    #endif
    scanf("%d", &gridnum);
    for(int i = 1; i <=  gridnum; i++)
    {
        getchar();
        for(int j = 1;j <= gridnum; j++)
        {
            scanf("%c", &grid[i][j]);
        }
    }
    maxarea = 0;

    for(int i = 1; i <= gridnum; i++)
    for(int j = 1; j <= gridnum; j++)
    {
        if(grid[i][j] == 'J')
        {
            for(int k = gridnum; k >= i; k--)
            for(int m = 1; m <= gridnum; m++)
            {
                if(grid[k][m] == 'J' && !(i==k&&j==m))
                {
                    int p = i-k , q = j-m;
                    int dis = p*p+q*q;
                    if((dis>>1) <= maxarea) continue;
                    int x1 =(i-j+m+k)>>1;
                    int y1 = i+m-x1;
                    int x2 = (j+i+k-m)>>1;
                    int y2 = j+k-x2;
                    
                    #define ok(a,b,c,d) (a>0&&a<=gridnum&&b>0&&b<=gridnum&&c>0&&c<=gridnum&&d>0&&d<=gridnum)
                    if(ok(y1, x1, x2, y2) && ((grid[x1][y1]=='J' && grid[x2][y2] != 'B')
                                              || (grid[x1][y1] != 'B' && grid[x2][y2] == 'J')))
                       maxarea = (dis>>1);
                }
            }
        }
    }
    printf("%d\n", maxarea);
    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