zoukankan      html  css  js  c++  java
  • 中国海洋大学第四届朗讯杯高级组 Cash Cow(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2721

    题意: 给定n个左标,跟那n个坐标相同的 且3个以上的消失,圈都 靠下, 而且 如果一整列都没有的话,就都往左靠。。。。

    思路:比赛的时候没调试完,,,, 最坑爹的是,用后台数据测试都对了,结果还是wrong, 经过鑫哥指导。。。那些字符要以字符串的形式输入,

    否则会wrong ,后台的原因不知道为什么。。。

      1 #include <iostream>
      2 #include <cstring>
      3 #include <cstdio>
      4 #include <queue>
      5 using namespace std;
      6 
      7 int dx[5]= {1,-1,0,0};
      8 int dy[5]= {0,0,1,-1};
      9 char G[20][20],map[20][20];
     10 struct node
     11 {
     12     int x,y;
     13 }a[100];
     14 
     15 struct point
     16 {
     17     int x,y;
     18 }pos,next;
     19 void bfs(int x1,int y1)
     20 {
     21     int i,j,k,count=0;
     22     int vis[20][20];
     23     char ch;
     24     char f;
     25     f='a';
     26     memset(vis,0,sizeof(vis));
     27     ch=G[x1][y1];
     28     queue<point>q;
     29     next.x=x1;
     30     next.y=y1;
     31     vis[x1][y1]=1;
     32 
     33     q.push(next);
     34     while(!q.empty())
     35     {
     36         pos=q.front();
     37         q.pop();
     38         count++;
     39         for(i=0; i<4; i++)
     40         {
     41             next.x=pos.x+dx[i];
     42             next.y=pos.y+dy[i];
     43             if(!vis[pos.x+dx[i]][pos.y+dy[i]]&&G[pos.x+dx[i]][pos.y+dy[i]]==ch&&
     44                     pos.x+dx[i]>=1&&pos.x+dx[i]<=10&&pos.y+dy[i]>=1&&pos.y+dy[i]<=12)
     45             {
     46                 vis[pos.x+dx[i]][pos.y+dy[i]]=1;
     47                 q.push(next);
     48             }
     49         }
     50     }
     51     if(count>=3)//刚开始 没看到这句with a cluster of 3 or more circles, 
     52     {
     53         for(i=1; i<=10; i++)
     54         for(j=1; j<=12; j++)
     55         if(vis[i][j]==1)
     56         G[i][j]=f;
     57     }
     58     for(i=1; i<=10; i++)
     59     {
     60         for(j=11; j>=1; j--)//一定要倒着来,因为这个调试了好长时间。。。
     61         {
     62             if(G[i][j]==f)
     63             {
     64                 for(k=j; k<=11; k++)
     65                 {
     66                     G[i][k]=G[i][k+1];
     67                     G[i][k+1]=f;
     68                 }
     69             }
     70         }
     71     }
     72     for(i=10; i>=1; i--)//一定要倒着来,因为这个调试了好长时间。。。
     73     {
     74         if(G[i][1]==f)
     75         {
     76             for(j=i; j<=9; j++)
     77                 for(k=1; k<=12; k++)
     78                 {
     79                     G[j][k]=G[j+1][k];
     80                     G[j+1][k]=f;
     81                 }
     82         }
     83     }
     84 }
     85 int main()
     86 {
     87     int n,i,j,sum;
     88     char ch;
     89     char f;
     90     f='a';
     91     while(scanf("%d%*c",&n)!=EOF&&n)
     92     {
     93         sum=0;
     94         memset(G,0,sizeof(G));
     95         memset(map,0,sizeof(map));
     96 
     97         for(i=12; i>=1; i--)
     98         cin>>map[i];
     99 
    100         for(i=12; i>=1; i--)
    101         {
    102             for(j=1; j<=10; j++)
    103             G[j][i]=map[i][j-1];
    104         }
    105         for(i=0; i<n; i++)
    106         {
    107              cin>>ch>>a[i].y;
    108             a[i].x=ch-96;
    109             if(G[a[i].x][a[i].y]!=f)
    110             bfs(a[i].x,a[i].y);
    111         }
    112         for(i=1; i<=10; i++)
    113             for(j=1; j<=12; j++)
    114                 if(G[i][j]!=f)
    115                     sum++;
    116 
    117         printf("%d
    ",sum);
    118     }
    119     return 0;
    120 }
  • 相关阅读:
    Java并发包线程池之ThreadPoolExecutor
    Java并发包之线程池概述
    Java同步数据结构之ConcurrentHashMap
    new 操作符
    javascript-类型转换
    javascript-引用类型
    JS-数组与伪数组
    SVG-JS操作
    SVG-变换
    SVG-标签
  • 原文地址:https://www.cnblogs.com/bfshm/p/3453005.html
Copyright © 2011-2022 走看看