wxpython 获得poj上自己代码的小工具

2010年6月30日 16:41

wxFormBuilder +wxPython

noname.xrc

getcode.py

评论(2) 阅读(2644)

poj 1014 多重背包

2010年6月17日 19:51

多重背包见 http://www.cgang.tk/pack/P03.html

mac下还是用macvim更顺手一些

在家,混混度日

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int v[7];
int sum,V;
int f[100000];

void CompletePack(int cost,int weight)
{
    for(int i=cost;i<=V;i++)
        f[i]=max(f[i],f[i-cost]+weight);
}

void ZeroOnePack(int cost,int weight)
{
    for(int i=V;i>=cost;i--)
        f[i]=max(f[i],f[i-cost]+weight);
}

void MultiplePack(int cost,int weight,int amount)
{
    if(cost*amount>=V)
    {
        CompletePack(cost,weight);
        return;
    }
    int k=1;
    while(k<amount)
    {
        ZeroOnePack(k*cost,k*weight);
        amount-=k;
        k*=2;
    }
    ZeroOnePack(amount*cost,amount*weight);
}


int main () 
{
    //freopen("in.txt","r",stdin);
    int cas=1;
    while(1)
    {
        sum=0;
        for(int i=1;i<=6;i++)
        {
            cin>>v[i];
            //v[i]=v[i]%60;
            sum+=i*v[i];
        }
        if(sum==0) break;
        cout<<"Collection #"<<cas++<<":"<<endl;

        if(sum%2)
        {
            cout<<"Can't be divided."<<endl<<endl;
            continue;
        }

        V=sum/2;
        memset(f,0,sizeof(f));
        for(int i=1;i<=6;i++)
        {
            MultiplePack(i,i,v[i]);
        }

        if(f[V]==V)
            cout<<"Can be divided."<<endl<<endl;
        else
            cout<<"Can't be divided."<<endl<<endl;
    }

}

14/10/10:背包又忘得差不多了...

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int V;
int f[100000];

void CompletePack(int cost,int weight)
{
    for(int i=cost;i<=V;i++)
        f[i]=max(f[i],f[i-cost]+weight);
}

void ZeroOnePack(int cost,int weight)
{
    for(int i=V;i>=cost;i--)
        f[i]=max(f[i],f[i-cost]+weight);
}

void MultiplePack(int cost,int weight,int amount)
{
    if(cost*amount>=V)
    {
        CompletePack(cost,weight);
        return;
    }
    int k=1;
    while(k<amount)
    {
        ZeroOnePack(k*cost,k*weight);
        amount-=k;
        k*=2;
    }
    ZeroOnePack(amount*cost,amount*weight);
}


int main ()
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int cash,N,n[11],d[11];
    while(scanf("%d%d",&cash,&N)!=EOF)
    {
        for(int i=1;i<=N;i++)
            scanf("%d%d",&n[i],&d[i]);
        V=cash;
        memset(f,0,sizeof(f));
        for(int i=1;i<=N;i++)
            MultiplePack(d[i],d[i],n[i]);
        printf("%d\n",f[V]);
    }
}

评论(1) 阅读(3465)

画地为牢(转)

2010年5月25日 16:16

两个项目之间喘息之际,帮着做招聘是每个ThoughtWorker义不容辞的责任。这不,一回到办公室坐下来,就有人给安排活。

这 次是一个电话面试,一个C#程序员。这个应聘者表达能力很不错,和他聊天感觉还很舒服。聊着聊着,我们谈到了.NET版本的问题。
我:你们用 的.NET是哪个版本的?
应聘者:2.0。
我:那你对新版本的.NET了解多少?
应聘者:不怎么了解。
我:没尝试着了解 一下?
应聘者:我们的项目比较稳定,不会轻易更换底层的库。
我:我是说,你自己没有了解一下?
应聘者:学了也用不到。

这 不是我第一次在面试的过程中问这个问题,也不是我第一次得到这样的回答。在那些咨询的日子里,我也曾与人讨论过这个话题,得到的答案大体也是类似的,用不 到。

很多程序员都把目光放在眼皮底下的一亩三分地,绝不越雷池半步。所以,我们有机会看到,有些程序员写着照猫画虎的代码,鲜有属于自己 的思考在里面。

我曾经看过这样的代码,一个实现了IEnumerable的类,要对它的一个实例进行遍历。这段代码通过 getEnumerator,然后用while循环,自己判断还有没有元素,再把它下一个元素取出来。
问:为什么不直接用foreach循环?
答: 前面的代码也是这么写的。

我也见过,原本用LINQ可以一句搞定的代码,然后自己一句一句把所有的逻辑堆砌出来,长长的代码让人不知所 云。能写出这样代码的人,多半是不知道LINQ存在的,或是仅仅知道存在而已。

这个问题的背后,我的关注点在于开放的心态。

自 己的学习和成长是为了谁呢?为了别人而学习,大可不必继续,那会是一件非常无趣的事。自以为优秀的人常常会丧失前进的动力,而许多优秀的人并不会觉得自己 多么优秀。打开自己的心,才能学到更多的东西。学然后知不足。

我所接触过的优秀程序员大多是视野极宽的人,与他们讨论问题,经常为自己的无知暗自羞愧。曾和WPC聊过,他说,自己在写Ruby的第一年完全就是 在写Java代码,这让他痛苦万分,不断的学习让他的Ruby代码有了Ruby的味道。我也曾见过很多用Java或C++写就C代码,而作者们浑然不知。

别 人不会限制你学习,也不会限制你成长,但自己可以画地为牢。

评论(1) 阅读(1931)

poj 3126 第一个BFS题

2010年5月22日 07:44

Source Code

Problem: 3126   User: scturtle
Memory: 776K   Time: 16MS
Language: G++   Result: Accepted
  • Source Code
    #include <iostream>
    #include <cstring>
    #include <queue>
    using namespace std;
    #define MAX 9999
    int prime[MAX+1];
    int visit[MAX+1];
    int st,ed;
    int bas[4]= {1,10,100,1000};
    void shai()
    {
        for(int i=2; i<=MAX; ++i) prime[i]=1;
        int t;
        for(int i=2; i<=MAX/2; ++i)
        {
            t=2*i;
            while(t<=MAX)
            {
                prime[t]=0;
                t+=i;
            }
        }
    }
    
    void bfs()
    {
        fill(visit,visit+9999,0);
        queue<int> q;
        queue<int> qs;
        int t,ts;
        int n,ns;
        ts=0;
        t=st;
        q.push(t);visit[t]=1;
        qs.push(ts);
        int num,i,j;
        while(1)
        {
            t=q.front();q.pop();
            ts=qs.front();qs.pop();
            if(t==ed)
            {
                cout<<ts<<endl;
                return;
            }
            for(i=0; i<4; ++i)
                for(j=0; j<10; ++j)
                {
                    if(i==3&&j==0) continue;
                    num=t/bas[i]%10;
                    if(num!=j)
                    {
                        n=t-num*bas[i]+j*bas[i];
                        ns=ts+1;
                        if(!visit[n]&&prime[n]) {q.push(n);visit[n]=1;qs.push(ns);}
                    }
                }
        }
    
    }
    int main()
    {
        shai();
        int cas;
        cin>>cas;
        while(cas--)
        {
            cin>>st>>ed;
            bfs();
        }
    }
    

评论(59) 阅读(2698)

cx_freeze和py2exe打包py程序笔记

2010年5月20日 03:53

环境: python 2.6  win7  cx_freeze4.1.2  py2exe-0.6.9.win32-py2.6

cx_freeze打包tkinter程序的话,setup.py里写入tk\tcl目录如:

# -*- coding: utf-8 -*-
from cx_Freeze import setup, Executable  

includeFiles = [
     ( r"D:\lib\Python26\tcl\tcl8.5", "tcl"),  
     ( r"D:\lib\Python26\tcl\tk8.5", "tk")  
	]

setup(
        name = "hello",
        version = "0.1",
        description = "Sample cx_Freeze script",
        options = {"build_exe": {"include_files": includeFiles,}},  
  
        executables = [Executable("test.py",base="Win32GUI")])

(命令行程序去掉base那个选项)

在当前目录下执行(需把python地址加入环境变量):

python setup.py build

 

py2exe的setup.py写成:

# -*- coding: utf-8 -*-
# setup.py
from distutils.core import setup
import py2exe

setup(windows=["mine.pyw"])

不用像cx_freeze在意tkinter,命令行程序把最后一行的windows换成console

在当前目录下执行:

python setup.py py2exe

 

OK! 笔记完成!

 

补充:

py2exe打包wxpython程序时遇到找不到msvcp9.dll

需下载MSVCP90.DLL 并拷贝到Python26/DLLs 目录下

setup.py写成:

# -*- coding: utf-8 -*-
# setup.py
from distutils.core import setup
import py2exe

setup(
	windows=["test.pyw"],
	options = {           
	"py2exe":  
	{"dll_excludes":["MSVCP90.dll"]}  
	}
)

评论(2) 阅读(6729)