John Smith has decided to number the pages in his notebook from 1 to N. Please, figure out the number of zeros, ones, twos, ... , nines he might need.
Input
One number N (N<1000000000)
Output
There should be 10 lines. The first line should contain the number of zeros needed , the second line should contain the number of ones needed, ... , the tenth line should contain the number of nines needed.
Sample
input
output
12
1 5 2 1 1 1 1 1 1 1
Problem Author: Eugene Bryzgalov
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Tour
解答如下:
1using System; 2 3namespace Skyiv.Ben.Timus 4{ 5// Timus 1150. Digits: 求 1 到 N 的正整数中包含 0 .. 9 的数目。 6// N 9 99 999 9,999 99,999 999,999 9,999,999 99,999,999 999,999,999 7// i*p 1 20 300 4,000 50,000 600,000 7,000,000 80,000,000 900,000,000 8// q 1 11 111 1,111 11,111 111,111 1,111,111 11,111,111 111,111,111 9// 上表中,i*p 是 1 .. 9 的数目,i*p - q 是 0 的数目。 10//http://acm.timus.ru/problem.aspx?space=1&num=1150 11sealedclass T1150 12 { 13staticvoid Main() 14 { 15int[] a =newint[10]; // 0 .. 9 的数目 16int k =0, n =int.Parse(Console.ReadLine()); 17for (int i =0, m =1, p =1, q =0; n >0; i++, n /=10, q = q *10+1) 18 { 19int d = n %10; // d: n 的第 i 位数字,i: 0:个位 1:十位 2:百位 20 k += i * p * d; // i*p: 0 1 20 300 4000 50000 600000 7000000 21if (i >0) p *=10; // p: 1 1 10 100 1000 10000 100000 1000000 22for (int j = d -1; j >=0; j--) a[j] += p; // 0 .. d-1 的数目 23if (n <10) a[0] -= p + q; // q: 0 1 11 111 1111 11111 111111 24 a[d] += m; // d 的数目 25 m += d * p; // m: n 的低 i 位 + 1, 例 n: 59842,m: 1 3 43 843 9843 26 } 27for (int i =0; i < a.Length; i++) Console.WriteLine(a[i] + k); 28 } 29 } 30}
利用JavaScript进行对象排序,根据用户的年龄排序展示
<script>
var bob={
name;bob,
age:30
}
var peter={
name;peter,
age:30
}
var amy={
name;amy,
age:24
}
var mike={
name;mike,
age:29
}
var john={
FLP
One famous theory in distributed computing, known as FLP after the authors Fischer, Lynch, and Patterson, proved that in a distributed system with asynchronous communication and process crashes,
每一行命令都是用分号(;)作为结束
对于MySQL,第一件你必须牢记的是它的每一行命令都是用分号(;)作为结束的,但当一行MySQL被插入在PHP代码中时,最好把后面的分号省略掉,例如:
mysql_query("INSERT INTO tablename(first_name,last_name)VALUES('$first_name',$last_name')");
题目链接:zoj 3820 Building Fire Stations
题目大意:给定一棵树,选取两个建立加油站,问说所有点距离加油站距离的最大值的最小值是多少,并且任意输出一种建立加油站的方式。
解题思路:二分距离判断,判断函数的复杂度是o(n),这样的复杂度应该是o(nlogn),即使常数系数偏大,但是居然跑了4.5s,也是醉了。 判断函数里面做了3次bfs,但是每次bfs节点最多