291 - The House Of Santa Claus

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

eg_frx
New poster
Posts: 21
Joined: Sat Oct 02, 2004 2:17 pm

Post by eg_frx »

What is wrong with my code??????!?!?!?!!!!!!!

My code generates exactly the same result as the 'correct one' above, but got WA!!

Why?!

Grateful for any help! Thanks
[cpp]
#include <iostream>
#include <algorithm>
using namespace std;

void main(){
int route[7] = {2, 3, 1, 5, 3, 4, 5};
int process;

bool edges[21];
do{
edges[2] = 0;
edges[6] = 0;
edges[3] = 0;
edges[15] = 0;
edges[12] = 0;
edges[10] = 0;
edges[5] = 0;
edges[20] = 0;

process = route[0];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[0] * route[1];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[1] * route[2];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[2] * route[3];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[3] * route[4];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[4] * route[5];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[5] * route[6];
if (edges[process])
continue;
else
edges[process] = 1;

process = route[6] * 2;
if (edges[process])
continue;
else
edges[process] = 1;

cout << 1;
for (int i = 0; i < 7; i++)
cout << route;
cout << 2 << endl;

} while (next_permutation(route, route + 7));

}
[/cpp]
eg_frx
New poster
Posts: 21
Joined: Sat Oct 02, 2004 2:17 pm

Post by eg_frx »

help!
Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

malf's post here is a spoiler, REQUESTING MODERATOR'S ATTENTION
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 291 WA

Post by kbr_iut »

if u try to solve it with next_permutation u only have to do two things over each permutation-----

1.check whether it is possible to reach from each element to next element of that permutation or not.
2.check whether one edge overlaps other edge or not.
if u r still getting WA.let me know i will send u the pseudocode over pm.
although,,,better if u solve it with backtrack.
hope it will help.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 291 WA

Post by lnr »

Output from AC code:

Code: Select all

123153452
123154352
123451352
123453152
123513452
123543152
125134532
125135432
125315432
125345132
125431532
125435132
132153452
132154352
132534512
132543512
134512352
134512532
134521532
134523512
134532152
134532512
135123452
135125432
135215432
135234512
135432152
135432512
152134532
152135432
152345312
152354312
153123452
153125432
153213452
153254312
153452132
153452312
154312352
154312532
154321352
154325312
154352132
154352312
Post Reply

Return to “Volume 2 (200-299)”