B – Who’s in the Middle

  B – Who’s in the Middle FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less. Input * ...

A – All in All

  A – All in All You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. Given two strings s and t, you have to decide whethe ...

linux下多线程多进程pthread的使用以及理解

word文档:点击此处进行下载 一些函数的具体用法就不明说了,只做一些核心的解释 下面直接贴代码: pthread_create():创建一个线程   /* thread_create.c */ #include<stdio.h> #include<stdlib.h> #include<pthread.h> /* 线程函数1 */ void *mythread1(void){ int i; for(i=0;i<5;i++){ printf("I am the 1st pthread,created by mybeilef321\n"); sleep(2); } } /* 线程函数2 */ void *mythread2(void){ int i; ...

CodeBlock安装后无法运行为什么?无法找到编译器?

安装完codlblocks后常会出现以下警告:cant find compiler executable in your configured search paths for GNU GCC Compiler 提示给出的路径无法找到编译器。 注意:CodeBlock只是一个IDE(集成开发环境,Integrated Development Environment),其编译器一般是mingw或GCC(TDM-GCC),Codeblock分为带编译器的安装程序,和不带编译器的安装程序。 可以下载自带编译器的codeblocks,否则得先安装一个编译器(例如,GCC编译器)才能将该编译器加载到codeblocks. 安装之后在Code::Blocks的菜单中点击Settings->Compiler,如果安装了 ...

筛选法求素数

用筛法求素数的基本思想是:把从1开始的、某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉。剩下的数中选择最小的数是素数,然后去掉它的倍数。依次类推,直到筛子为空时结束。 如有: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1不是素数,去掉。剩下的数中2最小,是素数,去掉2的倍数,余下的数是: 3 5 7 9 11 13 15 17 19 21 23 25 27 29 剩下的数中3最小,是素数,去掉3的倍数,如此下去直到所有的数都被筛完,求出的素数为: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 4 ...

c++折半查找

介绍 折半查找,又称作二分查找。这个查找的算法的特点,就是,要求数据要是有序的。 1 ,存储结构一定是顺序存储 2 ,关键字大小必须有序排列 然后,利用这组有序的数据之间的关系,来进行折半的查找。 比方说,这组数据是升序排列的。一开始,首先对比这组数据的中间的项与关键值(key)的关系。若是关键值(key)>中间值,则说明,关键值(key)在中间值的右侧,因此将这组数据的区间缩小为以中间值为最左侧的小区间。然后,继续用中间值进行比较,以此类推,最终肯定会找到在数组当中与之匹配的关键值,直到区间缩小为0还没找 ...