数学||规律
别哔哔好伐
安静的coder
展开
-
HDU1143 Tri Tiling 递推
#includeint main(){ int f[31]; int i,L; int n; f[0]=1; for(i=1;i<=30;i+=2) f[i]=0; for(i=2;i<=30;i+=2) { f[i]=0; for(L=2;L<=i;L+=2) { if(L==2) f[i]+=3*f[i-L]; else f[i]+=2*f[i-原创 2014-11-13 20:42:46 · 633 阅读 · 0 评论 -
leetcode-190-Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represen原创 2015-08-01 22:34:58 · 495 阅读 · 0 评论 -
leetcode-242-Valid Anagram
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return f原创 2015-08-01 21:27:47 · 716 阅读 · 0 评论 -
筛选法求素数
筛选法求素数。将合数都标记,剩下的就是素数。出现一个数,则把已这个数为因子的数都标记为合数。如2,所以4,6,8 10....都标记为合数如3,所以9,12,15.....都标记为合数如4,所以16,20,24...都标记为合数即,若i是素数,则从 j=i*i 开始,把 j+i , j+2i , j+3i .....都标记为合数 (因为从2*i , 3*i,原创 2015-07-21 21:16:03 · 1030 阅读 · 0 评论 -
leetcode-172-Factorial Trailing Zeroes
Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.求 n!中,末尾的0连续有多少个。例如 10!=10*原创 2015-08-31 19:25:09 · 496 阅读 · 0 评论 -
leetcode-258-Add Digits
Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2.原创 2015-08-31 13:19:39 · 577 阅读 · 0 评论 -
leetcode-292-Nim Game
Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last原创 2015-10-18 20:20:42 · 386 阅读 · 0 评论 -
巴什博奕
下面这段来自白白の屋的文章的一段:巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果原创 2015-10-18 20:14:11 · 369 阅读 · 0 评论 -
leetcode-283-Move Zeroes
Move ZeroesGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 1原创 2015-09-21 13:20:51 · 329 阅读 · 0 评论 -
leetcode-326-Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?Credits:Special thanks to @dietpepsi for adding this原创 2016-01-11 23:22:00 · 561 阅读 · 0 评论 -
leetcode-231-Power of Two
Power of TwoGiven an integer, write a function to determine if it is a power of two.判断给出的数,是否为2的次方,如1,2,4,8,16... 移位操作,2的次方的数,换位2进制表示,都是第一个为1 ,其后面都是0,。如8=1000class Soluti原创 2015-07-17 19:25:08 · 586 阅读 · 0 评论 -
leetcode-263-Ugly Number
Ugly Number Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly原创 2015-08-24 09:47:40 · 587 阅读 · 0 评论 -
Codeforces-475B Strongly Connected City
只用判断最外层是不是回路 如果是 则每两个点之间连通#include#include#include#include#define INF 200000using namespace std;int main(){ char a[3][22]; int n,m,i,j; scanf("%d%d",&n,&m); getchar();原创 2014-11-19 21:16:47 · 984 阅读 · 0 评论 -
codeforces-#287-- 507B Amr and Pins
B. Amr and Pinstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr loves Geometry. One day he came up with原创 2015-01-24 13:45:16 · 892 阅读 · 0 评论 -
快速幂取模
用二分,使复杂度由 O(n) 变为 O(logn)#include#includeusing namespace std;/// (b^n)mod m; (a*b mod m) = (a mod m)*(b mod m)mod m O(log n)/// (b^n)mod m; (a - b ) mod m =( (a mod m)-(b mod m)原创 2015-07-09 15:20:02 · 746 阅读 · 0 评论 -
leetcoder-50-Pow(x, n)
Pow(x, n) 可以直接用库函数pow(x,n)一步搞定,但明显这样就没意思了。参考快速幂取模二分,复杂度为O(logn)递归方法class Solution {public: double myPow(double x, int n) { if(n<0) return 1.0/myPow_1(x,-n);原创 2015-07-09 16:46:30 · 856 阅读 · 0 评论 -
全排列
全排列暴力枚举,每次在数组中选一个数,能则继续选下一个,否则另找一个数。#include /// 排列#include#includeusing namespace std;void next(int n,int* a,int cur) ///1~n的全排列 cur为要填充的位置{ if(cur==n){ for(int i=0;i<n;i++)prin原创 2015-07-09 18:13:49 · 817 阅读 · 0 评论 -
leetcode 46-Permutations and 47-Permutations II
PermutationsGiven a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]原创 2015-07-09 20:22:06 · 758 阅读 · 0 评论 -
leetcode-191-Number of 1 Bits
Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11'原创 2015-06-21 01:51:10 · 264 阅读 · 0 评论 -
leetcode-136-Single Number
Single Number Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implem原创 2015-06-21 01:58:44 · 389 阅读 · 0 评论 -
leetcode-204-Count Primes
Count PrimesDescription:Count the number of prime numbers less than a non-negative number, n.题目 Count Primes计算小于n的所有素数的总数。用一般的方法超时,应该用筛选法求素数 ,参考 筛选法求素数class Solution {publ原创 2015-07-26 19:48:10 · 633 阅读 · 0 评论 -
leetcode-338-Counting Bits
338. Counting BitsGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.原创 2016-03-19 11:09:40 · 1463 阅读 · 0 评论