- 博客(11)
- 收藏
- 关注
原创 HDU-1133Buy the Ticket
Problem DescriptionThe \\\\\\\"Harry Potter and the Goblet of Fire\\\\\\\" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won...
2018-07-05 15:59:01 225
转载 hdu1018(求n!的位数)
求大数的位数,要想到使用log的方法!!n的位数 =(int)log10(n)+1这样一来,本题就变为求 log10(n!)+1log内的乘法可以转化为log外的加法:log10(n!) = log10(n) + log10(n-1) + log10(n-2) + ...+ log10(2)#include <iostream>#include <stdio.h>#in...
2018-07-05 14:42:31 186
原创 Uva-1610 细节题
本题思路简单,但细节需要注意,否则不能AC。思路:将给定的字符串集合按字典序排序,取排在最中间的两个字符串A和B,则答案ans只需要满足A<= ans <B即可。按位比较A和B的每一位字符a、b:当a、b相等,ans.push_back(a);否则 ans.push_back(a+1)。这里有几个特殊情况需要考虑: 1. 如果a是A的最后一位,当a、b不相等时,ans应该push...
2018-05-15 08:39:25 154
原创 Largest Sum of Averages
We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?Note that our partition mus...
2018-04-17 10:52:51 466
原创 Subarray Sum Equals K (O(n)时间复杂度)
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2最简单的想法是,遍历所有可能的子序列,分别求各个子序列的...
2018-04-17 09:55:32 172
原创 Queue Reconstruction by Height (根据身高排队)
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this ...
2018-04-03 15:51:44 374
原创 Counting Bits (统计数字的二进制表达式中有几个1)
Given 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.Example:For num = 5 you sho...
2018-04-03 15:30:57 265
转载 使用C/C++列出某个目录下的文件
用C/C++列出目录下的文件,在linux下可采用readdir()函数来实现,代码实现过程为:打开目录循环读目录,输出目录下文件关闭目录指针#include <io.h>#include <stdio.h> void printDir( const char* path ){ struct _finddata_t data; long hnd = ...
2018-04-03 08:59:17 2737
原创 Linked List Cycle 找出单链表中环路
问题:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解法1:使用两个步伐不一样的指针遍历链表(eg:a每步走一格,b每步走两格),如果链表存在环路,两个指针总会相遇/** * Definition for singly-link...
2018-04-02 20:21:08 222
原创 Palindromic Substrings (回文子串)
题目:Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist...
2018-04-02 20:00:33 128
转载 内存对齐
内存分配会返回一个指针,那么对齐就意味着,返回的指针所指向的空间的访问地址是对齐的,如果是2字节对齐,那么地址最低1bit一定是0,返回地址一定能被2整除,如果是4字节对齐则最低2 bits一定是0,返回地址一定能被4整除,如果是16字节对齐则最后4bits一定是0,同样该地址可以被16整除。原理4楼说的很清楚了,就是预先多分配一些空间,然后将返回的地址根据输入的对齐参数,向后偏移,返回即可。实现则
2017-10-11 09:49:11 206
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人