NEU OJ 1651 Great number】的更多相关文章

循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostream> #include<cstring> using namespace std; ; long long mod1(char *a1,int b) { ] = {}; ] = {}; long long i, k, d; k = strlen(a1); ; i < k; i++)…
先来一次线性素数筛,把1到10000000的素数都筛选出来,然后暴力跑一遍所有可能的值,打个表,查询的时候o(1)效率出解. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<cstring> using namespace std; ; },num_prime = ; , }; +]; +];…
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Number. Suppose we have following (3m+1) numbers in the array A: x0, x1, x1, x1, ..., xm, xm, xm We are asked to find out the value of x0. However we ca…
Prolbem link: http://oj.leetcode.com/problems/single-number/ This prolbem can be solved by using XOR(exclusive OR) operation. Let x, y, and z be any numbers, and XOR has following properties: x XOR 0 is itself, i.e. x XOR 0 = 0; x XOR x is 0, i.e. x…
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number contain all digit 7 or only 1 digit other than 7. For example, 777 is a happy number because 777 contail all digit 7, 7177 and 87777 both happy number…
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the…
题目: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated a…
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated as an…
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the…
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 while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty…
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a string instead of an i…
题目: 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 while 14 is not ugly since it includes another prime factor 7. Note that 1 i…
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:691 解决:412 题目描述: Starting from point (0,0) on a plane, we have written all non-negative integers 0,1,2, ... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 给你一个数n,让你求 这个要是直接算的话肯定TLE,要是用1e8的数组预处理存储答案也一定MLE. 所以我用1e6的数组存储每100个数的答案,然后每次给你n的时候顶多算99次. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int…
优先级队列 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std; int n; int main() { while(~scanf("%d",&n)) { ; priority_queue<int>Q; while(n--) { int x; sc…
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true 基本上是leetCode上通过率最低的一道了,自己写了很多遍,就是有小问题通不过,最后参考了别人的写法,很精简,代码如下所示: bool…
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example,Given nums = [0, 1, 3] return 2. Note:Your algorithm should run in linear runtime complexity. Could you implement it usi…
先举个例子,假如给你的数是100的话,将100/2=50;是不是就是100除100-51之间的数取整为1: 100/3=33;100除50到34之间的数为2,那么这样下去到sqrt(100);就可以求得100除以sqrt(100)+1到100之间数的和,也就是后90项的和以求得. 剩余的前10项直接代公式求就行了. 复杂度为2*sqrt(N); http://lightoj.com/volume_showproblem.php?problem=1245 1 #include<stdio.h>…
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制等等... 有些题目还需要大家对程序的效率做出优化..大一的小宝宝可能有一些吃不消..当成是一种体验就好了. 题解目录: ZUFE OJ 2307: 最长连续不下降子串 ZUFE OJ 2308: Lucky Number ZUFE OJ 2309: 小明爱吃面 ZUFE OJ 2310: 小明爱消除 ZUF…
转载自:http://blog.csdn.net/lnho2015/article/details/50962989 以下是我个人做题过程中的一些体会: 1. LeetCode的题库越来越大,截止到目前,已经有321个问题了.对于大多数人来说,没有时间也没有必要把所有题目都做一遍(时间充裕可以随意).刷个100题左右应该就差不多了(可以考虑序号为前100多的题目,相对更经典一点). 2. 从AC率高的开始做,难度从简单->中等,先不要做困难的. 3. 可以按照下文的面试出题频率顺序来做,从频率最…
/** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生选拔赛题 题意:给定两个数的和以及他们的最小公倍数,求这两个数. 思路: x+y=A lcm(x,y)=B => x*y/gcd(x,y)=B 要把这两个公式联立,那么必须消掉gcd: 设:d = gcd(x,y), x = kx*d, y = ky*d; kx与ky互质: x+y=A => d(…
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k-th prime number. 样例输入: 3 7 样例输出: 5 17 Ways 首先用C++做了一遍,刚开始没有AC的原因是判断素数的函数写的不对,没有处理2这个情况.后来发现每次停止循环的时候…
LintCode 83. Single Number II (Medium) LeetCode 137. Single Number II (Medium) 以下算法的复杂度都是: 时间复杂度: O(n) 空间复杂度: O(1) 解法1. 32个计数器 最简单的思路是用32个计数器, 满3复位0. class Solution { public: int singleNumberII(vector<int> &A) { int cnt[32] = {0}; int res = 0; f…
class Solution { public: int singleNumber(int A[], int n) { ; ; ; i<=bits; i++) { ; ; ; j<n; j++) w += (A[j]>>(i-))&t; result+= (w%)<<(i-); //若是除过一个数之外,其他数重复k次,则将此处的3改为k } return result; } }; 利用二进制的位运算来解决这个问题,比如输入的数组是[2,2,3,2] 它们对应的二…
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by…
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23" Output: ["ad", "ae", &q…
Write 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' has binary representation 00000000000000000000000000001011, so the function should retu…
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 比较简单,类似进制的转换,代码如下: class Solution { pu…
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 while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty…
http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3709 You are playing one game called "Number Maze". The map of an example is shown in the following figure. In the map, there are N*N+2 cells. When the game starts, you…