Bharath,
Here is the 'C' source code. Thanks much. How much were you able to solve.
Kindly chk the logic, and let me know where i would have went wrong.
Thanks much,
Robin.
On Tue, May 10, 2011 at 10:57 PM, Bharath Raghavendran <[email protected]
> wrote:
> @robin,
>
> your answer seems wrong for many of the cases. Would it be possible to
> show the program so that we can figure out where the mistake might be?
> For example, Case #5, i am getting 9946662
>
> Here is the code I had written ... just in case ..
> http://pastebin.com/C1muXM9U
>
> On 10 May 2011 20:19, Umer Farooq <[email protected]> wrote:
> > For practice questions, does everyone receive same input ? Or do they
> give
> > different input files every time you download an input set??
> >
> > On Tue, May 10, 2011 at 7:43 PM, robin john <[email protected]> wrote:
> >>
> >> Hello,
> >> Kindly try with this input sample. Also attached the output.
> >> Shall wait for your reply. I really would like to know, have also
> attached
> >> the 'C' source code. Please try and let me know if the output is
> different.
> >> Regards, Robin.
> >>
> >> On Mon, May 9, 2011 at 10:22 PM, Paul Smith <[email protected]>
> >> wrote:
> >>>
> >>> Everyone gets different inputs I think, so you probably need to post
> >>> the input as well as the output.
> >>>
> >>> In fact the easiest thing to do is download someone else's answer, run
> >>> their answer, run your answer, and compare for differences.
> >>>
> >>> Paul Smith
> >>>
> >>> [email protected]
> >>>
> >>>
> >>>
> >>> On Mon, May 9, 2011 at 3:16 PM, robin john <[email protected]>
> wrote:
> >>> > Hello
> >>> > Can anybody kindly upload prob C output or let me know how my output
> is
> >>> > wrong ?
> >>> > Am sure my logic is right. [Comparing xor's of the 2 divided group
> such
> >>> > that
> >>> > they are same and printing highest such possible sum as value]
> >>> > Reg, robin.
> >>> >
> >>> > On Sun, May 8, 2011 at 12:50 PM, vivek dhiman <
> [email protected]>
> >>> > wrote:
> >>> >>
> >>> >> Lucky!
> >>> >>
> >>> >> You are right.
> >>> >>
> >>> >> if xor of two lists is same. (say xor1 = xo2)
> >>> >>
> >>> >> So the exor of these two wil be 0 (xor (xor1,xor2) = 0)
> >>> >> Or in other words lists can be divided if the xor of all the
> elements
> >>> >> is
> >>> >> zero.
> >>> >>
> >>> >> :)
> >>> >>
> >>> >>
> >>> >>
> >>> >> On Sun, May 8, 2011 at 8:17 AM, keshav agarwal <[email protected]
> >
> >>> >> wrote:
> >>> >>>
> >>> >>> please tell me of my logic was correct or i just got lucky to get
> it
> >>> >>> correct
> >>> >>>
> >>> >>> if xor to a list of nos. is zero only then the division is possible
> >>> >>> in this case patrick can be given the one candy with lowest value
> >>> >>> while
> >>> >>> sean keeps the rest
> >>> >>>
> >>> >>> if xor(n nos.)=0
> >>> >>> then (nth no.) xor (xor of n-1 nos.)=0
> >>> >>>
> >>> >>> so patrick gets the nth candy and sean keeps the rest
> >>> >>>
> >>> >>> --
> >>> >>> You received this message because you are subscribed to the Google
> >>> >>> Groups
> >>> >>> "google-codejam" group.
> >>> >>> To post to this group, send email to [email protected].
> >>> >>> To unsubscribe from this group, send email to
> >>> >>> [email protected].
> >>> >>> For more options, visit this group at
> >>> >>> http://groups.google.com/group/google-code?hl=en.
> >>> >>
> >>> >>
> >>> >>
> >>> >> --
> >>> >> Regards
> >>> >> Vivek Dhiman
> >>> >>
> >>> >> --
> >>> >> You received this message because you are subscribed to the Google
> >>> >> Groups
> >>> >> "google-codejam" group.
> >>> >> To post to this group, send email to [email protected].
> >>> >> To unsubscribe from this group, send email to
> >>> >> [email protected].
> >>> >> For more options, visit this group at
> >>> >> http://groups.google.com/group/google-code?hl=en.
> >>> >
> >>> > --
> >>> > You received this message because you are subscribed to the Google
> >>> > Groups
> >>> > "google-codejam" group.
> >>> > To post to this group, send email to [email protected].
> >>> > To unsubscribe from this group, send email to
> >>> > [email protected].
> >>> > For more options, visit this group at
> >>> > http://groups.google.com/group/google-code?hl=en.
> >>> >
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> Groups
> >>> "google-codejam" group.
> >>> To post to this group, send email to [email protected].
> >>> To unsubscribe from this group, send email to
> >>> [email protected].
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/google-code?hl=en.
> >>>
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "google-codejam" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected].
> >> For more options, visit this group at
> >> http://groups.google.com/group/google-code?hl=en.
> >
> >
> >
> > --
> > Umer
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-codejam" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> > http://groups.google.com/group/google-code?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.
//#include "InsertionSort.h"
//#include "queue.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//#if 0
// int a[] = {10,4,2,45,6,34,25};
// int count = 7;
// printf("Before InsertionSort, ");
// for(int i =0; i<7; i++)
// printf("%d ", a[i]);
// printf("\n");
// insort(a,count);
// printf("After InsertionSort, ");
// for(int i =0; i<7; i++)
// printf("%d ", a[i]);
// printf("\n");
FILE *fp = fopen("InputC.txt", "r");
FILE *fp2 = fopen("Output", "w");
if (fp == NULL)
printf("Couldn't open file");
int testcases; int number, total;int max=0; int xorvalue;
char *line, *scanned_line;
line = (char *)malloc(sizeof(char)*10000);
scanned_line = (char *)malloc(sizeof(char)*10000);
if(fgets(line, 10000, fp) != NULL)
{
sscanf(line, "%d", &testcases);
// printf("line -> %s\n",line);
}
printf("%d testcases\n",testcases);
int pairs, pairscopy; char *token, *saveptr;int color;
// queue q;
int *ptr = (int *)malloc(sizeof(int)*1000);
// init_q(&q);
for(int i=0; i<testcases; i++)
{
max = 0;total = 0;
if(fgets(line, 10000, fp) != NULL)
{
sscanf(line, "%d", &pairs);
printf("pairs = %d\n", pairs);
}
if(fgets(line, 10000, fp) != NULL)
{
scanned_line = line;
ptr = (int *)realloc(ptr,sizeof(int)*pairs);
int j=0; pairscopy = pairs;
while(pairs > 0)
{
if(token == NULL) break;
token = strtok_r(scanned_line, " ", &saveptr);
scanned_line = NULL;
// printf("token -> %s ", token);
color = atoi(token);
*(ptr+j) = color;
// enqueue(&q, color);
// printf("color = %d\n", color);
if(pairs == pairscopy) xorvalue = ptr[j];
else xorvalue = xorvalue xor ptr[j];
pairs = pairs - 1; total = total + ptr[j]; j = j + 1;
}
printf("total = %d xorvalue = %d ",total, xorvalue);
}
// while(q.count)
// printf("%d ", dequeue(&q));
vector<vector<int> > combinations;
int n = pairscopy; int *numbers = new int[n];
for( int i = 1; i <= pairscopy; i++ )
numbers[i - 1] = ptr[i-1];
for( int len = 1; len <= pairscopy; len++ ) {
//create index array, l
int *l = new int[len];
for( int _ = 0; _ < len; _++ )
l[_] = len - 1 - _;
while( l[0] < pairscopy ) {
vector<int> comb;
for( int _ = 0; _ < len; _++ )
comb.push_back( numbers[l[_]] );
combinations.push_back(comb);
//iterate l
for( int _ = 0; _ < len; _++ ) {
l[_]++;
if( l[_] < pairscopy )
break;
if( _ < len - 1 )
l[_] = l[_ + 1] + 2;
}
}
delete l;
}
int curr_total; int curr_xorvalue = xorvalue;int subtotal;
//print combinations and check max value satisfying condition
for( int a = 0; a < combinations.size() ; a++ ) {
subtotal = 0; curr_xorvalue = xorvalue;
for( int b = 0; b < combinations[a].size() ; b++ ) {
cout << combinations[a][b] << ' ';
curr_xorvalue = curr_xorvalue xor combinations[a][b];
// curr_total = curr_total + combinations[a][b];
curr_total = curr_xorvalue + xorvalue;
subtotal += combinations[a][b];
}
if(curr_total == curr_xorvalue && subtotal != total)
{
if(subtotal > max) { max = subtotal;}
}
printf("max = %d,xor = %d, total = %d \n",max, curr_xorvalue, curr_total);
}
//output file writing
if(max !=0) fprintf(fp2, "%s%d%s%d\n","Case #", i+1,": ",max);
else fprintf(fp2, "%s%d%s%s\n","Case #", i+1,": ","NO");
delete numbers;
}
free(line); free(scanned_line);
free(ptr);
fclose(fp2); fclose(fp);
return 0;
//#endif
}