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

Re:楼主,就因为你这一句话,我整整wa了五次! 请你以后要注意素质,别随便蒙人

Posted by 117474335 at 2010-09-10 19:46:44 on Problem 2488
In Reply To:楼主,就因为你这一句话,我整整wa了五次! 请你以后要注意素质,别随便蒙人 Posted by:117474335 at 2010-09-10 19:45:28
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int T , p, q , b[100][100], k = 0 , dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}, dy[8] = {-1,1,-2,2,-2, 2, -1,1} ;
struct yan {
    int x,  y ;}yan[300] ;

int dfs (int t, int x, int y , int a[][100], struct yan yy[]) 
{
    int i ; 
    yy[t].x = x ;
    yy[t].y = y ;
    if (t == p * q - 1){
        for (i = 0 ;i < p * q ; i ++ )
            printf ("%c%d", (char)(yy[i].x + 64), yy[i].y ) ;
        printf ("\n") ;
        return 1 ; }
         
    a[x][y] = 1 ; 
    
    for (i = 0 ; i < 8 ; i ++ ) {
        if (x + dx[i] > 0 && x + dx[i] <= q && y + dy[i] > 0 && y + dy[i] <= p && ! a[x + dx[i]][y + dy[i]]){
            a[x + dx[i]][y + dy[i]] = 1 ;
            if (dfs (t + 1, x + dx[i], y + dy[i], a, yy)) 
                return 1 ;
            a[x + dx[i]][y + dy[i]] = 0 ;}} 
    return 0 ;
} 

main () 
{
    int i, j, t ;
    scanf ("%d", &T ) ;
    while (T -- ){
        k ++ ;
        scanf ("%d%d", &p, &q) ;
        printf ("Scenario #%d:\n", k ) ;
        t = 0 ;
        for (i = 1 ;i <= (q+1)/2 && ! t ;i ++ ) 
            for (j = 1 ;j <= i ; j ++ ){ 
                memset (b, 0, sizeof (b) ) ;
                if (dfs (0, i, j, b, yan) ){t = 1 ;break ;}}
        if ( !t ) printf ("impossible\n") ;
        printf ("\n") ;} 
    system ("pause") ;
} 

把注释去了就ac;不去就wa

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