zoukankan      html  css  js  c++  java
  • poj1656---数黑格子

    题意:有white,black,test操作

    black将给定范围涂黑,white将给定范围涂白,test将给定范围的黑格子数出来并且输出

    思路:无论哪个操作格子范围都在  (x,y)  (x+L-1,y+L-1),行跨度:x到x+L-1,列跨度:y到y+L-1

    一个white操作,使用两个for循环对这一范围内的元素赋值,1位黑,0为白

    以上行列跨度为1开始的,如果想直接引用,100*100数组最上面增加1行,最左边增加一列

    arr[101][101],可以直接引用

    #include <stdio.h>
    #include <stdlib.h>
    #include<string.h>
    int table[101][101],row,col;
    void white(int x,int y,int L)
    {
        for(row=x;row<=(x+L-1);row++)
        {
            for(col=y;col<=(y+L-1);col++)
            {
                table[row][col]=0;
            }
        }
    }
    void black(int x, int y ,int L)
    {
        for(row=x;row<=(x+L-1);row++)
        {
            for(col=y;col<=(y+L-1);col++)
            {
                table[row][col]=1;
            }
        }
    }
    
    int test(int x, int y ,int L)
    {
        int count=0;
        for(row=x;row<=(x+L-1);row++)
        {
            for(col=y;col<=(y+L-1);col++)
            {
                if(table[row][col]==1)
                    count++;
            }
        }
        return count;
    }
    
    
    int main()
    {
        int n,x,y,L,count;
        char str[8];
        memset(table,0,sizeof(table));
        scanf("%d",&n);
        while(n--)
        {
            scanf("%s%d%d%d",str,&x,&y,&L);
            if(strcmp(str,"WHITE")==0)
            {
                white(x,y,L);
            }
            else if(strcmp(str,"BLACK")==0)
            {
                black(x,y,L);
            }
            else
            {
                count=test(x,y,L);
                printf("%d
    ",count);
            }
        }
        return 0;
    }
  • 相关阅读:
    Git 分支管理
    Kubernetes 中文文档
    Docker 命令大全
    Redis 常用命令 大全
    Docker 资源汇总
    Docker 安装 Redis
    JavaScript闭包
    CSS选择器
    JavaScript类型转换
    javascript字符串处理方法
  • 原文地址:https://www.cnblogs.com/gabygoole/p/4495359.html
Copyright © 2011-2022 走看看