小编Ric*_* Li的帖子

检测角度是否大于180度

我正在研究教授指定的一个问题,而我正在寻找一种方法来检测3点之间的角度是否大于180度,例如:

我想检测alpha是否超过180度.无论如何,我的教授有一个解决问题的代码,但他有一个名为zcross的函数,但我不知道它是如何工作的.有谁能告诉我?他的代码在这里:

#include <fstream.h>
#include <math.h>
#include <stdlib.h>

struct point {
    double  x;
    double  y;
    double  angle;
};

struct vector {
    double  i;
    double  j;
};

point   P[10000];
int     hull[10000];

int 
zcross (vector * u, vector * v)
{
    double  p = u->i * v->j - v->i * u->j;
    if (p > 0)
    return 1;
    if (p < 0)
    return -1;
    return 0;
}

int 
cmpP (const void *a, const void *b)
{
    if (((point *) a)->angle < ((point *) …
Run Code Online (Sandbox Code Playgroud)

c algorithm math trigonometry computational-geometry

20
推荐指数
1
解决办法
7320
查看次数

.vssettings文件(Visual Studio设置)颜色格式

我正在为基于Visual Studio主题的Sublime文本创建自己的配色方案.

Visual Studio主题定义了前景和背景,但它们不在标准RGB三元组中.我不知道这个数字意味着什么,我想知道如何将它转换为RGB三元组(即#FFFFFF)以用于Sublime Text.

样品:

<Item Name="Comment" Foreground="0x007B7466" Background="0x02000000" BoldFont="No"/>
<Item Name="Plain Text" Foreground="0x00F3F2F1" Background="0x002A2822" BoldFont="No"/>
<Item Name="Selected Text" Foreground="0x00FFFFFF" Background="0x0064614F" BoldFont="No"/>
Run Code Online (Sandbox Code Playgroud)

我试过在这里和谷歌搜索,但显然我无法正确找到我的搜索条件以找到正确的答案.

rgb hex vssettings visual-studio sublimetext

10
推荐指数
2
解决办法
2397
查看次数

这两种背包算法是否相同?(他们总是输出相同的东西)

在我的代码中,假设C是容量,N是项目的数量,w [j]是项目j的权重,v [j]是项目j的值,它是否与0-做同样的事情1背包算法?我一直在尝试我的代码在一些数据集上,似乎是这种情况.我之所以想知道这是因为我们教过的0-1背包算法是二维的,而这是一维的:

for (int j = 0; j < N; j++) {
    if (C-w[j] < 0) continue;
    for (int i = C-w[j]; i >= 0; --i) { //loop backwards to prevent double counting
        dp[i + w[j]] = max(dp[i + w[j]], dp[i] + v[j]); //looping fwd is for the unbounded problem
    }
}
printf( "max value without double counting (loop backwards) %d\n", dp[C]);
Run Code Online (Sandbox Code Playgroud)

这是我对0-1背包算法的实现:(具有相同的变量)

for (int i = 0; i < N; i++) {
    for (int j = 0; j …
Run Code Online (Sandbox Code Playgroud)

algorithm knapsack-problem

7
推荐指数
1
解决办法
1233
查看次数

什么是将一组项目公平地分成3个独立组的算法?

我的教科书中有这个问题:给定一组n个项目,每个项目都有一个不同的值V(i),将项目分成3组的最佳方法是什么,以便将具有最高值的组最小化?给出这个最大的组的价值.

我知道如何做这个问题的2堆变体:它只需要在问题上向后运行背包算法.但是,我很困惑如何解决这个问题.任何人都可以给我任何指示吗?

答:与0-1背包几乎完全相同,尽管是2D

algorithm dynamic-programming

7
推荐指数
1
解决办法
2122
查看次数

什么时候std :: priority_queue <>自行排序?

我想知道C++ STL何时priority_queue自行排序.我的意思是insert当你push进入物品时它是否正确地进入了一个正确的位置,或者当你peekpop它出来时它是否对它自己进行排序并给你最优先的项目?我问这个是因为我priority_queue<int>将包含一个可能有值更新的数组的索引,我希望它在我做的时候更新pq.top();.

#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
  priority_queue<int> pq;
  pq.push(2);
  pq.push(5); //is the first element 5 now? or will it update again when I top() or pop() it out?
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

c++ algorithm computer-science stl priority-queue

5
推荐指数
1
解决办法
1462
查看次数

extern关键字"缺少类型说明符"

我正在使用Visual C++ Express创建一个DLL,并在extern ValveInterfaces* VIFace内部声明时 Required.h,编译器告诉我ValveInterfaces没有定义.(我想暴露VIFace给任何文件,包括Required.h)

这是我的文件的结构:

DLLMain.cpp

#include "Required.h" //required header files, such as Windows.h and the SDK  

ValveInterfaces* VIFace;  

//the rest of the file
Run Code Online (Sandbox Code Playgroud)

Required.h

#pragma once
//include Windows.h, and the SDK
#include "ValveInterfaces.h"

extern ValveInterfaces* VIFace; //this line errors
Run Code Online (Sandbox Code Playgroud)

ValveInterfaces.h

#pragma once
#ifndef _VALVEINTERFACES_H_
#define _VALVEINTERFACES_H_
#include "Required.h"

class ValveInterfaces
{
public:
    ValveInterfaces(void);
    ~ValveInterfaces(void);
    static CreateInterfaceFn CaptureFactory(char *pszFactoryModule);
    static void* CaptureInterface(CreateInterfaceFn fn, char * pszInterfaceName);
    //globals
    IBaseClientDLL* gClient; …
Run Code Online (Sandbox Code Playgroud)

c c++ extern

5
推荐指数
1
解决办法
647
查看次数