小编jus*_*tyy的帖子

O(n ^ 2)解决这个问题的速度不够快.更快的方法?

我一直试图在ACM Timus上解决这个问题

http://acm.timus.ru/problem.aspx?space=1&num=1932

我的第一种方法是O(n ^ 2),它肯定不够快,无法通过所有测试.下面的O(n ^ 2)代码在测试10中给出TL.

import java.util.*;
import java.io.*;

public class testtest
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader rr = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(rr.readLine());
        String[] p = new String[n];
        for (int i = 0; i < n; i ++)
        {
            p[i] = rr.readLine();
        }
        int[] diff = new int[]{0, 0, 0, 0};
        for (int i = 0; i < n - 1; i ++)
        {
            for (int j = i …
Run Code Online (Sandbox Code Playgroud)

java string algorithm

16
推荐指数
1
解决办法
909
查看次数

Delphi中有HashSet吗?

Delphi中有HashSet吗?

我知道使用set最多可以容纳255个项目.最新的Delphi编译器中是否有HashSet,例如西雅图的XE8

delphi hashset

15
推荐指数
1
解决办法
1593
查看次数

11
推荐指数
3
解决办法
5万
查看次数

Delphi threadvar是否适用于Parallel.For?

这里

"ThreadVar关键字启动一组线程使用的变量定义.每个线程都有一个单独的每个变量实例,从而避免数据冲突,并保持线程独立性."

所以我可以在Parallel.For这样使用吗?

threadvar
    threadID: integer;

procedure TForm5.Button1Click(Sender: TObject);
var
 Tot: Integer;
begin
 TParallel.For(1, Max, procedure (I: Integer)
   begin
     threadID := i;  // each thread gets its own threadID?
     if IsPrime (threadID) then
       TInterlocked.Increment (Tot);
   end);
end;
Run Code Online (Sandbox Code Playgroud)

delphi

11
推荐指数
1
解决办法
356
查看次数

为什么优化器不会在循环中消除High?

人们说Delphi在整数运算上产生了相当不错的优化代码.我在Delphi 2007中尝试以下示例,并查看编译器生成的汇编代码.

program p1000;
{$APPTYPE CONSOLE}

procedure test;
var
  arr: array of integer;
  i: integer;

begin
  SetLength(arr, 100);
  for i := 0 to High(arr) do
  begin
    if (i = High(arr)) then
    begin
      arr[i] := -9;
    end;
  end;
end;

begin
  test;
  readln;
end.
Run Code Online (Sandbox Code Playgroud)

当构建配置设置为DEBUG时,我可以设置断点并使用短键Ctrl+ Alt+ D来查看其汇编代码,如下所示:

Project3.dpr.11: for i := 0 to High(arr) do
004045A1 8B45FC           mov eax,[ebp-$04]
004045A4 E8F7FAFFFF       call @DynArrayHigh
004045A9 8BF0             mov esi,eax
004045AB 85F6             test esi,esi
004045AD 7C1D             jl $004045cc
004045AF 46               inc …
Run Code Online (Sandbox Code Playgroud)

delphi compiler-construction compiler-optimization

10
推荐指数
1
解决办法
367
查看次数

汇编中的GetThreadID

我阅读了FastMM4的源代码,并注意到这个有趣的功能

function GetThreadID: Cardinal;
{$ifdef 32Bit}
asm
  mov eax, FS:[$24]
end;
{$else}
begin
  Result := GetCurrentThreadID;
end;
{$endif}
Run Code Online (Sandbox Code Playgroud)

我已经测试了它,它有效,所以我的问题是任何解释为什么它有效?

delphi x86 inline-assembly fastmm

10
推荐指数
1
解决办法
772
查看次数

Delphi AsyncCalls访问冲突

Andy开发的这个Library AsynCalls让我印象深刻.

我写了一段代码只是为了测试库,但它总是得到内存A/V,我在这里想念一些东西吗?

以下代码旨在使用两个异步线程并行执行此简单任务(从数组中获取最大值).

program Test;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math,
  Windows,
  Forms,
  AsyncCalls in 'AsyncCalls.pas';

var
  arr: array of integer;
  i: integer;

procedure GetMax(const arr: array of integer; left, right: integer; var max: integer);
var
  i: integer;
begin
  max := arr[left];
  for i := left + 1 to right do
  begin
    if (arr[i] > max) then
    begin
      max := arr[i];
    end;
  end;
end;

const
  N = 100000;

var
  a, b: IAsyncCall;
  maxv, max1, max2: integer;

begin
  SetLength(arr, N); …
Run Code Online (Sandbox Code Playgroud)

delphi

10
推荐指数
1
解决办法
407
查看次数

TParallel.&For和TParallel.For之间有区别吗?

有没有之间的差异TParallel.&ForTParallel.For

两者都可以在Delphi 10 Seattle中编译.那么我应该坚持哪一个?

delphi delphi-10-seattle

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

Delphi 10 Seattle和10.1 Berlin无法调试COM DLL

我有一个COM DLL项目,我能够在Delphi 2007和XE8中调试它(在断点处停止).

但是,似乎IDE无法在Delphi 10 Seattle或10.1 Berlin的断点处停止.

我的调试步骤:

  1. 更改为DEBUG(并检查勾选的那些调试选项.例如,调试信息)

  2. regsvr32输出目录下的项目DLL

  3. 编写一个简单地创建COM对象并调用其方法的vbscript

  4. 在调试器中,为32位或64位调试设置Run命令行c:\windows\syswow64\cscript.exec:\windows\system32\cscript.exe

  5. 设置命令行参数以运行vbscript.

  6. 在调用的方法上设置断点.

  7. 点击F9

预计:在断点处停下来

在Delphi 2007和XE8中,一切都很好,但我无法在Delphi Seattle或Berlin中完成.

什么可能出错?在Delphi的最新IDE版本下,为了调试COM DLL,是否需要启用/禁用任何设置?

delphi delphi-10-seattle delphi-10.1-berlin

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

LongInt和Integer,LongWord和Cardinal之间的区别

在Delphi中,LongInt和Integer,LongWord和Cardinal有什么区别?

有时我会发现DWORD的用法,它是什么?

它们在所有版本的Delphi中是否一致?我应该坚持哪一个?

delphi

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