zoukankan      html  css  js  c++  java
  • Codeforces Round #176 (Div. 2)总结A. IQ Test

    A. IQ Test
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In the city of Ultima Thule job applicants are often offered an IQ test.

    The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most onecell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.

    Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.

    Input

    Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.

    Output

    Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.

    Sample test(s)
    input
    ####
    .#..
    ####
    ....
    output
    YES
    input
    ####
    ....
    ####
    ....
    output
    NO
    Note

    In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.

    分析:水题~,给定一个4*4的格子,在里面找有没有一个2*2的格子(要求2*2的格子中至少有三个格子里面的符号是相同的),我的做法是直接考虑左上角的9个格子,对它们每一个格子都进行判断,例如判断的是(i,j)这个格子,只需要判断(i,j),(i+1,j),(i,j+1),(i+1,j+1),这四个格子中的符号是否至少有三个格子是相同的,如果是,就直接跳出,输出YES,否则继续查找,直到找遍左上角的9个格子,如果还没找到则输出NO。方法很水~但是能过~

    AC code

    View Code
     1 #include <iostream>
     2 #include<stdio.h>
     3 char s[5][5];
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     while(scanf("%s",s[0])!=EOF)
     9     {
    10         getchar();
    11         scanf("%s",s[1]);
    12         getchar();
    13         scanf("%s",s[2]);
    14         getchar();
    15         scanf("%s",s[3]);
    16         getchar();
    17         int i,j;
    18         int bsum,wsum;
    19         for(i=0;i<3;i++)
    20         {
    21             for(j=0;j<3;j++)
    22             {
    23                  bsum=0;
    24                  wsum=0;
    25                  if(s[i][j]=='#')bsum++;
    26                  else wsum++;
    27                  if(s[i+1][j]=='#')bsum++;
    28                  else wsum++;
    29                  if(s[i][j+1]=='#')bsum++;
    30                  else wsum++;
    31                  if(s[i+1][j+1]=='#')bsum++;
    32                  else wsum++;
    33                  if(bsum>=3||wsum>=3)
    34                  break;
    35             }
    36             if(bsum>=3||wsum>=3)
    37             break;
    38         }
    39         if(bsum>=3||wsum>=3)
    40         printf("YES\n");
    41         else printf("NO\n");
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    iOS开发——多线程篇——NSOperation(基于GCD多线程编程),下载图片并合成新图片
    iOS开发——多线程篇——GCD
    iOS开发——多线程篇——NSThread
    iOS开发——多线程篇——多线程介绍
    iOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果
    推荐系统_七月算法4月机器学习班第9次课程笔记
    STL源码分析读书笔记--第三章--迭代器(iterator)概念与traits编程技法
    C语言基础(不断更新)
    字节对齐总结
    大端模式与小端模式
  • 原文地址:https://www.cnblogs.com/ACshasow/p/3019005.html
Copyright © 2011-2022 走看看