如何将这种快速排序算法转换为3,5,7,9和11个元素的分区?
#include"stdafx.h"
#include<iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#define size 50
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
int partition(int i,int j )
{
return((i+j) /2);
}
void quicksort(int list[],int m,int n)
{
int key,i,j,k;
if( m < n)
{
k = partition(m,n);
swap(&list[m],&list[k]);
key = list[m];
i = m+1;
j = n;
while(i <= j)
{
while((i <= n) && (list[i] <= key))
i++;
while((j >= m) …
Run Code Online (Sandbox Code Playgroud) 我们可以选择3元素分区的中位数来实现快速排序.同样,我们可以选择5,7或11元素的中位数来实现快速排序吗?如果是这样,那怎么样?
我正在研究宾馆管理系统。每天、每周和每月生成不同的报告。例如,我有包含房间号、租金等的房间等级。根据公式(房间占用率=房间占用总数/房间总数)每周生成房间占用报告,
我如何在我的报告中表示此报告或任何其他报告类图还是我需要将它包含在我的类图中?
在我的algoritham分析课程中,老师告诉我们,Breath First搜索的时间复杂度是O(V + E)但现在在人工智能课程中,老师说BFS的复杂性是O(b d).当我问他问题时,他给了我一个合乎逻辑的理由,即"在理论计算机科学中,O(V + E)是合适的,因为图形是输入到搜索算法的显式数据结构.在AI中,图形通常表示由初始状态,动作和转移模型隐含地且经常是无限的.因此,复杂性以O(b d)"表示.现在我有两个问题
algorithm artificial-intelligence breadth-first-search time-complexity
在采访中我被问到以下问题(不幸的是我找不到比N ^ 2更好的答案)
对于给定的阵列arr
为unsigned int
的大小N,每个元素(索引i
)我应该在索引返回元件j
(j> i)中,使得arr[j] > arr[i]
即我应该返回阵列RES其中RES [I]具有ARR [J ],j> i,arr [j]> arr [i],j在所有索引k中都是min,例如arr [k]> arr [i]
arr[] = {3,1,4,2,5,7};
res[] = {2,2,4,4,5,-1};//-1 says no such index
Run Code Online (Sandbox Code Playgroud)
是否有更好的时间复杂性?谢谢
我刚刚写了一个小程序,它在一个颜色阈值化的二进制图像中搜索轮廓,在阈值化后用 canny 处理,但不知何故,它总是为图像中的每个对象找到两个轮廓。
在绘制找到的轮廓的右下方图像中,您可以看到最大的轮廓被绘制了两次,两个轮廓之间有一点偏移。下图显示了该图像的详细视图。
http://img831.imageshack.us/img831/3641/doubleframe2.png
这里只绘制了最大的轮廓两次,但每隔一个轮廓就会随机发生一次。我只想要每个对象都有一个轮廓,我怎样才能做到这一点?:/
更新:
由 findContours 方法填充的轮廓向量的大小为 8,而它的大小应仅为 4。
更新 2:
这是来自 kinect http://img405.imageshack.us/img405/9761/inputimage.jpg的 rgb 输入图像,
用于颜色阈值我使用以下方法
cv::cvtColor(in, out, CV_BGR2HSV);
cv::inRange(out,
cv::Scalar(25, 131, 97),
cv::Scalar(35, 220, 217),
out);
Run Code Online (Sandbox Code Playgroud)
然后是一个大小为 1 的 rect 元素的腐蚀 + 膨胀。
我正在开发一个应用程序,在该应用程序中我使用来自站点的 jsoup 解析 XML 文件并将其显示在 textview 上。我遇到的问题是 RSS 中包含的格式说明符 \n 不是 wprking。而不是进入新行,它只是显示 \n 原样。这是我的代码
hello = sb.toString();
String title, description = null;
Document document = Jsoup.parse(hello);
Elements a = document.getElementsByTag("item");
for (Element element : a) {
title = element.child(0).text();
description = element.getElementsByTag("description").get(0).text();
String src = Jsoup.parse(description).select("img").first().attr("src");
String id = Jsoup.parse(description).select("id").text();
description = Jsoup.parse(description).text();
description = description.replace(id, "");
description = description.replace("/", "\\");
list.add(new News(title, id, src, description ));
Run Code Online (Sandbox Code Playgroud)
描述包含 \n 标签,但在文本视图中它不起作用,如图所示。正如您在第一行中看到的那样,而不是进入新行 \n 显示原样。
没有使用super.paintComponent(g);
可以我仍然清除我的Jpanel或Jframe屏幕?我在JPanel上绘制了一些形状,我希望在用户按下右键而不使用此方法时清除所有绘图.或者我说是在Java中有任何替代的super.paintCompenent(g)
方法或方法clrscr();
.
编辑
public void mousePressed(MouseEvent e) {
super.paintComponents(null); //i want to use this method here?? how can i?
if(e.isPopupTrigger())
{
s=e.getX();
as=e.getY();
try {
Thread.sleep(10L);
} catch (InterruptedException ex) {
Logger.getLogger(animate.class.getName()).log(Level.SEVERE, null, ex);
}
p.repaint();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在画这样的形状
public class mypanel extends JPanel {
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g ;
Color[] c = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW,
Color.MAGENTA, Color.WHITE, Color.ORANGE, Color.PINK};
for(int i=0; i<8; ++i){
g2.setColor(c[i]);
int start_angle=i*45;
g2.fillArc(mx-100, my-100, …
Run Code Online (Sandbox Code Playgroud) aField = models.ForeignKey('self')
class aClass(models.Model): aField = models.ForeignKey('aClass')
我的中位数 3 实现在这里不能正常工作。我必须随机选择 3 个数字作为中号,这是我的代码,请帮助我。
#include"stdafx.h"
#include <iostream>
#include<algorithm>
using namespace std;
#define size 10
int i;
void show(int* array, int n);
int partition(int* array, int pValue, int left, int right);
void QuickSort(int* array, int left, int right);
int main(void)
{
int array[size];
int i;
for( i = 0; i < size; i++)
{
array[i]=rand()%100;
}
cout<<endl<<"The random generated numbers are: "<<endl;
show(array, size);
QuickSort(array,0,size - 1);
cout<<endl<<"The sorted numbers are : "<<endl;
show(array, size);
system("pause");
return 0;
}
void …
Run Code Online (Sandbox Code Playgroud)