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]
291 - The House Of Santa Claus
Moderator: Board moderators
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
-
- Experienced poster
- Posts: 103
- Joined: Tue Mar 25, 2008 11:00 pm
- Location: IUT-OIC, DHAKA, BANGLADESH
- Contact:
Re: 291 WA
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.
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...............................
It is more tough to become a good person.
I am trying both...............................
Re: 291 WA
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