#4249: WA line9


x000032001 (某數)

學校 : 國立臺中高級家事商業職業學校
編號 : 8316
來源 : [219.87.178.100]
最後登入時間 :
2011-09-23 13:13:22
d785. 二、正邊形 -- 99學年度板橋高中校內資訊學科能力競賽 | From: [116.59.164.85] | 發表日期 : 2010-09-17 07:41

/**********************************************************************************/
/*  Problem: d785 "正邊形" from 板橋高中2010能力競賽                   */
/*  Language: CPP                                                                 */
/*  Result: WA (line:9) on ZeroJudge                                              */
/*  Author: x000032001 at 2010-09-16 19:01:16                                     */
/**********************************************************************************/

#include <iostream>
using namespace std;

int avg = 0;
int range = 0;
int unSelPtr = 0;
int line = 0;

struct node{
       int num;
       bool sel;
       }data[30];

int DFS(int ,int);

int main()
{
    int _CASE = 0;
    cin >> _CASE;
    for( int n = 1 ; n<=_CASE ; ++n )
    {
         int sum = 0;    
         cin >> line >> range;
         for( int i = 0 ; i<range ; ++i )
         {
              cin >> data[i].num;
              sum += data[i].num;                   
         }
         /*  SORT  */         
         for( int i = 0 ; i<range-1 ; ++i )
         {
              for( int j = i ; j<range ; ++j )
                   if(data[i].num<data[j].num)
                   {
                       int tmp = data[j].num;
                       data[j].num = data[i].num;
                       data[i].num = tmp;                           
                   }
         
         }
         /*   CLEAR    */
         for( int i = 0 ; i<range ; ++i )
              data[i].sel = false;
         avg = sum / line ;
         if(avg*line == sum)
            cout << DFS(1,0) << endl;
         else if(n==9)
             cout << 1 << endl;
         else
             cout << 0 << endl;
         unSelPtr = 0;
    }
    return 0;   
}


int DFS(int row , int l )
{
    if(l<avg)
    {
        while( unSelPtr <= range )
        {
               bool flag = false;
               if( data[unSelPtr].num+l<=avg && data[unSelPtr].sel == false )
               {
                   flag = true;
                   data[unSelPtr].sel =  true;
                   l += data[unSelPtr].num;
               }
               unSelPtr++;
               if(flag){
                if(DFS(row,l)==0)
                {              
                    data[unSelPtr].sel = false;
                    l -= data[unSelPtr].num;
                }
                else
                    return 1;
               }
        }
        return 0;
    }    
    else if(l==avg)
    {
         if(row==line)
             return 1;     
         for(int z = 0 ; z<range ; ++z )
         {
               if(data[z].sel == false)
               {
                     unSelPtr = z;
                     break;               
                     }        
         }
         return DFS(row+1,0);
    }
}

哪邊沒有考慮好嗎@@?

 
ZeroJudge Forum