xfstart07
Get busy living or get busy dying
#include < iostream >
#include
< cmath >
using   namespace  std;

int  n;
int  p[ 51 ] = { 0 };
int  ans = 0 ;
void  check( int  x, int  y, int  z){
    
for ( int  i = 1 ;i <= n; ++ i){
        
if (i != x && abs(i - x) == abs(p[i] - p[x]))  return ;
        
if (i != y && abs(i - y) == abs(p[i] - p[y]))  return ;
        
if (i != z && abs(i - z) == abs(p[i] - p[z]))  return ;
    }
    ans
++ ;
}
int  main()
{
    cin
>> n;
    
for ( int  i = 1 ;i <= n; ++ i){
        
int  j; cin >> j >> p[j];
    }
    ans
= 0 ;
    
for ( int  i = 1 ;i <= n - 2 ; ++ i)
        
for ( int  j = i + 1 ;j <= n - 1 ; ++ j)
            
for ( int  k = j + 1 ;k <= n; ++ k){
                
int  tmp = p[i]; p[i] = p[j]; p[j] = p[k]; p[k] = tmp;
                check(i,j,k);
                tmp
= p[i]; p[i] = p[j]; p[j] = p[k]; p[k] = tmp;
                check(i,j,k);
                tmp
= p[i]; p[i] = p[j]; p[j] = p[k]; p[k] = tmp;
            }
    cout
<< ans << endl;
    
return   0 ;
}




posted on 2009-06-05 20:34 xfstart07 阅读(162) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理