Pagini: [1]   În jos
  Imprimă  
Ajutor Subiect: Hill Climbing Shortlist  (Citit de 7939 ori)
0 Utilizatori şi 1 Vizitator pe acest subiect.
Cosmin
Echipa infoarena
Nu mai tace
*****

Karma: 351
Deconectat Deconectat

Mesaje: 1.799



Vezi Profilul
« : Iunie 23, 2015, 06:05:51 »

http://www.infoarena.ro/blog/hill-climbing-shortlist
Memorat
SebiSebi
Nu mai tace
*****

Karma: 76
Deconectat Deconectat

Mesaje: 306



Vezi Profilul
« Răspunde #1 : Iunie 23, 2015, 11:57:42 »

The first problem can be solved using Simulated Annealing method. Time complexity is O(N log P), where P depends on the precision the result is calculated. This method also works for the third problem.
« Ultima modificare: Iunie 23, 2015, 21:00:46 de către Pirtoaca George Sebastian » Memorat
loses
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 14



Vezi Profilul
« Răspunde #2 : Iunie 23, 2015, 16:28:08 »

For #1 since it's the squared distance, the x and y coordinates are independent to each other Smile
Hence, the cost for x is sum((x[itr] - cX) ^ 2)
And this is sum(x[itr] * x[itr] - 2 * cX * x[itr] + cX * cx)
From this we have a 2nd degree equation
N * cX * cX - 2 * cX * sum(x[itr]) + sum(x[itr] * x[itr])
And cX = sum(x[itr]) / N

#[2, 5] it is correct to do some hill climbing like ... right?
Cod:
rez = [0, 0]
p = maxRange
while p >= 0:
  mn = f(rez)
  where = -1
  for dir in allDirections(2 * nrDimensions):
    if f(rez + changeDir[dir] * p) < mn:
      mn = f(rez + changeDir[dir] * p)
      where = dir
  if where == -1:
    p /= 2
  else
    rez = changeDir[where] * p + rez

this should run in O(N * logMaxRange * nrDimension) ~ around there Smile
with a bigger, lets say, constant

#11 Is there a faster way than making a min-matching in the graph, and the result is just the answer?
« Ultima modificare: Iunie 23, 2015, 18:22:44 de către blank never » Memorat
retrograd
Client obisnuit
**

Karma: 3
Deconectat Deconectat

Mesaje: 50



Vezi Profilul
« Răspunde #3 : Iunie 24, 2015, 16:46:51 »

[#10]: If n is large (I think N>=7 holds), we can make an undirected graph where the vertices are the N peeps, and the edges are { (u,v) : u is not an enemy of v }. For a large N, the graph would be dense enough for us to apply the Hamiltonian Cycle in a dense graph algorithm, as shown here: http://www.infoarena.ro/ciclu-hamiltonian-in-graf-dens.
The cycle would give an "ideal" scenario, where no 2 enemies are near each other. That ought to make them happy enough Smile .

For N<7, a brute-force approach should work fine.

For this solution to be correct, I presumed the "enemy" relationships are reciprocal (and, let's be serious, they usually are). If they are not, however, we redefine the edges to be {(u, v) : u is not an enemy of v and v is not an enemy of u}. If the graph is dense, we apply the algorithm. If is is not, then N is small enough and we can use the brute-force (or a randomized approach, if we want to be sneakier).
Memorat
klamathix
Echipa infoarena
Nu mai tace
*****

Karma: 733
Deconectat Deconectat

Mesaje: 1.216



Vezi Profilul
« Răspunde #4 : Iunie 24, 2015, 17:05:22 »

@Lucian Bicsi

It seems that you're describing a way to minimize *adjacent* enemy relationships, but this is not what the problem asks at all (although I get how the table setting can be confusing). I think this is the actual problem: http://codeforces.com/problemset/problem/272/E.
Memorat
retrograd
Client obisnuit
**

Karma: 3
Deconectat Deconectat

Mesaje: 50



Vezi Profilul
« Răspunde #5 : Iunie 24, 2015, 17:15:50 »

You are right. I was solving some other problem, for sure  Embarassed
Memorat
loses
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 14



Vezi Profilul
« Răspunde #6 : Iunie 25, 2015, 15:10:40 »

#10 it's simple.
we have a bipartite graph, and then assume that cost(G) is equal to the number of edges that are wrong, that is the same 2 persons are in the same team or w/e

let's say that cost(G) is equal to s Smile
if 1 person is on the left side, and it has 2 enemies, we can move him to the other table or side, and than he has only 1 enemy.
if we do this, we extract from s 2 and then add 1 to it (by moving it in the wrong side)
in this manner we can do this at most 2 * n times or so and at the end of the day we will end with at most 1 enemy for every guy.

maybe we can do better, like cost(G) = 0, but we only need to have at most 1 enemy so this will do it
Memorat
retrograd
Client obisnuit
**

Karma: 3
Deconectat Deconectat

Mesaje: 50



Vezi Profilul
« Răspunde #7 : Iunie 28, 2015, 16:43:14 »

That would be correct, but I don't think scanning the people in linear manner would do the job, as moving vertices around may cause earlier-scanned ones to "break" (for example, maybe you have to move vertex no. 5 to the right table, but doing that will make vertex no. 2 have two enemies at his table). What I am thinking now, if the idea works, is keeping all the people in a MAX-heap sorted by the number of enemies at the same table, and solving the problem in a Dijkstra-like manner (XORing the top's table and updating its enemies' status), until the heap top has a priority less than 2.

However, I am not very certain about why it actually works.
« Ultima modificare: Iunie 28, 2015, 18:41:40 de către Lucian Bicsi » Memorat
Pagini: [1]   În sus
  Imprimă  
 
Schimbă forumul:  

Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines