【石子合并】 在一个圆形操场的四周摆放着n 堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的2 堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。 试设计一个算法,计算出将n堆石子合并成一堆的最小得分和最大得分。 【输入文件】 包含两行,第1 行是正整数n(1<=n<=100),表示有n堆石子。 第2行有n个数,分别表示每堆石……继续阅读 » 8年前 (2017-06-01) 2415浏览 1448个赞
用样式控制网页部分区域不被打印,我们经常需要在打印的网页上面放置一个打印按钮,如何让这个按钮不被同时打印出来,可以用一句样式解决。定义如下样式.noprint{display:none;} 只需要给不想打印的标签贴上noprint的class就可以了 <div class="noprint"> <i……继续阅读 » 8年前 (2017-06-01) 2555浏览 2702个赞
asp.net将DataSet中的数据导出Execl并提供下载那么把DataSet中的数据导出,也就是把DataSet中的表中的各行信息,以ms-excel的格式Response到http流,这样就OK了。说明:参数ds应为填充有数据表的DataSet,文件名是全名,包括后缀名,如execl2006.xlspublic void CreateExcel(……继续阅读 » 8年前 (2017-05-31) 2246浏览 1969个赞
django获得用户ip地址def get_client_ip(request): x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(……继续阅读 » 8年前 (2017-05-31) 1292浏览 967个赞
打印出所有的 “水仙花数 “,所谓 “水仙花数 “是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 “水仙花数 “,因为153=1的三次方+5的三次方+3的三次方。public class exp2{ public static void main(Strin……继续阅读 » 8年前 (2017-05-31) 2336浏览 2508个赞
C语言回溯法解决背包问题#include #include #include using namespace std;#define MAXN 10struct Goods_Info{ int v; //价值 int w; //重量 double vw; //价值重量比}goods[MAXN];int n;……继续阅读 » 8年前 (2017-05-31) 2643浏览 2974个赞
100 可以表示为带分数的形式:100 = 3 + 69258 / 714 还可以表示为:100 = 82 + 3546 / 197 注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。 类似这样的带分数,100 有 11 种表示法。#include#include/*检查某个数是否出现重位的情况,可以与nKill整合,但这儿单独列出*……继续阅读 » 8年前 (2017-05-31) 2956浏览 2646个赞
Pascal经典算法详解 – 最长递增子序列 给定数列A1,A2,…An,求最长递增子序列输入: 第一行一个整数n,表示有n个数(n<=1000) 第二行n个整数,用空格隔开。输出: 最长递增子序列长度。【分析】     在求以Ai为末元素的最长递……继续阅读 » 8年前 (2017-05-31) 1344浏览 2173个赞
pymongo为mongodb数据库添加索引from pymongo import ASCENDING, DESCENDINGposts.create_index([("date", DESCENDING), ("author", ASCENDING)])返回u'date_-1_author_1……继续阅读 » 8年前 (2017-05-31) 2343浏览 112个赞
JS代码返回iframe的name属性(名称)<!DOCTYPE html><html><body><iframe id="myframe" src="/default.asp" name="myframe"><p>……继续阅读 » 8年前 (2017-05-31) 3133浏览 215个赞
小米面试题:N对括号所有的合法状态解法代码给定N对括号,输出其所有的合法的组合状态,例如,N=3,所有的合法状态为:”((()))”, “(()())”, “(())()”, “()(())”, “()()()”思路:还是深搜DFS的思路,深搜的过程关键在于记录已经用掉的左括号个数和右括号的个数,当用过的左括号个数大于右括号则非法;当二者个数和大……继续阅读 » 8年前 (2017-05-31) 2665浏览 523个赞
0-1背包问题:给定n种物品和一背包.物品i的重量是wi, 其价值为ui,背包的容量为C. 问如何选择装入背包的物品,使得装入背包中物品的总价值最大? 分析: 0-1背包是子集合选取问题,一般情况下0-1背包是个NP问题. 第一步 确定解空间:装入哪几种物品 第二步 确定易于搜索的解空间结构: 可以用数组p,w分别表示各个物品价值和重量。 用数组x记录,是否……继续阅读 » 8年前 (2017-05-31) 2505浏览 685个赞
通过python对字符串中的所有单词进行统计,统计出每个单词出现的次数,并显示出现次数最多的单词text = "ga bu zo meuh ga zo bu meuh meuh ga zo zo meuh zo bu zo"items = text.split(' ')counters = {}for i……继续阅读 » 8年前 (2017-05-27) 1325浏览 1478个赞
通过JS代码控制iframe居左或者居右显示,下面的代码控制iframe居右显示,如果希望居左显示,只需要将right改成left即可<!DOCTYPE html><html><body><p>This is some text. This is some text. This is so……继续阅读 » 8年前 (2017-05-27) 2666浏览 2079个赞
如果希望通过按钮动态修改iframe的高度和宽度,可以参考下面的JS代码<!DOCTYPE html><html><head><script>function changeSize(){document.getElementById("myframe").hei……继续阅读 » 8年前 (2017-05-27) 3074浏览 980个赞
Java使用逆波兰表达式算法制作的表达式计算器package com.infogrid.g2b; import java.util.HashMap; import java.util.Map; public class Op { private static final Ma……继续阅读 » 8年前 (2017-05-27) 2993浏览 1330个赞
本代码可以帮你自动剪切掉图片的边缘空白区域,如果你的图片有大片空白区域(只要是同一颜色形成一定的面积就认为是空白区域),下面的python代码可以帮你自动切除,如果是透明图像,会自动剪切大片的透明部分。本代码需要PIL模块import Image, ImageChopsdef autoCrop(image,backgroundColor=None):……继续阅读 » 8年前 (2017-05-27) 2594浏览 1082个赞
下面的代码可以用来去除iframe的滚动条<!DOCTYPE html><html><head><script>function removeScroll(){document.getElementById("myframe").scrolling="……继续阅读 » 8年前 (2017-05-27) 1292浏览 1528个赞
python通过reportlab实现图片转换pdf#!/usr/bin/env pythonimport osimport sysfrom reportlab.lib.pagesizes import A4, landscapefrom reportlab.pdfgen import canvasf = sys.argv[1]fi……继续阅读 » 8年前 (2017-05-25) 1385浏览 1903个赞
python编写的用于测试网站访问速率的代码片段,可以输出打开某url的时间,访问100次的平均时间,最大时间和最小时间等等来源:http://www.75271.comdef Process(url,n): minSpan = 10.0 maxSpan = 0.0 sumSpan= 0.0 over1s = 0……继续阅读 » 8年前 (2017-05-25) 2912浏览 549个赞
python数组插入新元素li=['a', 'b'] li.insert(0,"c") #输出为:[‘c’, ’a’, ’b’]  li=[&……继续阅读 » 8年前 (2017-05-25) 2969浏览 1633个赞
Python和Singleton (单件)模式实现代码我知道的一种在 python 中 Singleton mode 的实现如下:class Foo: passdef instance(): global inst try: inst……继续阅读 » 8年前 (2017-05-25) 1819浏览 2366个赞
python3的序列化和反序列化代码演示#coding=utf-8import pickleaa={}aa["title"]="我是好人"aa["num"]=2t=pickle.dumps(aa)#序列化这个字典print(t)f=pickle.loads(t)#反序列……继续阅读 » 8年前 (2017-05-25) 2489浏览 277个赞
代码提供了三种基本方法连接字符串和数字,效率各有不同#!/usr/bin/env python## [代码名字: String and number concatenation]# [代码分类: Python Core]# [代码描述: Concatenate a string and a number]# [代码作者: Jono Ba……继续阅读 » 8年前 (2017-05-25) 2980浏览 2669个赞
这个函数可以对数组进行分组排序,排序根据字符串的相似性,用户可以在第二个参数指定相似程度,比如75表示相似程度在75%以上# [代码名字: Sort list by group]# [代码分类: Python Core]# [代码描述: This function takes a list of string and sorts them base……继续阅读 » 8年前 (2017-05-23) 2130浏览 1711个赞
python没有C语言里的for(int i=0;i<10;i++)这样的语法,只有for in 的语法,如果需要进行数字0-9的循环可以实用下面的代码,其中range(10)会产生0-9的数组#!/usr/bin/env python## [代码名字: Numeric loop]# [代码分类: Python Core]# [代码描……继续阅读 » 8年前 (2017-05-23) 2096浏览 1010个赞
本文包含了python字典的各种用法,字典在python中的重要性不言而喻#!/usr/bin/env python## [代码名字: Dictionaries 101]# [代码分类: Python Core]# [代码描述: Basic and not so basic dictionary operations]# [代码协议: ……继续阅读 » 8年前 (2017-05-22) 1671浏览 370个赞
一个python实现的圆周率pi算法def pi(): # Compute digits of Pi. # Algorithm due to LGLT Meertens. k, a, b, a1, b1 = 2, 4, 1, 12, 4 while 1: p, q, k = k*k, 2*k+1, ……继续阅读 » 8年前 (2017-05-22) 1692浏览 2791个赞
python中反转字符串可以说是易如反掌,估计再没有语言比python的字符串反转方式更简单了,下面的代码对数组里的所有元素进行反转#!/usr/bin/env python## [代码名字: Reversing strings]# [代码分类: Python Core]# [代码描述: How to reverse the content……继续阅读 » 8年前 (2017-05-22) 2793浏览 577个赞
本代码可以对python的源代码进行语法高亮后输出html文件进行显示## {{{ http://code.activestate.com/recipes/578178/ (r11)'''Add syntax highlighting to Python source code'''__a……继续阅读 » 8年前 (2017-05-16) 1487浏览 286个赞
python通过apply使用元祖和列表调用函数def my_fuc(a, b): print a, batuple=(30,10)alist= ['Hello','World!']apply(my_fuc,atuple)apply(my_fuc,alist)输出:D:\py>……继续阅读 » 8年前 (2017-05-12) 1459浏览 1111个赞
php按单词截取字符串的代码,指定字符串和单词数量进行截取<?phpfunction limit_words($string, $word_limit){ $words = explode(" ",$string); return implode(" ",array_splice($……继续阅读 » 8年前 (2017-05-09) 2807浏览 1465个赞
php生成随机密码的函数function auth_pwgen(){ $pw = ''; $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones $v = 'aeiou'; ……继续阅读 » 8年前 (2017-05-09) 1369浏览 241个赞
php检查要包含的文件是否存在可读……继续阅读 » 8年前 (2017-05-09) 1647浏览 304个赞
如果文件大小为字节单位的,阅读起来不方便,这个函数可以把字节单位转换成KB,MB,GB,TB等单位,方便阅读function ByteSize ( $file_size ){ $file_size = $file_size-1; if ($file_size >= 1099511627776) $show_filesize = nu……继续阅读 » 8年前 (2017-05-05) 2761浏览 2717个赞
php将文件夹下的所有图片放入数组function listImages($dirname=".") { $ext = array("jpg", "png", "jpeg", "gif"); $files = array(); ……继续阅读 » 8年前 (2017-05-05) 1226浏览 1059个赞
指定一个文件夹,在php里include这个文件夹下的所有.php文件foreach (glob("*.php") as $filename) { include($filename);}……继续阅读 » 8年前 (2017-05-05) 1481浏览 2852个赞
php检测浏览器类型代码// Simple browser detection$is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = false; if (strpos($_SERVER['HTTP_U……继续阅读 » 8年前 (2017-05-05) 2386浏览 1087个赞
Asp.Net MVC中如果希望Action重定向到另外一个Action,则可以使用RedirectToAction,下面是演示代码:using System.Web.Mvc;namespace MvcApplication1.Controllers{public class ProductsController : Controller{……继续阅读 » 8年前 (2017-05-04) 2116浏览 2012个赞
反向传播算法C语言实现//实现对异或的分类#include #include #include #include #define PN 4#define INPUT 2#define HIDDEN 2#define TARGET 1#define OUTPUT 1struct NN{ int ni;……继续阅读 » 8年前 (2017-05-04) 1907浏览 2012个赞
php动态生成表单代码<?php define('VALID_NOT_EMPTY', '/.+/'); define('VALID_EMAIL', "/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&&……继续阅读 » 8年前 (2017-05-04) 2260浏览 2419个赞
php动态改变图片尺寸后输出,输出图片时使用下面的地址:image_resize.php?img=image.jpg&w=150&h=150&constrain=1w和h为要显示的尺寸 0) { // calculate resized height and width if percent is defined ……继续阅读 » 8年前 (2017-05-04) 2585浏览 678个赞
php不破坏单词截取子字符串的方法/* snippet(phrase,[max length],[phrase tail]) snippetgreedy(phrase,[max length before next space],[phrase tail]) */ function snippet($text,$le……继续阅读 » 8年前 (2017-05-04) 2619浏览 2260个赞
php 将数组转换成xml的类class ArrayToXML{ /** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and bu……继续阅读 » 8年前 (2017-05-03) 1627浏览 1656个赞
演示python如何创建和使用一个简单的元类#!/usr/bin/env python#-*- coding: utf-8-*-# [代码名字: Simple metaclass]# [代码分类: Python Core] # [代码描述: Shows how to create a and use a simple metaclass]……继续阅读 » 8年前 (2017-05-03) 2913浏览 961个赞