Bulb Switcher

题目
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.

Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:

Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...

答案

class Solution {
    public int flipLights(int n, int m) {
        if(m == 0) return 1;
        if(n == 1) return 2;
        if(n == 2) {
            if(m == 1) return 3;
            if(m >= 2) return 4;
        }
        if(n >= 3) {
            if(m == 1) return 4;
            if(m == 2) return 7;
            if(m >= 3) return 8;
        }
        return 0;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • 这一季谢谢你们的陪伴,是你们在我最需要的时候陪着我,是你们在让我在九月的各奔东西中感到暖暖的热流! 第一个认识的是...
    薄柒染阅读 386评论 0 0
  • 正枯坐在窗前,看远处那群鸽子在低空盘旋,看那些红蓝色的屋顶平台,有人来来回回地走动,晾晒的床单正悠然地飘呀飘,搅动...
    秦倪阅读 399评论 0 0
  • 我想写下一些东西,趁我还记得的时候。 每次看《千与千寻》都会哭,就是会莫名其妙的感动,我也不知道要哭的点在...
    野生妹妹啊阅读 1,312评论 0 1