代码改变世界

随笔档案-2014年02月

PAT 解题报告 1052. Linked List Sorting (25)

2014-02-28 20:55 by Loull, 504 阅读, 收藏, 编辑
摘要: 1052. Linked List Sorting (25)A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and aNextpointer to the next structure. Now given a linked list, you are supposed to sort the structures according to th 阅读全文

PAT 解题报告 1051. Pop Sequence (25)

2014-02-28 20:27 by Loull, 1215 阅读, 收藏, 编辑
摘要: 1051. Pop Sequence (25)Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain 1, 2, 3, 4, 5, 6, 阅读全文

PAT 解题报告 1050. String Subtraction (20)

2014-02-28 20:00 by Loull, 416 阅读, 收藏, 编辑
摘要: 1050. String Subtraction (20)Given two strings S1and S2, S = S1- S2is defined to be the remaining string after taking all the characters in S2from S1. Your task is simply to calculate S1- S2for any given strings. However, it might not be that simple to do itfast.Input Specification:Each input file c 阅读全文

PAT 解题报告 1049. Counting Ones (30)

2014-02-28 19:37 by Loull, 436 阅读, 收藏, 编辑
摘要: 1049. Counting Ones (30)The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's in 1, 10, 11, and 12.Input Specification:Each input file contains one 阅读全文

PAT 解题报告 1048. Find Coins (25)

2014-02-28 19:30 by Loull, 356 阅读, 收藏, 编辑
摘要: 1048. Find Coins (25)Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only 阅读全文

PAT 解题报告 1047. Student List for Course (25)

2014-02-28 19:22 by Loull, 360 阅读, 收藏, 编辑
摘要: 1047. Student List for Course (25)Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input Specification:Each input file contains one test case. For each case, th 阅读全文

PAT 解题报告 1013. Battle Over Cities (25)

2014-02-27 15:59 by Loull, 2130 阅读, 收藏, 编辑
摘要: 1013. Battle Over Cities (25)t is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the cities connected. 阅读全文

PAT 解题报告 1010. Radix (25)

2014-02-27 15:19 by Loull, 3670 阅读, 收藏, 编辑
摘要: 1010. Radix (25)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of 阅读全文

PAT 解题报告 1009. Product of Polynomials (25)

2014-02-27 15:11 by Loull, 548 阅读, 收藏, 编辑
摘要: This time, you are supposed to find A*B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1N2 aN2... NK aNK, where K is the number of nonzero terms in the polynomial 阅读全文

PAT 解题报告 1007. Maximum Subsequence Sum (25)

2014-02-27 15:04 by Loull, 965 阅读, 收藏, 编辑
摘要: Given a sequence of K integers { N1, N2, ..., NK}. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj} where 1 mx) { mx = sum; s = i;t = j; } } } printf("%d %d %d", mx,n[s], n[t]);思路2、扫描经典DP问题, 基于这样一个事实:保存一个最大字段和以及一个当前子段和, 如果当前字段和大于当前... 阅读全文

PAT 解题报告 1003. Emergency (25)

2014-02-27 14:31 by Loull, 3966 阅读, 收藏, 编辑
摘要: 1003. Emergency (25)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there 阅读全文

PAT 解题报告 1004. Counting Leaves (30)

2014-02-27 14:26 by Loull, 785 阅读, 收藏, 编辑
摘要: 1004. Counting Leaves (30)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.InputEach input file contains one test case. Each case starts with a line containing 0 #include #include #include #include using namespace std;#define MX 阅读全文

【转】DataSource高级应用

2014-02-21 16:50 by Loull, 384 阅读, 收藏, 编辑
摘要: 我们知道 DataSource能提供最高性能的对数据库的并发访问,但是,对DataSource的引用,也还有很多知识要弄清楚,获取Connection的方式是数据库性能最相关的技术,而对DataSource的调用对数据库性能起着很大的决定作用。一般对于DataSource的引用是通过以下流程来进行: Context ct = new InitialContext(); DataSource ds = (DataSource) ct.lookup(sourceUrl); 就这么简单的两行,但其调用条件不同却可以产生性能上巨大的差别。因为一个取得Connect的封装类(Bean)要对DataSo. 阅读全文

tomcat下jndi配置

2014-02-21 16:36 by Loull, 903 阅读, 收藏, 编辑
摘要: jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API。命名服务将名称和对象联系起来,使得我们可以用名称访问对象。目录服务是一种命名服务,在这种服务里,对象不但有名称,还有属性。 tomcat... 阅读全文

java中DriverManager跟DataSource获取getConnection有什么不同?

2014-02-21 14:42 by Loull, 6360 阅读, 收藏, 编辑
摘要: 1、datasource是与连接池获取连接,而DriverManager是获取与数据库的连接!DriverManager类的主要作用是管理注册到DriverManager中的JDBC驱动程序,并根据需要使用JDBC驱动程序建立与数据服务器的网络连接。但是建立与数据库的连接是一项较耗资源的工作,频繁的进行数据库连接建立操作会产生较大的系统开销,为了解决上述问题,可以采用数据库连接池技术。2、datasource内部封装了DriverManager的使用。。。DataSource主要是为了方便配置使用。。。作为OO概念上也需要有这个类和对象来表示数据的来源。。。3、c3p0是一个连接池同样常用还有 阅读全文

理解JDBC和JNDI

2014-02-21 14:24 by Loull, 1946 阅读, 收藏, 编辑
摘要: 下面的英文是我找过来的,因为是英文所以不敢翻译出来误导别人,但是它描述的确实恰到好处,比所谓网上的JNDI和JDBC云云的解释要精辟很多,如果遇到不认识的单词,用有道吧~~:)The Java Naming and Directory Interface (JNDI) is an application programming interface (API) for accessing different kinds of naming and directory services. JNDI is not specific to a particular naming or director 阅读全文

JDBC

2014-02-21 13:54 by Loull, 332 阅读, 收藏, 编辑
摘要: 一、什么是JDBC? Java语言访问数据库的一种规范,是一套API JDBC (Java Database Connectivity) API,即Java数据库编程接口,是一组标准的Java语言中的接口和类,使用这些接口和类,Java客户端程序可以访问各种不同类型的数据库。比如建立数据库连接、执行SQL语句进行数据的存取操作。 JDBC规范采用接口和实现分离的思想设计了Java数据库编程的框架。接口包含在java.sql及javax.sql包中,其中java.sql属于JavaSE,javax.sql属于JavaEE。这些接口的实现类叫做数据库驱动程序,由数据库的厂商或其它的厂商或个人... 阅读全文

Dive into python 实例学python (2) —— 自省,apihelper

2014-02-12 20:21 by Loull, 698 阅读, 收藏, 编辑
摘要: apihelper.pydef info(object, spacing=10, collapse=1): """Print methods and doc strings. Takes module, class, list, dictionary, or string.""" methodList = [e for e in dir(object) if callable(getattr(object, e))] processFunc = collapse and (lambda s: " ".join(s. 阅读全文

Dive into python 实例学python (1) —— 函数和测试

2014-02-12 20:04 by Loull, 475 阅读, 收藏, 编辑
摘要: odbchelper.pydef buildConnectionString(params): """Build a connection string from a dictionary Returns string. """ return ";".join(["%s=%s" % (k, v) for k, v in params.items()])if __name__ == "__main__": myParams = {"server":" 阅读全文
点击右上角即可分享
微信分享提示