`
EmmaZhao
  • 浏览: 32179 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论
文章列表
质数也叫素数,是只能被1和它本身整除的正整数,最小的质数是2,目前发现的最大的质数是p=2^57885161-1【注1】。 判断一个数是质数的最简单的方法如下: def isPrime1(n): for i in range(2, n): if n % i == 0: return False return True 但是在上面的方法中有一些冗余的计算,所以做以下改进 def isPrime2(n): import math if n == 1: return False elif n < 4: return True else ...

POJ1276

#include<iostream> using namespace std; int main() { int cash,n,max; while(cin>>cash>>n) { max = 0; int m[1001],v[1001]; for(int i = 0;i<n;i++) cin>>m[i]>>v[i]; bool dp[100001]; memset(dp,0,sizeof(dp)); dp[0] = true; for(int i = 0;i ...
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less ...
#include<iostream> #include<math.h> //248K 16MS using namespace std; typedef struct RGB { short R; short G; short B; }; int D(RGB a,RGB b) { int t1 = (a.R - b.R) * (a.R - b.R); int t2 = (a.G - b.G) * (a.G - b.G); int t3 = (a.B - b.B) * (a.B - b.B); return sqr ...
#include<iostream> using namespace std; int main() { int dp[10001]={0},n,a[10001]={0}; while(cin>>n) { for(int i = 1;i<=n;i++) cin>>a[i]; dp[1] = 1; int max,tmp; for(int i = 2;i<=n;i++) { dp[i] = 1; for(int j = i-1;j>=1;j--) { if(a[i] &g ...
#include<iostream> #define N 350 using namespace std; int main() { int n,max; int t[N+1][N+1]={0},dp[N+2][N+2]={0}; cin>>n; for(int i = 1;i<=n;i++) for(int j = 1;j<=i;j++) cin>>t[i][j]; max = t[1][1]; for(int i = 1;i<=n+1;i++) { for(int j = 1;j< ...
#include<iostream> #include<string> using namespace std; int value['T'+1]['T'+1]; int dp[101][101]; int max(int a,int b,int c) { int k = (a>b)?a:b; return (c>k)?c:k; } int main(){ value['A']['A'] = value['C']['C']=value['T']['T']=value['G']['G'] =5; value['A']['C ...
#include<iostream> #include<string> using namespace std; int main() { string websites[102]; websites[1] = "http://www.acm.org/"; string str,tmp; int i = 1,max; while(cin>>str && (str[0] != 'Q')){ if(str[0] == 'V') { cin>>tmp; w ...
#include<iostream> using namespace std; int main() { int p,e,i,d,num = 1; cin>>p>>e>>i>>d; while((p!=-1) || (e!=-1) || (i!=-1) || (d!=-1)){ while((p!=e) || (p!=i)){ if(p<e){ if(p<i){ p+=23; }else i+=33; } else{ if(e& ...
使用apt-get install apache2后,修改配置文件: 1. 默认的配置在/etc/apache2/sites-available/default文件中 2.默认的http.conf是空的,如果要修改ServiceName,在hrttp.conf中添加一句即可 3.端口信息在ports.conf中,如果要修改端口,则要修改其中的内容 4.主机名设置成127.0.0.1:端口 4.配置虚拟机的网络连接为桥接模式 5.关闭虚拟机防火墙ubuntu的命令是sudo ufw disable 6.在虚拟机中查看ip地址,在主机浏览器中输入即可。
2011阿里云计算研发中心笔试题(45minutes) 引用http://oneweaklight.itpub.net/post/42951/519364 应聘职位:软件开发工程师-数据平台 1.状态转换图,有限自动机,正则表达式 2.最小堆,删除堆根节点,画出任意结果 3.Heap与stack在进程中的区别 4.硬盘概率问题,对立事件,独立事件,平均分布,一季度,一年 5.工厂分布距离最小问题 6.多线程输出变量的所以可能值 7.补充题,堆排序补充 8.整数数组中求相加和最大的子数组,时间复杂度为O(n),编程语言不限(C/C /JAVA) 附加知识: 一个由C/C++ ...
题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果。 如果是返回true,否则返回false。 例如输入5、7、6、9、11、10、8,由于这一整数序列是如下树的后序遍历结果:          8       /  \      6    10     / \  / \ 5  7 9  11 因此返回true。 如果输入7、4、6、5,没有哪棵树的后序遍历的结果是这个序列,因此返回false。 package cn.emma.interview_9; public class Ex9 { public static boolean isBa ...
输入一颗二元树,从上往下按层打印树的每个结点,同一层中按照从左往右的顺序打印。 public static void hierarchyTraverse(BinaryTree tree){ Queue queue = new Queue(); if(tree.getRoot() != null){ queue.enQueue(tree.getRoot()); while(!queue.emptyStack()){ TreeNode p = queue.deQueue(); System.out.print(p.getVlaue() + ...

名企面试100题_15

第15题(树): 题目:输入一颗二元查找树,将该树转换为它的镜像, 即在转换后的二元查找树中,左子树的结点都大于右子树的结点。 用递归和循环两种方法完成树的镜像转换。 package cn.emma.interview_15; public class Mirror { public static void getMirror(BinaryTree.TreeNode tree){ if(tree != null){ BinaryTree.TreeNode temp = tree.left; tree.left = tree.right; ...
第14题(数组): 题目:输入一个已经按升序排序过的数组和一个数字, 在数组中查找两个数,使得它们的和正好是输入的那个数字。 要求时间复杂度是O(n)。如果有多对数字的和等于输入的数字,输出任意一对即可。 例如输入数组1、2、4、7、11、15和数字15。由于4+11=15,因此输出4和11。 思路: package cn.emma.interview_14; public class GetDivision { public static void getDivision(int[] a, int n){ int i,j; for(i = 0,j=a.len ...
Global site tag (gtag.js) - Google Analytics