- 浏览: 467229 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 1439(M个相同苹果放入N个相同的盒子里)//本题是很简单的递推。 ... -
java 面试问题集E文(转,有答案)
2011-05-24 10:14 1217Q: Is Empty .java file a valid ... -
java 实现排序算法(冒泡,选择,快速,归并)
2011-05-20 16:11 1110package other; import java.u ... -
二叉树的java实现
2011-05-18 17:04 900package other; import java.u ... -
阿里巴巴程序设计大赛,看你能做出几道
2011-05-09 08:25 1260第一题:Description 为了准备期末考试了,lapro ... -
java程序员面试宝典----线程
2011-04-29 09:38 844设计4个线程,两个线程每次对j增加1,另外两个对j减少1 pa ... -
选择,插入,冒泡排序
2011-04-12 10:06 1095package algorithm; public cl ... -
英语听力
2010-12-11 10:56 830见附件,英语 -
N!后面0的个数(经典转)
2010-12-01 20:36 796public static int countFactoria ... -
找出数组中前n个最大的(转)
2010-11-30 08:56 1519接口 package test; public interf ... -
将一个整数倒置输出
2010-11-18 09:53 1188如将3867变为7683 public static int ... -
用java实现选择排序,快速,归并,冒泡排序
2010-10-19 16:16 1421//*************************** ...
相关推荐
【标题】"浙江大学ACM题解 ACM"是一个专注于ACM(国际大学生程序设计竞赛)的资源集合,由浙江大学提供,包含了大量的竞赛题目及其相应的解题代码。这些资源对于准备参加ACM竞赛的学生或是对算法和编程挑战有兴趣的...
北京大学ACM题解训练指南是面向参与ACM国际大学生程序设计竞赛(ICPC)的学子们提供的一份宝贵资源。ACM竞赛旨在培养学生的算法设计、编程和问题解决能力,而这份指南则提供了大量经过精心挑选和解答的题目,帮助...
【杭州电子科技大学ACM题解】是一份针对杭州电子科技大学ACM竞赛的解题资源集,包含了五十多道不同难度和类型的题目。ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)是一项全球性的...
【北大ACM题解】- Trade on Verweggistan 这道题目来源于1999年ACM世界总决赛,属于动态规划与递推问题的一种应用。主要探讨的是荷兰商人如何在Verweggistan进行交易以最大化利润,面对的挑战是Verweggistan独特的...
《浙江大学ACM题解JU_ACM_All_Anwer》是一份极为宝贵的资源,它集结了浙江大学在ACM(国际大学生程序设计竞赛)历年来的题目及其解答。这份资料以CHM电子书的形式呈现,方便读者查阅和学习。对于那些对ACM编程竞赛感...
【描述】提到的"poj acm题解,包括绝大部分poj题目的题解,可以供acm爱好者学习研究"表明这份压缩包内包含的是对POJ平台上大多数题目的详细解题思路和代码实现。这些解题资料对于参加ACM竞赛的选手或者对算法感兴趣...
【标题】:“浙江工业大学acm题解”是一个关于ACM竞赛题目解答的资源集合,主要由个人完成,包含了近60道题目。这样的资源对于学习和准备ACM竞赛的学员来说,是极其宝贵的实践材料。 【描述】:描述中提到的“个人...
【描述】"这是网上看到的ACM题解,浙江大学网站上的东西,大家可以看看 学习下" 提示我们这份压缩包可能来源于浙江大学的官方或非官方渠道,可能是校内团队分享的资源。它提供了一个学习ACM竞赛编程的机会,不仅适合...
【北大杭电ACM题解(详细)】是针对北京大学与杭州电子科技大学主办的ACM/ICPC(国际大学生程序设计竞赛)所编写的详细解题资料。这些解题报告和指南旨在帮助参赛者理解和解决各类算法问题,提高编程及问题解决能力...
《北大ACM题解》是一本专为解决POJ(Programming Online Judge)平台上的编程竞赛题目而编写的指导书籍。ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)是一项全球性的比赛,旨在...
这个"ACM题解.zip"文件很显然包含了对历年来ACM比赛题目的一些解答,可能是由经验丰富的参赛者或教练整理的。下面将详细探讨ACM竞赛的背景、赛制、常见知识点以及解题策略。 ACM国际大学生程序设计竞赛(ICPC,...
【浙江大学ACM题解代码】是一份集合了众多ACM竞赛题目解答的资源,主要针对的是浙江大学ACM竞赛团队的训练材料。ACM,全称是国际大学生程序设计竞赛(International Collegiate Programming Contest),是一项全球性...
《ACM程序设计竞赛算法介绍&课件&经典acm题解题报告》是一份集理论与实践于一体的资源包,旨在帮助参赛者或对算法竞赛感兴趣的程序员深入理解ACM(国际大学生程序设计竞赛)的核心技术和策略。这个压缩包包含的内容...
### 大学生程序设计竞赛专业组ACM题解解析 #### MaxMin(签到题) - **题目背景**:此题考察的是基本的数据结构和算法基础。任务是找到给定数组中的最大值和最小值,并考虑数值的绝对值以及边界情况。 - **解题...
【哈工大 ACM 题解(900 多 道)经典】是哈工大计算机学院学生们精心编写的算法竞赛题目的解析集合,它涵盖了丰富的算法思想和问题解决策略,对于学习和提升算法能力具有极高的价值。ACM(International Collegiate ...
《ACM题解——探索编程竞赛的智慧之旅》 ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)是全球范围内的顶级编程竞赛,旨在锻炼并提升参赛者的算法设计、问题解决以及团队合作能力。...
【北大ACM题解(有讲解和源代码)】是一个针对北京大学ACM竞赛训练的资源集合,其中包含了对各类算法的详细讲解以及相应的源代码实现。这个资源对于想要提升算法能力,尤其是准备参加ACM(国际大学生程序设计竞赛)的...
根据提供的文件信息,可以看出这是一份关于哈尔滨工程大学ACM竞赛题目解答的文档。文档包含了多个ACM竞赛题目及其解答的列表。为了更好地理解和总结这些知识点,我们将对部分题目进行详细解析。 ### 1. 1004、...