今天看Thinking in Java看到一个吸血鬼数的问题,于是查找UVa里也有类似的问题就动手写了先是用Java写的,不过WA了两次,然后没有发现错误,又用c++写的还是不行.最后发现要排序去重.然后改用Java的SortedSet解决了这个问题,主要就是暴力枚举求解.但是同样的算法Java用了将近5秒.c++只用了1秒.差距啊.还有避免不必要的重复的循环不能为00,还有不能为奇数.尽量提高程序的效率. 题目描述: Problem D Vampire Numbers Input: stand…
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a b, then a and b are an amicable pair and each of a and b are called amicable numbers. For example, the proper d…
1565: Vampire Numbers 时间限制: 3 Sec 内存限制: 128 MB提交: 20 解决: 9[提交][状态][讨论版] 题目描述 The number 1827 is an interesting number, because 1827=21*87, and all of the same digits appear on both sides of the `='. The number136948 has the same property: 136948=14…
Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7″. If n is 20, the output should be “2, 3, 5, 7, 11, 13,…
题目原文: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6…
Problem Description Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There are m chain on the tree, Each chain has a certain weight. Coco would like to pick out some chains any two of which do not share common vertices.Find out t…
题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1. 输入: n (1 < n…
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试了好久才发现.改过来1A. 贴个AC的代码: const int N=1e5+10; ll k,m,s[10]; struct mat { ll a[10][10]; }; mat mat_mul(mat A,mat B) { mat res; memset(res.a,0,sizeof(res.a…
Root of the Problem Time Limit: 1000MS Memory Limit: 65536K http://poj.org/problem?id=3100 已AK; Description Given positive integers B and N, find an integer A such that AN is as close as possible to B. (The result A is an approxima…
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae: Triangle P3,n=n(n+1)/2 1, 3, 6, 10, 15, ... Square P4,n=n2 1, 4, 9, 16, 25, ... Penta…
本文转载自:http://blog.csdn.net/a567890k/article/details/52956798 最近编译Android6.0时经常出现以下错误 临时解决方法: Building with Jack: out/target/common/obj/APPS/Launcher3_intermediates/with-local/classes.dexERROR: Security problem, see Jack server log (/tmp/jack-weilan/j…
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not…
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... By converting each letter in a word to a number corresponding to its alphabetical position and…
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array. Could you do it without extra space and in O(n) runtime?…
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Also, a self-dividing number is not allowed to contain the digit zero. G…
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory limit per test 256 megabytes 问题描述 Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his proble…
http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道怎么枚举.还有就是一般求第k小的思路一般是什么?对这类题目理解的不是很好. 这道题,跟上一篇的题解里面写的hdu 1002 递增数的题目的解法差不多,但是底层的求解需要花一些时间去推敲! 不会做,就看官方题解,看不懂说的什么.就从下面的讨论找大神的题解. I can describe my solu…
Problem 2 --- Add Two Numbers 简单的模拟题. Problem 3 --- Longest Substring Without Repeating Characters 题意: 给定一个字符串序列,找出最长无重复的子序列.如"abcabcbb"的最长不重复子序列为"abc" 思路: 首先分配一个hashTable[256],里面保存每个字符在当前字符序列中的位置,同时设置left变量表示当前无重复字符串的最左端位置.然后从头到尾扫面字符串…
http://codeforces.com/problemset/problem/47/A Triangular numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A triangular number is the number of dots in an equilateral triangle unifor…
任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3181 Accepted: 1776 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the…