问题列表 - 第34608页

挑选五个总和为S的数字

给定一个数组AN非负数,我感兴趣的是找到办法,你可以选择5个号码(数组中从不同的位置)的数量,使得它们的总和S.

有一个简单的解决方案O(N^3):

Let H be a hash table of (sum, position of leftmost element of sum)
for i = 0, N
    for j = i + 1, N
        H.add(A[i] + A[j], i)

numPossibilities = 0
for i = 0, N
    for j = i + 1, N
        for k = j + 1, N
            numPossibilities += H.get(S - (A[i] + A[j] + A[k]), k)
Run Code Online (Sandbox Code Playgroud)

其中H.get(x, y)返回散列中元素的数量,其总和具有相同的散列,x并且其最左边的元素大于k.

或者,我们可以将3个元素的总和添加到哈希表中,然后继续使用2个嵌套for循环.然而,复杂性仍然相同,我们只使用更多内存.

假设输入是相当随机的(因此没有最坏情况的哈希),是否有一种算法可以解决这个问题, …

algorithm optimization hash

19
推荐指数
1
解决办法
3111
查看次数

Xcode从.pch编译错误?(IOS)

在对iPhone应用程序进行更改时,我保存并编译了; 得到了以下错误......解开了一切,我现在陷入了这些错误.我已经尝试清理构建,从这个文件夹复制文件,尝试在另一台机器上构建.我无法想到解决它,我所做的改变是.xib文件; 我删除了IBOutlet,因为我不再需要该元素.

有谁知道如何解决这些问题 - >对于长调试输出感到抱歉但是认为太多信息会比太少更好.

Build Hunter of project Hunter with configuration Debug

ProcessPCH /var/folders/di/diNSUsegESCJmVpYf71u4U+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/Hunter_Prefix-ewmgimmftydqkieofchvanjjzzvq/Hunter_Prefix.pch.pth Hunter_Prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd "/Users/stuartloxton/Documents/Hunter New"
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -x objective-c-header -arch i386 -fmessage-length=0 -pipe -fdiagnostics-print-source-range-info -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -fasm-blocks -mmacosx-version-min=10.6 -gdwarf-2 -fvisibility=hidden -fobjc-abi-version=2 -fobjc-legacy-dispatch -iquote "/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/Hunter-generated-files.hmap" "-I/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/Hunter-own-target-headers.hmap" "-I/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/Hunter-all-target-headers.hmap" -iquote "/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/Hunter-project-headers.hmap" "-F/Users/stuartloxton/Documents/Hunter New/build/Debug-iphonesimulator" "-F/Users/stuartloxton/Documents/Hunter New" "-I/Users/stuartloxton/Documents/Hunter New/build/Debug-iphonesimulator/include" "-I/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/DerivedSources/i386" "-I/Users/stuartloxton/Documents/Hunter New/build/Hunter.build/Debug-iphonesimulator/Hunter.build/DerivedSources" -c "/Users/stuartloxton/Documents/Hunter New/Hunter_Prefix.pch" -o /var/folders/di/diNSUsegESCJmVpYf71u4U+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/Hunter_Prefix-ewmgimmftydqkieofchvanjjzzvq/Hunter_Prefix.pch.pth

In file included …
Run Code Online (Sandbox Code Playgroud)

iphone xcode

9
推荐指数
1
解决办法
9534
查看次数

SQL连接:SQL ANSI标准的未来(vs加入)?

我们正在开发ETL工作,我们的顾问在连接表时一直使用"旧式"SQL

select a.attr1, b.attr1
from table1 a, table2 b
where a.attr2 = b.attr2
Run Code Online (Sandbox Code Playgroud)

而不是使用内部连接子句

select a.attr1, b.attr1
from table1 as a inner join table2 as b
   on a.attr2 = b.attr2
Run Code Online (Sandbox Code Playgroud)

我的问题是,从长远来看,是否有使用旧"加入"的风险?这种连接支持多长时间并保持为ANSI标准?我们的平台是SQL Server,我的主要原因是将来不再支持这些"where join".发生这种情况时,我们必须使用"内连接"连接方式修改所有ETL作业.

sql sql-server join ansi-sql sql-server-2008

8
推荐指数
2
解决办法
2507
查看次数

四元数绕轴旋转的分量

我很难找到关于这个主题的任何好消息.基本上我想找到四元数旋转的分量,即围绕给定轴(不一定是X,Y或Z - 任意单位矢量).有点像将四元数投影到矢量上.因此,如果我要求围绕与四元数轴平行的某个轴进行旋转,我将得到相同的四元数.如果我要求围绕与四元数轴正交的轴旋转,我会得到一个标识四元数.中间......嗯,这就是我想知道如何解决:)

rotation quaternions

38
推荐指数
2
解决办法
3万
查看次数

GoogleMaps v3 API点击时只创建一个标记

我在点击上成功创建了一个标记但是,使用下面的代码,每次点击都会得到一个新标记,我只想要添加一个标记,如果有人点击多次,我希望将现有标记移动到新标记位置任何人都可以帮助这里是代码

 function placeMarker(location) {
        var clickedLocation = new google.maps.LatLng(location);
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    }

google.maps.event.addListener(map, 'click', function(event) {
        placeMarker(event.latLng);
Run Code Online (Sandbox Code Playgroud)

google-maps google-maps-api-3

29
推荐指数
1
解决办法
3万
查看次数

如何防止双击HTML5画布外的文本选择?

(在我尝试的每个浏览器中)双击HTML5画布选择紧跟canvas元素后面的任何文本.我宁愿将点击限制在画布上.

(注:我不想完全禁用文本选择(例如像这样):如果您双击它应选择文本我只是不希望点击到从画布"泄漏".)

这可能吗?

这是一个简单的页面,演示了这个问题.

javascript css html5 canvas

8
推荐指数
1
解决办法
5881
查看次数

如果没有连续的内存空间,realloc会怎么做?

realloc 用于动态重新分配内存.

假设我已经使用该malloc函数分配了7个字节,现在我想将其扩展到30个字节.

如果内存中没有30个字节的连续(连续单行)空间,后台会发生什么?

是否有任何错误或内存将被分配?

c realloc dynamic-memory-allocation

11
推荐指数
2
解决办法
2578
查看次数

调用包含数组的函数

请看我的代码:

function getShopConfig()
{

$sql = "SELECT sc_name, sc_address, sc_phone, sc_email, sc_shipping_cost, sc_order_email, cy_symbol, sc_currency
        FROM kol_shop_config , kol_currency
        WHERE sc_currency = cy_id";
$result = dbQuery($sql);
$row    = dbFetchAssoc($result);

if ($row) {
    //extract($row);

 $shopConfig = array('name'           => $row['sc_name'],
                        'address'        => $row['sc_address'],
                        'phone'          => $row['sc_phone'],
                        'email'          => $row['sc_email'],
                        'sendOrderEmail' => $row['sc_order_email'],
                        'shippingCost'   => $row['sc_shipping_cost'],
                        'currency'       => $row['sc_currency']);
}
return $shopConfig;  

}
Run Code Online (Sandbox Code Playgroud)

然后我称之为,

<td colspan="4" align="right"><?php getShopConfig(); echo $shopConfig['name'];?></td>
Run Code Online (Sandbox Code Playgroud)

但没有显示任何内容..错误在哪里?请帮忙.

注意:两者都在同一页面中.dbQuery()和dbFetchAssoc()函数是预定义的,之前已正常工作.如果我在函数内部回显它然后只是调用它然后它正常工作.

php

0
推荐指数
1
解决办法
96
查看次数

Rails:如何使用OR而不是AND链接范围查询?

我正在使用Rails3,ActiveRecord

只是想知道如何用OR语句而不是AND来链接范围.

例如

Person.where(:name => "John").where(:lastname => "Smith")
Run Code Online (Sandbox Code Playgroud)

这通常会返回name ='John'和lastname ='Smith',但我想:

name ='John'或lastname ='Smith'

activerecord ruby-on-rails ruby-on-rails-3 rails-activerecord

131
推荐指数
14
解决办法
10万
查看次数

HTML5将画布保存到服务器上的文件

我需要使用给定的图像,用户可以搽,并直接HTML5画布(通过一种保存按钮),上传它的定制服务器上的版本,以创建一个组件.

我可以使用html canvas吗?有什么建议吗?

thx提前

javascript html5 canvas

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