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"

SRM587 (div2)_第1张图片


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

SRM587 (div2)_第2张图片


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";
  }
};
 

你可能感兴趣的:(SRM587 (div2))