Problem Description Little Ruins is a studious boy, recently he learned the four operations! Now he want to use four operations to generate a number, he takes a string which only contains digits ‘1’ - ‘9’, and split it into 5 intervals and add the fo
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 u
# -*- coding:utf-8 -*- __author__ = 'Ray' class Encryption: """整形数字简单的一个加密/解密算法""" def encryption(num): """对数字进行加密解密处理每个数位上的数字变为与7乘积的个位数字,再把每个数位上的数字a变为10-a.""" newNum=[] for i in str(num): if int
转载:http://www.cnblogs.com/grandyang/p/4756677.html 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 li
A.Movie 题意是给n个线段,要求求出是否存在三个不相交的线段,是的话输出yes,否则输出no.根据贪心的想法,可以先找出右端点r'最小的线段,他是三条线段中最左的那条,再找出左端点l'最大的线段,他是三条线段中最右的那条,这样我们只需要找出是否存在一条线段可以放在中间,即区间[l,r],l>r',r<l'. 代码 #include<cstdio> int n; long long L,R,l,r,a,b,c,d,mi,mx,flag,u,v,i; int main() { i
题目 给定一组数,要求进行若干次操作,这些操作可以分为两种类型: (1) CMD 1 beg end value 将数组中下标在[beg, end] 区间内数字都变为value (2) CMD 2 beg end 求出数组中下标在[beg ,end]区间中的所有数字的和 分析 树状数组在区间查询和单点修改情况下效率较线段树高一些,而无法像线段树一样在O(logN)的时间内完成区间修改.因此使用线段树解决.使用线段树主要的是定义好线段树节点的状态.(如代码中注释所说,状态一定要明确,且容易计算!)