摘要:Language:Bode PlotTime Limit:1000MSMemory Limit:10000KTotal Submissions:12040Accepted:7721DescriptionConsider the AC circuit below. We will assume that the circuit is in steady-state. Thus, the voltage at nodes 1 and 2 are given by v1= VScoswt and v2= VRcos (wt +q) where VSis the voltage of the sour
阅读全文
摘要:ParencodingsTime Limit:1000MSMemory Limit:10000KTotal Submissions:17819Accepted:10715DescriptionLet S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses before the ith right p
阅读全文
摘要:Web NavigationTime Limit:1000MSMemory Limit:10000KTotal Submissions:27086Accepted:12109DescriptionStandard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reac
阅读全文
摘要:proj 1007:DNA SortingTime Limit:1000MSMemory Limit:10000KTotal Submissions:76307Accepted:30599DescriptionOne measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'',
阅读全文
摘要:Maya CalendarTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 63165Accepted: 19479DescriptionDuring his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day lon
阅读全文
摘要:proj1003:HangoverTime Limit:1000MSMemory Limit:10000KTotal Submissions:93180Accepted:45118DescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the
阅读全文
摘要:void merge(int *A,int p,int q,int r){//归并排序 合并数组部分int *temp1 = new int[q-p+1];int *temp2 = new int[r-q+1];for(int i = 0;itemp2[flag2]){A[m+p] = temp2[flag2];flag2++;}else if(temp1[flag1]<=temp2[flag2]){A[m+p] = temp1[flag1];flag1++;}}}delete []temp1;delete []temp2;}void merge_sort(int *A,int p,in
阅读全文
摘要:无符号整型(U),有符号整型(T),以B表示二进制数,w表示有效位数。B2U表示二进制数据转化成无符号整型。 B2T:表示二进制数据转化成有符号数据。 U2T:无符号数据转化成有符号数据。 T2U:有符号转化成无符号数据。 c语言在处理同时包含有符号和无符号的表达式时,会隐含的将有符号转化成无符号,并假设这两个数都是非负的来执行这个运算。这对于标准的算术运算并无差异,但对关系运算来说,它会导致与直觉不相符的结果。当一个有符号和无符号数据比较是会将有符号数据转化成无符号数据在比较大小。如c语言在判断表达式(-10U),这与实际不符合。
阅读全文
摘要:Description 有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?Input 输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。n=0表示输入数据的结束,不做处理。 Output 对于每个测试实例,输出在第n年的时候母牛的数量。每个输出占一行。 Sample Input 2450 Sample Output 246 Source 一种错误的算法:int num_of_cows(int age,int year_left){if(year_lef
阅读全文
摘要:// shell_sort.cpp : 定义控制台应用程序的入口点。//#includeusing namespace std;/**以一定步长对数组中数字进行排序(a:待排序数组,len:数组长度,inc:步长,b:单步步长排序后数组,left:步长余量)*/void step_insert_so...
阅读全文
摘要:一、程序运行平台 不同的平台上对不同数据类型分配的字节数是不同的。 个人对平台的理解是CPU+OS+Compiler,是因为: 1、64位机器也可以装32位系统(x64装XP); 2、32位机器上可以有16/32位的编译器(XP上有tc是16位的,其他常见的是32位的); 3、即使是32位的编译器也可以弄出64位的integer来(int64)。 以上这些是基于常见的wintel平台,加上我们可能很少机会接触的其它平台(其它的CPU和OS),所以个人认为所谓平台的概念是三者的组合。 虽然三者的长度可以不一样,但显然相互配合(即长度相等,32位的CPU+32位的OS+32位的Com...
阅读全文
摘要:目 录1概念2判断方法3常见排序算法的稳定性1概念假定在待排序的记录序列中,存在多个具有相同的关键字的记录,若经过排序,这些记录的相对次序保持不变,即在原序列中,ri=rj,且ri在rj之前,而在排序后的序列中,ri仍在rj之前,则称这种排序算法是稳定的;否则称为不稳定的。2判断方法对于不稳定的排序算法,只要举出一个实例,即可说明它的不稳定性;而对于稳定的排序算法,必须对算法进行分析从而得到稳定的特性。需要注意的是,排序算法是否为稳定的是由具体算法决定的,不稳定的算法在某种条件下可以变为稳定的算法,而稳定的算法在某种条件下也可以变为不稳定的算法。例如,对于如下起泡排序算法,原本是稳定的排序算法
阅读全文
摘要:最近在学习linux环境高级编程,多进程编程算是编程中的最重要的一个部分了,本文让我学习和明白了很多,所以转载过来。让更多想多线程编程的人学习。只有顶到首页才能让更多的人学习。文章摘要: 多线程程序设计的概念早在六十年代就被提出,但直到八十年代中期,Unix系统中才引入多线程机制,如今,由于自身的许多优点,多线程编程已经得到了广泛的应用。本文我们将介绍在Linux下编写多进程和多线程程序的一些初步知识。-------------------------------------------------------------------------------- 正文: Linux下的多...
阅读全文
摘要:创建进程时经常会用到进程号的类型定义:pid_t。我们都知道这个类型定义实际上就是int型。但是在linux下的c中的头文件中这个定义到底是怎么定义的呢?今天就把以前找这个定义的过程贴出来:1.首先在/usr/include/sys/types.h中有如下定义#include ...... #ifndef __pid_t_definedtypedef __pid_t pid_t;# define __pid_t_defined#endif可以看到pid_t 其实就是__pid_t类型。2.在/usr/include/bits/types.h中可以看到这样的定义#include #if __..
阅读全文
摘要:字符串匹配算法方法一:朴素法:扫描待匹配字符串找出所有匹配子字符串,方法简单直接,这里省略代码方法二:字符串匹配之rabin karp算法用到的结论:(X*Y)%Q = ((X%Q)*Y)%Q/*Filename:rabin_karp_matcher.cpp */#include#include#includeusing namespace std;int chartoint(char in){//字符转换成数字函数 int m = in - '0'; return m;}void rabin_karp_matcher(char *t,char*p,int d,int q){/
阅读全文
摘要:/*Filename:gcd.cpp *//*计算两个数的公约数*//*原理:反转相减法*/#includeusing namespace std;int gcd(int a,int b){ int big = a > b?a:b; int small = a > b?b:a; int result = 2; while((result != 1)&&(result != 0)){ result = big - small; big = result > small?result:small; small = result > small?small:r
阅读全文
摘要:方法一: 直接排序法,这是一种最直观最容易理解的方法,先将数组用某种方法进行排序,然后选取第k大的数,算法的好坏取决与排序算法,常见的排序有,冒泡排序(n^2),擦入排序(n^2),堆排序(nlgn),快速排序(nlgn),归并排序(nlgn),计数排序(n+k),基数排序(n),由于方法简单这里就不给出代码了。方法二:// find_kth.cpp : 定义控制台应用程序的入口点。//方法类似于归并排序,平均时间复杂度O(n),最坏时间复杂度O(n^2)#include "stdafx.h"#includeusing namespace std;int find_the_
阅读全文