About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent…
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by e…
A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call,…
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it i…
插入排序: 在<算法导论>中是这样描述的 这是一个对少量元素进行排序的有效算法.插入排序的工作机理与打牌时候,整理手中的牌做法差不多. 在开始摸牌时,我们的左手是空的,牌面朝下放在桌子上.接着,一次从桌子上摸起一张牌,并将它插入到左手一把牌中的正确位子上. 为了找到这个正确的位置,要将它与手中已有的每一张牌从右到左进行比较,无论什么时候,左手的牌都是排好序的. 算法思想: 将一个记录插入到已经排好序的有序表中,从而得到一个新的,记录数加1的有序表. 图解: 每一张图都是一个for循环.红色和绿…
冒泡排序应该是最常用的排序方法,我接触的第一个排序算法就是冒泡,老师也经常那这个做例子. 冒泡排序是一种交换排序, 基本思想: 通过两两比较相邻的记录,若反序则交换,知道没有反序的记录为止. 例子: 依次类推.这里可以看出,每次比较从最后一个开始,向前比较,若反序则交换: 每次都保证了是两两相邻的记录比较. 冒泡排序的代码: void bubble_sort (myDataType *ary,int len) { int i,j; ;i<len;i++) { ;j>=i;j--) { ]) {…
之前在冒泡排序的附录中提到可以在每次循环时候,不用交换操作,而只需要记录最小值下标,每次循环后交换哨兵与最小值下标的书, 这样可以减少交换操作的时间. 这种方法针对冒泡排序中需要频繁交换数组数字而改进. 以此类推... 代码: void selectionSort(myDataType *ary,int len) { int i,j; int mymin; //记录最小值下标 ;i<len;i++) // 哨兵下标 { mymin = i; ;j<len;j++) //欲比较的下标 { if…
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent…
1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct People { int m_id; int m_virtue; int m_talent; People(int id, int virtue, int talent): m_id(id…
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣…