SRM587 (div2)



  第一题:InsertZ

              简单题,唉,脑子转的太慢了,我做完的时候只剩下145(250)分了。

              看了别人代码只有一行直接呆了:

	return goal.replace("z","").equals(init) ?"yes":"No";


 第二题:JumpFurther

             想一想就出来了。

int JumpFurther::furthest(int N, int badStep) {
  int pos =  0;
  bool flag = false;
  for(int i=1; i<=N; i++)
  {
        pos += i;
    if(pos ==badStep)
    {
            flag = true;
    }
  }
  if(flag) return pos-1;
  return pos;
 
}

第三题: ThreeColorabilityEasy

用红绿蓝三种颜色给顶点染色。问能否使相邻顶点染不同色。


在纸上YY,发现如果一个田字格里只有一个'N‘或者'Z'就无法三分图染色。

{“Z”}

Returns:"Yes"



{"NZ" 
,"NZ"}
Returns:"Yes"


class ThreeColorabilityEasy {
public:
  string isColorable(vector <string> cells) {
    int n = cells.size();
    int c1, c2;
    for (int i = 0; i < n - 1; i++)
    {
      for (int j = 0; j < cells[i].length() - 1; j++)
      {
        c1 = c2 = 0;
        if (cells[i][j] == 'N') c1++;
        else c2++;
        if (cells[i+1][j] == 'N') c1++;
        else c2++;
        if (cells[i][j+1] == 'N') c1++;
        else c2++;
        if (cells[i+1][j+1] == 'N') c1++;
        else c2++;
        
        if (c1 == 1 || c2 == 1) return "No";
      }
    }
    return "Yes";
  }
};
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值