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

贴上我这个神奇的程序(结构体数组开1都能过)

Posted by 0810311106 at 2010-08-25 18:36:38 on Problem 1175 and last updated at 2010-08-25 18:37:52
#include"iostream"
#include"cmath" 
#define M 101
#define MIN 1e-9
using namespace std;
int ma[M][M];/*存图*/
int de[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}}; 
int W,H;
int s; 
int num; 
typedef struct node
{
   int x,y; 
}point; 
point p[1];
int ll; 
void dfs(int i,int j)
{
     int k; 
     ma[i][j]=num; /*更改图中的值,与f对应*/
     p[ll].x=i;/*获取图中像素点的位置*/
     p[ll++].y=j; 
     for(k=0;k<8;k++)
     {
        int x=i+de[k][0],y=j+de[k][1];
        if(x>=0&&x<H&&y>=0&&y<W&&ma[x][y]==1) 
            dfs(x,y); 
     } 
} 
double dis(point *a,int n)/*求一个图的标志*/
{
       double sum=0;
       for(int i=0;i<n;i++)
       for(int j=i+1;j<n;j++)
             sum+=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)*1.0+(a[i].y-a[j].y)*(a[i].y-a[j].y)*1.0);
       return sum;
} 
int main()
{ 
    while(scanf("%d%d",&W,&H)!=EOF)
    {
    int i,j;
    char str;
    double clu[27]; 
    char f[400];
    for(i=0;i<2;i++)
     f[i]='0';
    int ss=1; 
    num=2; 
    clu[0]=0.01111; 
    for(i=0;i<H;i++)
    {
        getchar();
         for(j=0;j<W;j++)
          { scanf("%c",&str);
            ma[i][j]=str-'0';
          }
    }
    for(i=0;i<H;i++)
    for(j=0;j<W;j++)
    { 
       if(ma[i][j]==1)
       {   
           int l; 
           ll=0; 
           dfs(i,j);/*图从2开始存*/ 
           double sum=dis(p,ll);
           for(l=0;l<ss;l++)/*在已经存在的标志中比较*/
              {            
                   if(fabs(clu[l]-sum)<MIN)/*存在相同的标志*/
                      {
                          f[num]=l+'a'-1;
                          break; 
                      } 
              }
              if(l>=ss)/*不存在相同的标志*/
              {
                 f[num]=ss+'a'-1;
                 clu[ss]=sum;/*生成新的标志*/
                 ss++; 
              } 
              num++;    
       } 
    }
    for(i=0;i<H;i++)
    {     
        for(j=0;j<W;j++)
          printf("%c",f[ma[i][j]]); 
        printf("\n");
   }
} 
    //system("pause");
    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