posts - 24,  comments - 0,  trackbacks - 0
今天水了一道水题,下标不是从0开始的,开始没注意,WA到吐血
http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=23130
#include<cstdio>
#include
<cstring>
#include
<algorithm>
#include
<cstdlib>
using namespace std;
int main()
{
    
int n;
    scanf(
"%d",&n);
    
int cb[50];
    
int vis[3][10000];
    memset(cb,
0,sizeof(cb));
    memset(vis,
0,sizeof(vis));
    
int a,b;
    
for(int i=0; i<n; ++i)
    {
        scanf(
"%d%d",&a,&b);
        cb[a]
=b;
        vis[
0][b]=1;
        vis[
1][a-b+100]=1;
        vis[
2][a+b]=1;
    }
    
int cnt=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 tmp1=cb[i];
                
int tmp2=cb[j];
                
int tmp3=cb[k];
                vis[
1][i-tmp1+100]=0;
                vis[
1][j-tmp2+100]=0;
                vis[
1][k-tmp3+100]=0;
                vis[
2][i+tmp1]=0;
                vis[
2][j+tmp2]=0;
                vis[
2][k+tmp3]=0;
                
if(!vis[1][i-tmp2+100]&&!vis[2][i+tmp2])
                {
                    vis[
1][i-tmp2+100]=vis[2][i+tmp2]=1;
                    
if(!vis[1][j-tmp3+100]&&!vis[2][j+tmp3])
                    {
                        vis[
1][j-tmp3+100]=vis[2][j+tmp3]=1;
                        
if(!vis[1][k-tmp1+100]&&!vis[2][k+tmp1])
                        {
                            vis[
1][k-tmp1+100]=vis[2][k+tmp1]=1;
                            cnt
++;
                            vis[
1][k-tmp1+100]=vis[2][k+tmp1]=0;
                        }
                        vis[
1][j-tmp3+100]=vis[2][j+tmp3]=0;
                    }
                    vis[
1][i-tmp2+100]=vis[2][i+tmp2]=0;
                }
                
if(!vis[1][i-tmp3+100]&&!vis[2][i+tmp3])
                {
                    vis[
1][i-tmp3+100]=vis[2][i+tmp3]=1;
                    
if(!vis[1][j-tmp1+100]&&!vis[2][j+tmp1])
                    {
                        vis[
1][j-tmp1+100]=vis[2][j+tmp1]=1;
                        
if(!vis[1][k-tmp2+100]&&!vis[2][k+tmp2])
                        {
                            vis[
1][k-tmp2+100]=vis[2][k+tmp2]=1;
                            cnt
++;
                            vis[
1][k-tmp2+100]=vis[2][k+tmp2]=0;
                        }
                        vis[
1][j-tmp1+100]=vis[2][j+tmp1]=0;
                    }
                    vis[
1][i-tmp3+100]=vis[2][i+tmp3]=0;

                }
                vis[
1][i-tmp1+100]=1;
                vis[
1][j-tmp2+100]=1;
                vis[
1][k-tmp3+100]=1;
                vis[
2][i+tmp1]=1;
                vis[
2][j+tmp2]=1;
                vis[
2][k+tmp3]=1;
            }
    printf(
"%d\n",cnt);
    
return 0;
}
posted on 2011-09-08 17:37 ACSeed 阅读(186) 评论(0)  编辑 收藏 引用

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