Codeforces Round #632 (Div. 2)

Codeforces Round #632 (Div. 2)

A - Little Artem

题意:
有白色块W,与黑色块B, 当白色块四个方向有黑色块时,
才算白色块+1, 同理黑色块相加一也是要四周有白色块。
现在给n行m列, 要求白色块数量多余黑色块。

分析:
刚开始看不懂题 后来知道什么意思,结果陷到了一个破想法里面
,我想在最后一行在改变白色黑色块,根据上一行。
还要分奇数偶数。太麻烦了,最后花了一个小时才过了
菜是原罪。

下面展示`我的代码`。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath> 
typedef long long ll;
using namespace std;
int main()
{
 int t;
 int n, m;
 scanf("%d",&t);
 while(t --)
 {
  scanf("%d%d",&n,&m);
  for(int i = 0; i < n-1; i ++)
  {
   for(int j = 0; j < m; j ++)
   {
    if((i+j) % 2 == 1)
    printf("W");
    else
    printf("B");
   }
   printf("\n");
  }
  if(n*m %2 == 1 && n%2 == 1)
  {
   for(int i = 0; i < m; i ++)
   {
    if(i % 2== 1)
    printf("W");
    else
    printf("B");
   }
   printf("\n");
  }
  else
  if(n*m %2 == 0&&n%2 == 1)
  {
   for(int i = 0; i < m-1; i ++)
   {
    if(i % 2== 0)
    printf("B");
    else
    printf("W");
   }
   printf("B");
   printf("\n");
  }
  else
  if(n*m%2 == 0&&n%2 == 0)
  {
   printf("B");
   for(int i = 1; i < m; i ++)
   {
    if(i % 2 == 0)
    printf("W");
    else
    printf("B");
   }
   printf("\n");
  }
 }
 return 0;
}

我的简直是繁琐且没用,就是脱裤子放屁。

大佬的想法
: 如果想让W比B小一个,那么第一个为W其他为B即可了。

下面展示大佬代码

#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 10;
 
int n, m;
int T;
 
int main()
{
    cin >> T;
    while(T --)
    {
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i ++)
        {
        
        for (int j = 1; j <= m; j ++)
        {
            if(i == 1 && j == 1)
            {
                cout << "W";
            }
            else
            cout << "B";
        }
        cout << endl;
    }
    }
}

看了之后 我想自杀…
简直为我昨天浪费的时间羞愧!!!

B. Kind Anton

题意:
给两个数组A,B,注意! A的数组的元素只有三种{-1,0,1}
(这个是解题的关键,我就忘了 所以就憨了第一次敲得)
让A数组选择 (i j) 使a[j] = a[i] + a[j]。 如果每个数字都有
ij 使得a[j] = b[j]。就输出yes 否则输出no;

分析:
必须用map 否则超时。 还有就是注意要还原s 。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
typedef long long ll;
const int maxn = 1e6+6;
using namespace std;
int a[maxn], b[maxn], sum[maxn];
map<int,int>s;
int main()
{
 int t, n;
 scanf("%d",&t);
 while(t --)
 {
  int z = 1;
  s.clear();
  scanf("%d",&n);
  for(int i = 0; i < n; i ++)
  {
   scanf("%d",&a[i]);
   s[a[i]] ++;
  }
  for(int i = 0; i < n; i ++)
  {
   scanf("%d",&b[i]);
  }
  if(a[0] != b[0])
  {
   printf("NO\n");
   continue;
  }
  for(int i = n-1; i > 0; i --)
  {
   s[a[i]] --;
   if(a[i] == b[i])
   {
    continue;
   }
   if(a[i] < b[i])
   {
    if(!s[1])
    {
     z = 0;
     break;
    }
   }
   if(a[i] > b[i])
   {
    if(!s[-1])
    {
     z = 0;
     break;
    }
   }
  }
  if(z == 1)
   {
    printf("YES\n");
   }
   else
   {
    printf("NO\n");
   }
 }
 return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值