每日一道思维题——1725H - Hot Black Hot White

题意:给定n个整数Ai,定义一种运算concat(Ai,Aj)讲AiAj拼接在一起如concat(12,34)=1234

若i,j上颜色不同有运算concat(Ai,Aj)×concat(Aj,Ai)+Ai×Aj≡Zmod3

思路:

 

 

代码:

#include<iostream>
using namespace std;
const int N = 1e5+10;
int a[N];
int main()
{
  int n, cnt = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
    long long t;
    scanf("%lld", &t);
    a[i] = (t*t)%3;
    if(a[i])//非0
      cnt ++;
  }

  if(cnt < n/2)//非0个数小于0
  {
    printf("2\n");
    int res = (n-2*cnt)/2;//内部分配组数
    for(int i = 0; i < n; i++)
    {
      if(a[i])
        printf("1");
      else if(res){
        printf("1");
        res--;
      }else{
        printf("0");
      }
    }
    printf("\n");
  }else{
    printf("0\n");
    int res = (2*cnt-n)/2;//内部分配组数
    for(int i = 0; i < n; i++)
    {
      if(!a[i])
        printf("0");
      else if(res){
        printf("0");
        res--;
      }else{
        printf("1");
      }
    }
    printf("\n");
  }
    return 0;
}

反思:

要好好注意格式要求,多带空格wa了一发

检查是否需要开long long,因为忘记t开longlong又wa一发A

posted on 2023-03-02 20:17  玛卡巴卡要ac  阅读(28)  评论(0)    收藏  举报

导航