zoukankan      html  css  js  c++  java
  • CCF_ 201512-3_画图

    直接模拟就行了,注意坐标系方向与平常数组不一样,填充操作用深搜和广搜都可以,这里用了广搜。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    using namespace std;
    
    struct point{
        int x,y;
    };
    
    int m,n,q,dir[][2] = {{0,1},{0,-1},{-1,0},{1,0}};
    char a[105][105];
    
    void line()
    {
        int x1,x2,y1,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(x1 == x2)
        {
            int down = min(y1,y2),up = max(y1,y2);
            for(int i = down;i <= up;i++)
            {
                if(a[i][x1] == '-' || a[i][x1] == '+')  a[i][x1] = '+';
                else    a[i][x1] = '|';
            }
        }
        else
        {
            int left = min(x1,x2),right = max(x1,x2);
            for(int i = left;i <= right;i++)
            {
                if(a[y1][i] == '|' || a[y1][i] == '+')   a[y1][i] = '+';
                else    a[y1][i] = '-';
            }
        }
    }
    
    void bfs()
    {
        point start;
        char str;
        cin >> start.x >> start.y >> str;
        a[start.y][start.x] = str;
        queue<point> q;
        q.push(start);
        while(!q.empty())
        {
            int x = q.front().x,y = q.front().y;
            q.pop();
            for(int i = 0;i < 4;i++)
            {
                int xx = x+dir[i][0],yy = y+dir[i][1];
                if(xx < 0 || xx >= m || yy < 0 || yy >= n || a[yy][xx] == '-' || a[yy][xx] == '|' || a[yy][xx] == '+' || a[yy][xx] == str)   continue;
                point temp;
                temp.x = xx;
                temp.y = yy;
                q.push(temp);
                a[yy][xx] = str;
            }
        }
    }
    int main()
    {
        cin >> m >> n >>q;
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < m;j++)    a[i][j] = '.';
        }
        while(q--)
        {
            int flag;
            cin >> flag;
            if(flag)    bfs();
            else        line();
        }
        for(int i = n-1;i >= 0;i--)
        {
            for(int j = 0;j < m;j++)    cout << a[i][j];
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    费马小定理
    CF 1365D Solve The Maze
    CF 1367D Task On The Board
    CF 1368B Codeforces Subsequences
    CF 1368C Even Picture
    mybatis框架
    Ajax
    jdbc
    jQuery
    JSP
  • 原文地址:https://www.cnblogs.com/zhurb/p/5844262.html
Copyright © 2011-2022 走看看