Leetcode 319 Bulb Switcher 找规律】的更多相关文章

有n盏关着的灯,第k轮把序号为k倍数的关着的灯打开,开着的灯关闭. class Solution { public: int bulbSwitch(int n) { return (int)sqrt(n*1.0); } };…
319. Bulb Switcher My Submissions QuestionEditorial Solution Total Accepted: 15915 Total Submissions: 39596 Difficulty: Medium There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the thi…
题目描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle e…
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i…
智商压制的一道题 这个题有个数学定理: 一般数(非完全平方数)的因子有偶数个 完全平凡数的因子有奇数个 开开关的时候,第i个灯每到它的因子一轮的时候就会拨动一下,也就是每个灯拨动的次数是它的因子数 而拨动偶数次是关,拨动奇数次是开 现在就是求哪些数的因子有奇数个,也就是求n以内的完全平凡数 这里又有一个定理: n以内的完全平方数个数是sprt(n) 所以代码很简单 public int bulbSwitch(int n) { return (int)Math.sqrt(n); }…
[LeetCode]319. Bulb Switcher 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/bulb-switcher/description/ 题目描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the t…
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i…
题目: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle eve…
初始时有 n 个灯泡关闭. 第 1 轮,你打开所有的灯泡. 第 2 轮,每两个灯泡切换一次开关. 第 3 轮,每三个灯泡切换一次开关(如果关闭,则打开,如果打开则关闭).对于第 i 轮,你每 i 个灯泡切换一次开关. 对于第 n 轮,你只切换最后一个灯泡的开关. 找出 n 轮后有多少个亮着的灯泡.示例:给定 n = 3.状态off表示灯泡关闭,on表示开启.初始时, 灯泡状态 [off, off, off].第一轮后, 灯泡状态 [on, on, on].第二轮后, 灯泡状态 [on, off,…
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the i-th round, you toggle every …
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…
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the nth round, you only toggle th…
问题描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the nth round, you only tog…
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…
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就可以吃掉所有的.所以first必赢,} else {first无法一口吃掉所有的,所以second成了主动的了,如果first第一口吃掉k1个,那么明智的second只要吃掉k2个就可以了(n-k1-k2是偶数,也包括 0的),使得 剩下的数字是分成两个数字数目相等的堆,以后的工作便是first做什么,那么s…
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>…
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 85 Accepted Submission(s): 31 Problem Descr…
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasi…
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举…
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <algorithm> #include <vector> #include <set> #include <cmath> using namespace std…
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. There are exactly i javabeans in the i-th box (i = 1, 2, 3,...n). Everyday Javaman chooses an integer x. He also chooses several boxes where the numb…
递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步骤: 1.定义方法,以及方法中的参数--power( int base ,int n ) 2.根据定义的方法来找规律: 函数终止条件:n==0时,返回1:n<0时,返回-1:红色箭头表示函数的执行过程,蓝色箭头表示函数达到条件后开始一层一层的返回值,具体代码如下: long power(int ba…
讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solved: 380 [Submit][Status][Discuss] Description 小E 与小W 进行一项名为"E&D"游戏.游戏的规则如下:桌子上有2n 堆石子,编号为1..2n.其中,为了方便起见,我们将第2k-1 堆与第2k 堆(1 ≤ k ≤ n)视为同一组.第i堆…
Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3032 Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps.…
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数位DP:http://blog.csdn.net/libin56842/article/details/11580497 */ #include <cstdio> #include <iostream> #include <algorithm> #include <c…
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn.net/ahfywff/article/details/7432524 */ #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <iostrea…
Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop…
Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6012   Accepted: 3341 Description N children standing in circle who are numbered 1 through N clockwise are waiting their candies. Their teacher distributes the candies by in the following w…
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The b…