Fast query on the number of elements in a quarter plane

I have a scatter of 2D elements on a 2D plane.

I would like an efficient algorithm to prepare and query the number of points in a quarter plane (inclusive of boundary).

The quarter plane is defined by a point $ (x,y)$ . All elements $ (x’, y’)$ where $ x<=x’$ and $ y<=y’$ are in the quarter plane.

For example

  • I have elements [(1,1), (2,2), (1,2), (3,2)],
  • My queries are [(1,1), (2,2), (3,3)]

The program should return [1,3,4].

This is for a past competitive programming challenge (WiFi Network problem in this competition)

Fast approach to do losummation in Compile[]?

My code does massive Summation and Matrix multiplication

Compile[] has boosted it distinctly. But I read some literatures related to my program, It seems there are approches to make it even faster. Maybe it can be improved from optimizing MMA language or algorithm itself.

My first piece code is below.

MomentComputing =   Compile[{{Mmax, _Integer}, {k, _Integer}, {image, _Real,      2}, {xLegendreP, _Real, 2}, {yLegendreP, _Real, 2}},    Block[{m, n, width, momentMatrix},    width = Length[image];    momentMatrix = Table[0., {Mmax + 1}, {Mmax + 1}];    Do[ momentMatrix[[m + 1, n + 1]] = ((2. (m - n) + 1.) (2. n + 1.)/((k k)*width width)) xLegendreP[[         m - n + 1]].image.yLegendreP[[n + 1]], {m, 0, Mmax}, {n, 0,       m}];        momentMatrix], CompilationTarget -> "C",    RuntimeAttributes -> {Listable}, Parallelization -> True,     RuntimeOptions -> "Speed"] 

It should be better if I don’t use any loop operations. But I can not figure out any other approaches. Probably matrix vector multiplication should be time-consuming as well.

Second piece.

Reconstruction =    Compile[{{lambdaMatrix, _Real, 2}, {lPoly, _Real, 2}},     Block[{Mmax, width, x, y, m, n, reconstructedImage},     {Mmax, width} = Dimensions[lPoly];     reconstructedImage = Table[0., {width}, {width}];     Do[      reconstructedImage[[x, y]] =        Sum[lambdaMatrix[[m + 1, n + 1]]*lPoly[[m - n + 1, x]]*         lPoly[[n + 1, y]], {m, 0, Mmax - 1}, {n, 0, m}]      {x, 1, width}, {y, 1, width}];     reconstructedImage], CompilationTarget -> "C",     RuntimeAttributes -> {Listable}, Parallelization -> True,     RuntimeOptions -> "Speed"]; 

Likewise, I don’t want Do[] loop here. In addition, I think Sum[] is a very slow function.

I can give all my code if necessary.

Edit 1:

According to Micheal’s suggestion, the first part is fast enough. It does not need acceleration anymore. The second part is the main time-consuming part, I believe it can speed up anyway.

How to fast play Traps/Loot/Hidden treasure

As new players, we ran our first dongeon and the session left me a bitter taste. Some part lasted a long time without being usefull, those parts were when we were searching for treasures or traps.

Indeed, before entering EVERY room the group was : "we look at the door/every tile we step on/wall to determine if there is a hidden trap", and the DM to reply "OK roll for an investigation/perception". And actually there were only one trap for the full dongeon…

Then when we entered a new rom, EVERY player were asking the DM : "I am searching for a hidden treasure/loots/secret door". And the DM, one player at a time : "ok roll", just in order to loot a few pieces from the dead bodies or nothing most of the time…

My questions is : how to manage Traps/Loots/Hidden Treasures without rolling everytime for everyone and avoiding (as much as possible) to miss a secret door/treasure/hidden trap ?

Looking for fast LP solver algorithm for my Special case

I am interested to know what is the fastest algorithm (complexity wise) known to us to solve the following linear program. Due to its simplicity, I hope for a very fast algorithm. Your help is greatly appreciated and I would appreciate you providing me with relevant papers as well.

Context: I am trying to give an algorithm related to graph theory. Unfortunately, my knowledge of LP is very limited that is why I need your guidance. In the following algorithm $ 2k$ is the degree of the investigated vertex. Ideally, I am looking for $ O(k)$ or $ O(k \log k)$ solution, or in total $ O(n)/O(n\log n)$ when this applies to all the vertices. Note that $ |E|= O(n)$ . However, any fast algorithm would be appreciated.

Minimize: $ T$
Subject to:
$ \forall i \in [2k] \qquad 1 \le t_i \le 2k$

Comment: Ensuring that $ \forall i, j \in [2k],\ i \neq j \qquad |t_i – t_j| \ge 1$
Comment: I want $ t_i$ ‘s to be distinct positive integers in [2k]
$ \forall i, j \in [2k],\ i \neq j \qquad 1 \ge t_i – t_j$
$ \forall i, j \in [2k],\ i \neq j \qquad 1 \ge t_j – t_i$

$ \forall i \in [2k],\ i \text{ is an odd number} \qquad t_i \le t_{i+1}$

$ \forall i \in [k] \qquad 0 \le x_i \le 1$
$ \forall i \in [k] \qquad \text{A linear constraint}\ F(x_i,\ t_{2i},\ t_{2i-1},\ T)$

Assuming the Exponential time hypothesis is true, what’s the fast possible algrotimh’s that can be produced for NP-complete problems [duplicate]

Assuming the Exponential time hypothesis is true, what’s the fast possible algrotimh’s that can be produced for NP-complete problems?

If 3-Sat takes exponential time, then could it be possible that some NP-complete problems can be solved in $ n^{log^k(n)}$ time? $ 2^{n^{1/log(log(n))}}$ time? $ 2^{n^{0.5}}$ time?

WordPress Speed Optimization Service – Make Your WordPress Super Fast

We are a team of WordPress experts who focuses on WordPress speed optimization.

What will we do for you?

  • Google Page / Pingdom / GTMetrix Speed Optimization
  • Mobile Loading Speed Optimization
  • Extra Loading Speed Optimization
  • Optimize All Images
  • Reduce the number of plugins
  • Use CDN ( if you want )
  • Full Before & After Report

We charge $150 per website.

Have any questions? Feel free to contact me!

My contacts:
Skype: never2stop
Telegram: WPLegends

.png   1.png (Size: 202.44 KB / Downloads: 0)

.png   2.png (Size: 210.25 KB / Downloads: 0)

.png   3.png (Size: 103.04 KB / Downloads: 0)

.png   4.png (Size: 171.76 KB / Downloads: 0)

.png   5.png (Size: 87.12 KB / Downloads: 0)

.png   6.png (Size: 213.76 KB / Downloads: 0)

.png   7.png (Size: 54.8 KB / Downloads: 0)

.png   8.png (Size: 52.45 KB / Downloads: 0)

.png   9.png (Size: 237.95 KB / Downloads: 0)

Can I use Fast Hands to draw something from a magic item?

My DM gave me a magic little bag that has the description:

Someone holding the pouch could reach into it and speak the name of any type of nonmagical seasoning—salt, pepper, saffron etc.—and produce enough of that seasoning to apply to a single meal. This power could be used up to ten times until the pouch recovered its magic at the next dawn.

I’ve read that you can’t use an object that requires an action to use/activate, but that item does not require an action (and don’t need to get activated neither) and we’ve ruled it produces enough for a single meal, but does not requires to be applied on a meal. Wich means it’s basically the same thing as taking an item from a Bag of Holding.

I wanted to be able to draw pepper as an action and a bonus action, that way I would be able throw pepper in someone’s eyes on my next turn.