Big Bug Ban

兴趣 践行 创新

codejam2011

 

image_thumb[1]

今年去做了google的codejam..

感觉比往年的练习题难多了啊..

Magica的弄了n久都没对..题读了半天,几种情况都考虑完了..但是还是不行.

Candy的small倒是过了..largefile直接超时.

最后终于30分勉强过线..排到9k+去了.

但是下一轮因为21号有比赛不能再弄了.

牛人真多啊.

得加强算法饿..太脆弱了..哎..

Written by princehaku

5月 10th, 2011 at 9:54 上午

Posted in technology

Tagged with

without comments

pafetion1.3版发布

 

咳咳..这么久没更新了..今天花点时间升级一下..

版本号升级到1.3

1.4版本已发布,请更新

1.3修订记录:

加入了cache功能..极大的缓解了移动的号码丢失问题出现, 当然.前提是必须成功发送过一次

修改了xml的返回结果,多个用户发送的时候不再一直错误了

可以有更详细的结果返回

1.2修订记录:

修改了返回方式为xml,节点只会有action和statu,日志可以在debug开启的模式下输出

感谢 七子狴犴 指出的一个bug,修复了添加好友的时候姓名错误

感谢 追赶太阳 指出的一个bug,修复了cookie获取的代码

1.1修订记录:

增加了添加好友的方式,支持自定义通知姓名

增加了批量发送方式,请使用逗号分离

调用地址:

1.发送消息

http://lab.haku.hk/f/do?phone=xxxxxx&pwd=xxx&to=xxxx,xxxx,xxxx&msg=xxxx

2.添加好友

http://lab.haku.hk/f/do?phone=xxxxxx&pwd=xxx&add=xxxx,xxxx,xxxx

说明:

phone 发送者手机号码 (-v1)

pwd  发送者飞信密码 (-v1)

———————————————-

to 接收者的标志 (可以是手机号 也可以是昵称 ,昵称如果有重复的默认发第一个的)(注意:不能给自己发送) (不和v1兼容)

msg 消息的正文(默认gbk 编码) (-v1)

(可选) u 是否使用utf8编码(默认的编码是gbk , 此参数用于一些需要对中文特殊处理的地方 比如, 如果您需要做一个在线发什么东西的东西) (-v1)

———————————————-

add 需要添加成好友的手机号码

name 好友请求验证时看到的姓名

如果有问题请给我发email baizhongwei@gmail.com

[download id=”19″]

 

Written by princehaku

5月 10th, 2011 at 9:42 上午

Posted in php

Tagged with ,

with 38 comments

be Careful!

 

最近发生件事情.差点挂了.T_T.

大家小心煤气啊~

活着真好..

Written by princehaku

5月 1st, 2011 at 12:42 上午

Posted in things goes by

with 2 comments

codejam!!!

 

最近很郁闷啊..

清理htdocs的时候吧无数小代码给删掉了..

包括只有一份的pafetion1.3…

有空再重写吧..

然后今天看到google的codejam了..

来测试下去年的题~~

总共3道题

T 1:

没什么难度..不说了…

T 2:

没什么难度..不说了…

T 3:

手机拨号问题

image

就是说比如给你一个串

hello world   对应的按键应该是4433555 555666096667775553

其中空格代表停顿一下  因为连续的两个键相同 然后0代表的才是空格

然后我们分析下这个键盘.用1-27固然可以,,但是要写的代码太多了..分析下.其实2-6都是3个一组的,所以可以考虑用ascii码来解决问题

A = 97   (97-97) /3 + 1

B = 98   (98-97) /3 + 1  = 2

然后重复的次数就是余数加一

然后7 9上面有四个..比较麻烦..所以得单独判断一下..

代码如下..

/*  Copyright 2010 princehaku
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  Created on : 2011-4-19, 12:00:01
 *  Author     : princehaku
 */

package codejam3;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.InputStreamReader;

/**
 *
 * @author princehaku
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        FileInputStream fr=new  FileInputStream("C:\\Users\\princehaku\\Desktop\\C-large-practice.in");
        BufferedReader br = new BufferedReader(new InputStreamReader(fr));
        int rr=Integer.parseInt(br.readLine());
        String content=" ";
        for(int i=1;i<=rr;i++){
            String source=br.readLine();

            String line="";

            for(int y=0;y<source.length();y++){
                line=line+ToChar(source.substring(y,y+1));
            }
            if(!line.equals("sss")){
                content=content+"Case #"+i+": "+line+"\n";
            }
        }
        System.out.println(content);
        FileWriter fw=new FileWriter("C:\\Users\\princehaku\\Desktop\\C-large-practice.out");
        fw.write(content);
        fw.close();
    }

    static int last=-99;

    private static String ToChar(String s) {
        String pre="";
        int r=(s.getBytes()[0]);
        int base=0;
        if(s.equals(" ")){
            if(last==-8){
                pre=" ";
            }
            last=-8;
            return pre+"0";
        }
        if(s.equals("s")||s.equals("z")||s.equals("y")){
            base++;
        }
        if(r>=115){
            r=r-1;
        }
        if(r>=120){
            r=r-1;
        }
        int y=(r-97)/3+2;
        if(y==last){
            pre=" ";
        }
        int rep=base+(r-97)%3+1;
        String string="";
        for(int a=0;a<rep;a++){
            string=string+y;
        }
        string=pre+string;
        last=y;
        return string;
    }

}

[download id=”18″]

 

Written by princehaku

4月 19th, 2011 at 10:46 下午

Posted in technology

Tagged with

with one comment

Android开发日志 摄像头视频流捕获

 

这个是前几日做的东西

原理是利用手机的摄像头取景,然后解码视频流

拆分成位图,然后对位图进行处理和识别

要在android手机里面捕获视频流

当然,手机必须得有摄像头

然后嘛,第一步是在AndroidManifest.xml加入如下权限声明

<permission android:name="android.permission.CAMERA"></permission>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

 

 

摄像头的预览和捕获只能通过surfaceview..

而且他的工作模式必须是SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS

不然不能在surfaceview里面显示出预览的图像

然后在surfaceCreated方法里面加入我们的摄像头初始化

 

public void surfaceCreated(SurfaceHolder arg0) {
    //启动相机服务
     mCamera = Camera.open();
    Log.i("Camera", "surface open");
    try {
        //设置预览  这个holder是 SurfaceView的getHolder()方法得到的
        mCamera.setPreviewDisplay(holder);
         Camera.Parameters parameters = mCamera.getParameters();
        //设置图片格式
         parameters.setPictureFormat(PixelFormat.JPEG);
        //设置预览的帧数,受硬件影响.
        parameters.setPreviewFrameRate(10);
        //设置尺寸
        parameters.setPreviewSize(preV.getWidth(), preV.getHeight());
        mCamera.setParameters(parameters);
        //设置回调的类
         mCamera.setPreviewCallback(new ViewCallback(preV, this));
        //开始预览
         mCamera.startPreview();
    } catch (Exception e) {
        //释放相机
         mCamera.release();
        mCamera = null;
        return;
    }
}

 

然后看看我们的ViewCallback类

在这个类里面要实现PreviewCallback

主要是里面的 public void onPreviewFrame(byte[] data, Camera arg1) {}

data就是返回的数据流了, 不过麻烦的是这个流并不是rgb编码的,是YUV420SP编码的,

Camera.Parameters 里面有个setPreviewFormat()  这个虽然可以设置 但是具体能不能编码成JPEG是受你的手机影响的

老老实实得解码吧…网上关于YUV420SP编码的内容相当相当少..

    static public void decodeYUV420SP(byte[] rgbBuf, byte[] yuv420sp, int width, int height) {
    	final int frameSize = width * height;
		if (rgbBuf == null)
			throw new NullPointerException("buffer 'rgbBuf' is null");
		if (rgbBuf.length < frameSize * 3)
			throw new IllegalArgumentException("buffer 'rgbBuf' size "
					+ rgbBuf.length + " < minimum " + frameSize * 3);

		if (yuv420sp == null)
			throw new NullPointerException("buffer 'yuv420sp' is null");

		if (yuv420sp.length < frameSize * 3 / 2)
			throw new IllegalArgumentException("buffer 'yuv420sp' size " + yuv420sp.length
					+ " < minimum " + frameSize * 3 / 2);

    	int i = 0, y = 0;
    	int uvp = 0, u = 0, v = 0;
    	int y1192 = 0, r = 0, g = 0, b = 0;

    	for (int j = 0, yp = 0; j < height; j++) {
    		uvp = frameSize + (j >> 1) * width;
    		u = 0;
    		v = 0;
    		for (i = 0; i < width; i++, yp++) {
    			y = (0xff & ((int) yuv420sp[yp])) - 16;
    			if (y < 0) y = 0;
    			if ((i & 1) == 0) {
    				v = (0xff & yuv420sp[uvp++]) - 128;
    				u = (0xff & yuv420sp[uvp++]) - 128;
    			}

    			y1192 = 1192 * y;
    			r = (y1192 + 1634 * v);
    			g = (y1192 - 833 * v - 400 * u);
    			b = (y1192 + 2066 * u);

    			if (r < 0) r = 0; else if (r > 262143) r = 262143;
    			if (g < 0) g = 0; else if (g > 262143) g = 262143;
    			if (b < 0) b = 0; else if (b > 262143) b = 262143;

    			rgbBuf[yp * 3] = (byte)(r >> 10);
    			rgbBuf[yp * 3 + 1] = (byte)(g >> 10);
    			rgbBuf[yp * 3 + 2] = (byte)(b >> 10);
    		}
    	}
    }

 

具体怎么实现的我就不是很清楚了..好像是灰度在前面 然后把蓝色和青色混合成一个变量跟在后面..

但是呢.这个方法效率很低..特别是些cpu差的机器

可以数数..每次都是横向*纵向 算法复杂度挺高的..

然后我把他压缩了10倍..就是每隔10个点取一次,效率瞬间就上来了.

现在运行你的程序, 你可能会发现摄像头的样子很奇怪。

其实是因为屏幕方向的问题

把你的屏幕设置为永久横向即可

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//覆盖屏幕 不显示通知栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);

 

点击下载  [download id=”17″]


Written by princehaku

4月 11th, 2011 at 10:30 下午

Posted in Android

Tagged with

with 2 comments

特殊的清明扫墓

 

20100115244

老者用笔和清水在辛亥保路死事纪念碑下为先烈祭祀

Written by princehaku

4月 7th, 2011 at 9:01 上午

Posted in things goes by

without comments

不给力啊..

 

doudou

效率太低了…

间隔5个采样,3个进程并发也还是很卡,,1s以上的回调..这可如何是好.

内存又不够.悲催啊.

Written by princehaku

4月 4th, 2011 at 11:55 下午

Posted in Android

Tagged with

with 2 comments

ubuntu androidapk程序一键安装工具

 

这个东东呢叫apkinstaller 给ubuntu用的

ubuntu下面貌似没有豌豆荚啊之类的程序。

于是做了这个,一键安装android程序

已经打包成deb,直接安装就可以了

安装完后当你连接手机到usb的时候 双击任意的apk文件就可以安装了

支持HTC  索爱 华为 三星 摩托

GTK界面版本(推荐)

============2011年4月4日更新==============

[download id=”15″]

[download id=”16″]

控制台显示版本

[download id=”10″]  32位版本

[download id=”11″]  64位版本

源代码下载

[download id=”14″]

Written by princehaku

3月 27th, 2011 at 12:17 下午

Posted in Android,linux

Tagged with

with 7 comments

GTK..

 

准备做个linux下的小工具..

原来gtk做界面也很方便嘛…

相关信息稍后连源代码一起发布..

RT.

Written by princehaku

3月 25th, 2011 at 7:16 下午

Posted in linux

Tagged with

with 4 comments

Android开发日志 lamp 开灯小游戏

 

这个是移植的很久很久以前我山寨做的一个桌面小游戏.

android版…  有一些细节没处理了..  480*320的屏应该是可以完美使用的

其他屏幕应该就只是欢迎界面显示会出问题

当然..效果比较丑陋..

豌豆荚截屏

欢迎使用~

下载点我[download id=”8″]

源代码下载[download id=”9″]

Written by princehaku

3月 14th, 2011 at 11:58 上午

Posted in Android

Tagged with

with 9 comments