星期四, 十一月 30, 2006

随想

首先送上迟到的生日祝福,祝愿冬冬(大帅哥,要电话的mm赶快和我联系:-),抢占先机呀)终如所愿前途无量,美利坚是成就的远方,我也很向往。Fighting !Good to Great!

星期二, 十一月 28, 2006

两道M$的题目【From BMY】

【Problem 1】
有两个数组,均已经按升序排列好,编程序计算这两个数组的中位数。举个例子 数组A:{1,4,6,7,9} B{2,3,5,8} 两数组合并后{1,2,3,4,5,6,7,8,9} 中位数,就是中间的那个数: 5
要求时间复杂度O(lgn) 空间复杂度O(1)
Problem 2
给出两个单向链表的头指针,比如h1、h2,判断链表是否相交,如果不相交返回NULL;如果相交,返回指向第一个相交节点的指针。

星期一, 十一月 27, 2006

Heap Sort

package org.bitcore.sort;

import org.bitcore.CoreUtil.SwapUtil;

public class HeapSort {
private int heapSize;
public void initialHeap(){
heapSize = 0;
}

public int maxHeapfy(int[] a,int i){
int l = 2*i+1;
int r = 2*(i+1);
int largest = i;
if( l <> a[i] )
largest = l;
if( r <> a[largest] )
largest = r;
if(largest != i){
SwapUtil.swap(a,largest,i);
maxHeapfy(a,largest);
}
return largest;
}

public void buildMaxHeap(int[] a){
heapSize = a.length;
for(int root=a.length/2-1;root>=0;root--){
maxHeapfy(a,root);
}
}

public void heapSort(int[] a){
buildMaxHeap(a);
for(int i = a.length-1;i>0;i--){
SwapUtil.swap(a,0,i);
heapSize = heapSize - 1;
maxHeapfy(a,0);
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
HeapSort hp = new HeapSort();
hp.initialHeap();

int[] a = {4,1,3,2,16,9,10,14,8,7};
hp.heapSort(a);
for(int i = 0;i System.out.print("["+a[i]+"]\t");
}
}
}

星期六, 十一月 25, 2006

Problem1002 Fire Net

Problem: Fire Net
Java Solutions:算法思想来源于网上,这道题偶看了很久了一直不知道怎么开始动手做题,写了个Java版本的,可惜ZJU不能用Java提交,我会再深入看这道题,希望能撞出一些的想法。感谢Yimin的思想,我会深入钻研的:-),像xiaocui一样学习,像CSharp一样战斗~~


/*Solutions Version1.0*/
暂时没有空间提供文本下载:-(,后面会补上来
package core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class FireNet {
private int n;
private int max;
private char map[][];
public FireNet(int n){
this.n = n;
max = 0;
map = new char[4][4];
}
public static void inputWork(){
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int k;
String s;

try {
start:
while((s = in.readLine())!= null && s.length() != 0){
k = Integer.parseInt(s);
if(k>0&&k<=4){
FireNet fn = new FireNet(k);
int i=0;
retype:
while(i < fn.n ){
s = in.readLine();
for( int j=0;j < fn.n ; j++ ){
if(s.length() == fn.n){
fn.map[i][j]=s.charAt(j);
// System.out.print(fn.map[i][j]);
}
else{
System.err.print("输入长度不对");
continue retype;
// continue start;
}
}
i++;
// System.out.println();
}
System.out.println(fn.getMax(0,0));
}else if(k == 0){
continue start;
}
else{
System.out.println("输入大小有误,必须是介于0和4的数字(包括0和4)");
continue start;
}
}
} catch (NumberFormatException e1) {

System.err.println("输入字符非法,必须是介于0和4的数字(包括0和4)");
// e1.printStackTrace();
// break start;
} catch (IOException e1) {

e1.printStackTrace();
}
}
public boolean inputMap(int row,int col){
int i;
for(i = row -1;i >= 0;i--){
if(map[i][col] == '.')
return false;
if(map[i][col] == 'X')
break;
}
for(i = col -1;i >= 0;i--){
if(map[row][i] == '.')
return false;
if(map[row][i] == 'X')
break;
}
return true;
}

public int getMax(int pos,int cnt){
if(pos == (n*n)){
if(cnt > this.max)
this.max = cnt;
}
else{
int row = pos/n;
int col = pos%n;
if((map[row][col] == '.') && (inputMap(row,col))){
getMax(pos+1,cnt+1);
}
getMax(pos+1,cnt);
}
return this.max;
}
public static void main(String[] args){
inputWork();
}
}

Recording A Bug In A Simple C Program

description:


#include "stdio.h"
int main(void){
char c;
while((c = getchar())!=EOF && c!='\n'){
char b;
if(c == ' '){
if(b!=' '){
putchar(c);
b=c; //
}else{ //
continue;//
} //
}else{
b=c; //miss this sentence
putchar(c);
}
/*b = c; 所有注//句可删之,此句代之,不浪费一行代码*/
}
return 0;
}

星期五, 十一月 24, 2006

Where are you from

English corner is going to death?
Today In Advanced Oral English class many groups have shown us wonderful presentations for us.It really surprised me that plentiful visual aids were used in their performance,and the light and vivacity that shown in the eyes of members touched me much.
We should do better not only the style of performance,but also the visual and aural effets,giving all the wonderful touch with our innovation and friendly product.Come on,Believe ourselves,although two members of my groups were absent from this class so as that I can not cantact them.
We will be better.

星期四, 十一月 23, 2006

ThanksGiving Day【From ChinaDaily】

Almost every culture in the world has held celebrations of thanks for a plentiful harvest. The American Thanksgiving holiday began as a feast of thanksgiving in the early days of the American colonies almost four hundred years ago. In 1620, a boat filled with more than one hundred people sailed across the Atlantic Ocean to settle in the New World(新大陆). This religious group had begun to question the beliefs of the Church of England and they wanted to separate from it. The Pilgrims settled in what is now the state of Massachusetts. Their first winter in the New World was difficult. They had arrived too late to grow many crops, and without fresh food, half the colony died from disease. The following spring the Iroquois Indians(美国纽约州东北部易洛魁族印第安人)taught them how to grow corn, a new food for the colonists. They showed them other crops to grow in the unfamiliar soil and how to hunt and fish.
In the autumn of 1621, bountiful crops of corn, barley(大麦), beans and pumpkins were harvested. The colonists had much to be thankful for, so a feast was planned. They invited the local Indian chief and 90 Indians. The Indians brought deer to roast with the turkeys and other wild game offered by the colonists. The colonists had learned how to cook cranberries and different kinds of corn and squash dishes from the Indians. To this first Thanksgiving, the Indians had even brought popcorn.
In following years, many of the original colonists celebrated the autumn harvest with a feast of thanks.
After the United States became an independent country, Congress recommended one yearly day of thanksgiving for the whole nation to celebrate. George Washington suggested the date November 26 as Thanksgiving Day. Then in 1863, at the end of a long and bloody civil war, Abraham Lincoln asked all Americans to set aside the last Thursday in November as a day of thanksgiving.
Thanksgiving falls on the fourth Thursday of November, a different date every year. The President must proclaim that date as the official celebration.
Thanksgiving is a time for tradition and sharing. Even if they live far away, family members gather for a reunion at the house of an older relative. All give thanks together for the good things that they have.
In this spirit of sharing, civic groups and charitable organizations offer a traditional meal to those in need, particularly the homeless. On most tables throughout the United States, foods eaten at the first thanksgiving have become traditional.
Symbols of Thanksgiving
Turkey, corn, pumpkins and cranberry sauce(酸果曼沙司)are symbols which represent the first Thanksgiving. Now all of these symbols are drawn on holiday decorations and greeting cards. The use of corn meant the survival of the colonies. "Indian corn" as a table or door decoration represents the harvest and the fall season.
Sweet-sour cranberry sauce, or cranberry jelly, was on the first Thanksgiving table and is still served today. The cranberry is a small, sour berry. It grows in bogs(沼泽), or muddy areas, in Massachusetts and other New England states. The Indians used the fruit to treat infections. They used the juice to dye their rugs and blankets. They taught the colonists how to cook the berries with sweetener(甜味佐料)and water to make a sauce. The Indians called it "ibimi" which means "bitter berry." When the colonists saw it, they named it "crane-berry" because the flowers of the berry bent the stalk over, and it resembled the long-necked bird called a crane. The berries are still grown in New England.
In 1988, a Thanksgiving ceremony of a different kind took place at the Cathedral of St. John the Divine. More than four thousand people gathered on Thanksgiving night. Among them were Native Americans representing tribes from all over the country and descendants of people whose ancestors had migrated to the New World.
The ceremony was a public acknowledgment of the Indians' role in the first Thanksgiving 350 years ago. Until recently most schoolchildren believed that the Pilgrims cooked the entire Thanksgiving feast, and offered it to the Indians. In fact, the feast was planned to thank the Indians for teaching them how to cook those foods. Without the Indians, the first settlers would not have survived.

星期三, 十一月 22, 2006

The C Programming Language is done

Practice More,Come on......
K&R^_^
ThanksGiving Day~~~~Fourth Thursday in November

Blogging To Express My Views To This Fantastic World

Introduction:
Thanks to this space,I have the chance to record my thinking trip and communicate with men who seek after success and a better life.Whate's more,Blogging will become as one of living habit.Because Blogging firstly stands for one kind of mood,then we can coordinate my steps with the idea life.Introspectiveness and the sense of thinking others more(同理心) which are advocated preferently will be brought up through calming your brain and think about others more reasoningly.Through this window to my views,perhaps It is narrow,whatever,anyway,I can express my views to this fantastic world,with the perspective of tech and humanism.
The subject "thinking while walking(且思且行)" reflects determination to carry out our mission.In my opinion,As to us engaging in engineering explorer,There are two kinds of languages,one for men,one for machine,the same impotant.Resorting to such languages or tools,we express our thought and soul of culture inherited and developped.To get more essence of life,We should pay more attention to our profession and culture.History is a mirror,reflecting the shadow of giants, so is blog.
Bow~