- 浏览: 457198 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (272)
- java基础 (59)
- struts (8)
- spring (8)
- 数据库 (8)
- java 网络编程 (29)
- hibernate (3)
- JavaScript (10)
- 日志管理 (2)
- jsp (4)
- servlet (7)
- xml (4)
- ajax (2)
- web service (4)
- 算法与数据结构 (13)
- java 反射机制 (11)
- java 泛型 (3)
- java I/O (8)
- java 线程 (12)
- JavaEE (6)
- java解惑 (33)
- 工具 (5)
- MyEclipse编程实践 (1)
- OSGI (2)
- 设计模式 (9)
- 正则表达式 (0)
- EJB (3)
- Ubuntu linux (6)
- Android (1)
- web前端 (2)
- 找工作 (1)
- SCA (1)
- maven (1)
- 缓存 (1)
- json (1)
- javamail (1)
- 工作笔记 (2)
最新评论
-
霜花似雪:
博主可以分享一下源码吗?
使用maven构建web项目实例 -
王庆波-行:
很好的demo!
memcache使用实例 -
surpassno:
大写的牛逼
java可视化显示内存使用情况 -
zhulin0504:
怎么访问NetEcho.html页面呀???
applet与servlet的网络通信 -
springdata:
java多线程实例demo源代码下载:http://www.z ...
java多线程例子
北大poj1664,问题:将m个相同的苹果放入n个相同的盘子中,有多少放法
求最短非子序列长度,即长度小于这个长度的任意元素组成的都是原序列的子序列(不一定连续)
问题3:
Description
N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up for their evening meal, they did not line up in the required ascending numerical order of their brands.
Regrettably, FJ does not have a way to sort them. Furthermore, he's not very good at observing problems. Instead of writing down each cow's brand, he determined a rather silly statistic: For each cow in line, he knows the number of cows that precede that cow in line that do, in fact, have smaller brands than that cow.
Given this data, tell FJ the exact ordering of the cows.
Input
* Line 1: A single integer, N
* Lines 2..N: These N-1 lines describe the number of cows that precede a given cow in line and have brands smaller than that cow. Of course, no cows precede the first cow in line, so she is not listed. Line 2 of the input describes the number of preceding cows whose brands are smaller than the cow in slot #2; line 3 describes the number of preceding cows whose brands are smaller than the cow in slot #3; and so on.
Output
* Lines 1..N: Each of the N lines of output tells the brand of a cow in line. Line #1 of the output tells the brand of the first cow in line; line 2 tells the brand of the second cow; and so on.
Sample Input
5
1
2
1
0
Sample Output
2
4
5
3
1
简单的tcp 套接字编程
服务器端,要指定端口号,便于客户端连接时指定服务器的端口号,建立连接
客户端:
对象序列化:
package pkuACM; //本题是很简单的递推。 //①最少的盘子放了一个,这样每个盘子至少一个,n个盘子先放上n个,剩下的m-n个可以随便放 //②最少的盘子没有放,这样剩下的n-1个盘子还是随便放m个 import java.util.Scanner; public class Main1664 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); int i = 0; int N, M; StringBuffer sb = new StringBuffer(); while (i < num) { M = in.nextInt(); N = in.nextInt(); sb.append(cal(M, N) + "\n"); i++; } System.out.print(sb); } private static int cal(int m, int n) { if (m < 0) return 0; if (m == 0 || n == 1) return 1; return cal(m - n, n) + cal(m, n - 1); } }
求最短非子序列长度,即长度小于这个长度的任意元素组成的都是原序列的子序列(不一定连续)
package pkuACM; import java.util.Scanner; public class Main1989 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int K = in.nextInt(); int i=0; int current; int[] f = new int[K+1]; int count=0; int num =0; while(i<N){ current = in.nextInt(); if(f[current]==0){ //f[current]记录的是current出现的次数 f[current]=1;count++; } if(count==K){ count=0; num++; for(int j=1;j<=K;j++){ f[j]=0; } } i++; } System.out.println(num+1); } }
问题3:
Description
N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up for their evening meal, they did not line up in the required ascending numerical order of their brands.
Regrettably, FJ does not have a way to sort them. Furthermore, he's not very good at observing problems. Instead of writing down each cow's brand, he determined a rather silly statistic: For each cow in line, he knows the number of cows that precede that cow in line that do, in fact, have smaller brands than that cow.
Given this data, tell FJ the exact ordering of the cows.
Input
* Line 1: A single integer, N
* Lines 2..N: These N-1 lines describe the number of cows that precede a given cow in line and have brands smaller than that cow. Of course, no cows precede the first cow in line, so she is not listed. Line 2 of the input describes the number of preceding cows whose brands are smaller than the cow in slot #2; line 3 describes the number of preceding cows whose brands are smaller than the cow in slot #3; and so on.
Output
* Lines 1..N: Each of the N lines of output tells the brand of a cow in line. Line #1 of the output tells the brand of the first cow in line; line 2 tells the brand of the second cow; and so on.
Sample Input
5
1
2
1
0
Sample Output
2
4
5
3
1
package pkuACM; import java.util.Scanner; public class Main2182 { // lost cows,只知道牛的前面有多少小于它的,即当前位置的数代表前面的数有多少小于当前数字的,不对???? public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int i=1; int[] lock = new int[N+1]; int[] num = new int[N+1]; int j; for(;i<N;i++){ num[i]=in.nextInt(); } for(i=N-1;i>0;i--){ for(j=1;j<N;j++){ if(j<=num[i]+1&&lock[j]==1)num[i]++; lock[num[i]+1]=1; } } for(j=0,i=1;i<=N;i++){ if(lock[i]==1)j+=i; System.out.println((1+N)*N/2-j); } for(i=1;i<N;i++){ System.out.println(num[i]+1); } } }
简单的tcp 套接字编程
服务器端,要指定端口号,便于客户端连接时指定服务器的端口号,建立连接
package socket; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Server { public static void main(String[] args){ new Server(); } private ServerSocket server; private Socket s; private BufferedReader in; private PrintWriter out; public Server(){ try { server = new ServerSocket(8888); while(true){ s = server.accept(); String remoteIP = s.getInetAddress().getHostAddress(); String remotePort = ":"+s.getLocalPort(); System.out.println("a client come in !IP:"+remoteIP+remotePort); in = new BufferedReader(new InputStreamReader(s.getInputStream())); //使用reader可以读取字符数据 String line = in.readLine(); System.out.println(" client send is :"+line); out = new PrintWriter(s.getOutputStream(),true); out.println("your message has received"); out.close(); in.close(); s.close(); } } catch (IOException e) { e.printStackTrace(); } } }
客户端:
package socket; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; public class Client { private Socket s; private BufferedReader in; private PrintWriter out; public static void main(String[] args) { new Client(); } public Client() { try { s = new Socket("127.0.0.1", 8888); BufferedReader line = new BufferedReader(new InputStreamReader( System.in)); out = new PrintWriter(s.getOutputStream(), true); out.println(line.readLine()); in = new BufferedReader(new InputStreamReader(s.getInputStream())); out.println(in.readLine()); out.close(); in.close(); s.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
对象序列化:
package xunLieHua; import java.io.Serializable; public class Person implements Serializable { String name; House preferHouse; public Person(String name, House preferHouse) { this.name = name; this.preferHouse = preferHouse; } public String toString(){ return this.name+"["+super.toString()+"]"+this.preferHouse; } }
package xunLieHua; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Vector; public class MyWorld { public static void main(String[] args) { House h = new House(); Vector man = new Vector(); man.add(new Person("zhou",h)); man.add(new Person("jun",h)); man.add(new Person("mei",h)); System.out.println("man: "+man); //输出1 try { ByteArrayOutputStream buf1 = new ByteArrayOutputStream(); ObjectOutputStream o1 = new ObjectOutputStream(buf1); o1.writeObject(man); o1.writeObject(man); ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); ObjectOutputStream o2 = new ObjectOutputStream(buf2); o2.writeObject(man); ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray())); ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray())); Vector man1 = (Vector) in1.readObject(); Vector man2 = (Vector) in1.readObject(); Vector man3 = (Vector) in2.readObject(); System.out.println("man1: "+man1); //输出2 System.out.println("man2: "+man2); //输出3 //输出2,和3相同 System.out.println("man3: "+man3); //输出4 } catch (Exception e) { e.printStackTrace(); } } }
package xunLieHua; import java.io.Serializable; public class House implements Serializable { }
发表评论
-
ACM题(M个相同苹果放入N个相同的盒子里)
2011-05-27 16:22 1398(M个相同苹果放入N个相同的盒子里)//本题是很简单的递推。 ... -
java 面试问题集E文(转,有答案)
2011-05-24 10:14 1155Q: Is Empty .java file a valid ... -
java 实现排序算法(冒泡,选择,快速,归并)
2011-05-20 16:11 1067package other; import java.u ... -
二叉树的java实现
2011-05-18 17:04 869package other; import java.u ... -
阿里巴巴程序设计大赛,看你能做出几道
2011-05-09 08:25 1222第一题:Description 为了准备期末考试了,lapro ... -
java程序员面试宝典----线程
2011-04-29 09:38 812设计4个线程,两个线程每次对j增加1,另外两个对j减少1 pa ... -
选择,插入,冒泡排序
2011-04-12 10:06 1065package algorithm; public cl ... -
英语听力
2010-12-11 10:56 795见附件,英语 -
N!后面0的个数(经典转)
2010-12-01 20:36 762public static int countFactoria ... -
找出数组中前n个最大的(转)
2010-11-30 08:56 1485接口 package test; public interf ... -
将一个整数倒置输出
2010-11-18 09:53 1151如将3867变为7683 public static int ... -
用java实现选择排序,快速,归并,冒泡排序
2010-10-19 16:16 1384//*************************** ...
相关推荐
北大acm题解acm北大acm题解acm北大acm题解acm
浙江大学ACM题解,包括所有的题目和大部分解题代码
浙江大学ACM题解JU_ACM_All_Anwer,里面一本非常好的chm电子书,浙大的所有ACM题及题解都在了,对学习ACM的朋友非常的好~还等什么呢?
ACM题解 训练指南 北大ACM题解 北大ACM训练指南 北大ACM题解训练指南 北京大学ACM题目 源代码 POJ源代码 POJ做指南
ACM 题解ACM 题解ACM 题解ACM 题解ACM 题解ACM 题解ACM 题解
北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)
哈工程acm题解
关于杭州电子科技大学的ACM中的一些题目,有五十多道
大量acm题解,其中有若干经典与难题部分,供学习参考用。
大学生程序设计竞赛专业组acm题解
poj acm题解,包括绝大部分poj题目的题解,可以供acm爱好者学习研究
个人的含有接近60道题目的浙江工业大学ACM题解报告
浙江大学ACM题解包括了很多题的代码答案,喜爱ACM的赶快把
这是网上看到的ACM题解,浙江大学网站上的东西,大家可以看看 学习下
算法介绍&课件&经典acm题解题报告&ACM程序设计竞赛》课程教学大纲&基础训练题
北大ACM题解,对用到的算法进行讲解并附有源代码。
HDU2000至2099题的题目以及AC代码(含思路) 适合刚刚接触ACM的同学哦~ emmmm凑字
北大ACM解题代码,及解释。很好的,欢迎下载
介绍了c++的一些基础知识,以及算法的解答与应用,对初学者很有用,可以参考。。