Re: [gcj] Re: Square Dance - WA for Test Set 2

2020-04-15 Thread Edward Lockhart
The suggestion is that you avoid using float at all (because floating point
arithmetic is hard), and instead use integer arithmetic. In this case, you
can do that by not computing the average.

On Wed, 15 Apr 2020 at 16:42, Matt Fenlon  wrote:

> That fixed it! Thank you so much. Out of curiosity, for what reason should
> we avoid float when calculating average?
>
> On Tuesday, April 14, 2020 at 5:41:05 PM UTC-4, porker2008 wrote:
>>
>> I think the problem is related the following line
>>
>> *total += f[i][j] * when[i][j];*
>>
>> Since f[][] and when[][] are both int, the result may be overflowed.
>> Change the line to
>>
>> *total += 1LL * f[i][j] * when[i][j];*
>>
>> would solve the problem.
>>
>> Also for calculating average, try avoid using float number
>> instead you can check whether* sum > f[i][j] * neighbor*
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/0d968845-cebc-43d5-9f49-0daab864018f%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAE-ZSdK1WKPG4cxHf2K9GVtK5AaZxK2t1gSQuSKpJaz0H751wA%40mail.gmail.com.


Re: [gcj] Re: Parenting Partnering Returns

2020-04-13 Thread Edward Lockhart
Did you look at the example I posted?

On Mon, 13 Apr 2020, 17:09 AC,  wrote:

> Hi Matt,
>
> Thanks for the response
> So I revisited the problem after reading the many posts.
> Solution below is working and tested.
> For each case:
> 1. take input
> 2. sort the input , but keep the original order as well
> 3. Loop through sorted task and check if the task is not overlapping in C
> -- assign C at original position, similarly for J. Else: IMPOSSIBLE
> time taken is O(nlogn) for sorting and O(n) for the output generation.
>
> -- My solution during qual round:
> 1. Take input and make list of tasks
> 2. Loop through each task and check if it is conflicting in C (this is a
> loop), else check if it is conflicting in J(this is also loop), Else :
> IMPOSSIBLE
>
> This gives output which passes Sample Case#3: 'CJJCC' but got WA for
> submission.
> Granted the my qual solution is not ideal, hitting O(n^2) but I don't see
> anywhere in problem stating that when allocating task we need to do an
> ascending order.
> Did I miss something in the statement/language ? or am I missing some edge
> case.
>
> PFB the code in qual round(among many variations :) )
> T = int(input())
>
> def is_overlap(num1, num2):
> firstNum, lastNum = None,None
> if num1[0] < num2[0]:
> firstNum = num1
> lastNum = num2
> else:
> firstNum = num2
> lastNum = num1
>
> if lastNum[0] < firstNum[1]:
> return True
>
> return False
>
> for case in range(1,T+1):
> # read N
> N = int(input())
> #read schedules
> schedules = []
> for i in range(N):
> schedules.append(list(map(int,input().split(
>
> C = [[1441,-1]]
> J = [[1441,-1]]
>
> output = []
> count = 0
> flag = 'J'
> for task in schedules:
> #Check for C
> for C_task in C:
> if is_overlap(C_task,task):
> break
> else:
> output += ['C']
> count += 1
> C += [task]
> continue
>
> for J_task in J:
> if is_overlap(J_task,task):
> break
> else:
> output += ['J']
> J += [task]
> count += 1
>
> if count != N:
> output = []
> output = list('IMPOSSIBLE')
>
> print('Case #{}: {}'.format(case,''.join(output)))
>
>
>
>
> On Tuesday, 7 April 2020 13:59:29 UTC-7, Matt Fenlon wrote:
>>
>> Hi Aabhas!
>>
>> Sorting by start time allows us to focus on end times only. When we sort
>> by start time, we can assign activities to Cameron and Jamie in any fashion
>> we choose provided that the start time of the next activity is on or after
>> the end time of the last activity that we assigned to him or her. A simpler
>> example:
>>
>> Hey, Cameron, can you take this 1-5?
>> Sure!
>> How about this 2-4?
>> No, sorry.
>> What about 5-7?
>> Sure!
>>
>> When determining if we can or cannot take an activity, what we are doing
>> is simply checking the 5 in 1-5 against the 2 in 2-4, and the 5 in 1-5
>> against the 5 in 5-7. Easy! Now let's mix it up...
>>
>> Hey, Cameron, can you take this 2-4?
>> Sure!
>> How about this 1-5?
>> ...
>>
>> The output will end up looking the same, but the means in which we get
>> there are a bit more intensive than before. When deciding if we can take
>> the 1-5, we first need to decide if a 1 start time is okay, then we need to
>> determine if a 5 end time is okay. With two activities, the check is
>> relatively simple. With 1000 activities, the check is a bit more
>> challenging as we would need to search our schedule to find the 1-5
>> interval and evaluate end times and start times, and vice versa.
>>
>> Now, when it comes to output, yes, we must give it in the same order in
>> which it was received. When we are reading the input, we can index each
>> event: the first event is 1, the second event is 2, and so on. When we
>> sort, indices stay with the events regardless of where they end up after we
>> have sorted the activities by start time so that, when we have assigned
>> each activity to a partner, we can once again sort on indices. Now,
>> activities are in the proper order, and each activity has an assignment.
>>
>> Does this answer your question?
>>
>> Best,
>> Matt
>>
>> On Tuesday, April 7, 2020 at 12:56:02 PM UTC-4, AC wrote:
>>>
>>> Hi Bhavesh,
>>>
>>> Do we know why are we trying to sort the start time.
>>> Since we do have to put the output in same order as we received it.
>>> Is this a tie breaker condition for multiple solutions?
>>> Can u share the edge cases for this.
>>>
>>> Thanks,
>>>
>>> On Tue, Apr 7, 2020 at 8:51 AM Bhavesh Kumar 
>>> wrote:
>>>
 Yes, I solved in Python. Idea is simple, maintain a list of tuples.
 Each tuple will have three values (start_time, end_time, index). now sort
 the list based on first value. Checkout the code below.

 for t in range(int(input())):
 N = int(input())
 A = []
 for i in 

Re: [gcj] Re: Parenting Partnering Returns

2020-04-10 Thread Edward Lockhart
The greedy approach you're using doesn't handle all cases, eg

0 1
5 6
0 2
1 6


On Fri, 10 Apr 2020, 16:55 rajeswara reddy, 
wrote:

>
> Can anyone find what's wrong in my program for parenting partners returns
> problem
>
> z=int(input())
> for zz in range(1,z+1):
> n=int(input())
> l=[]
> out='C'
> for i in range(n):
> t=list(map(int,input().split()))
> l.append(t)
> c=set(range(l[0][0],l[0][1]))
> j=set()
> for i in l[1:]:
> t=set(range(i[0],i[1]))
> if len(c.intersection(t))==0:
> out+='C'
> c.update(t)
> elif len(j.intersection(t))==0:
> out+='J'
> j.update(t)
> else:
> out="IMPOSSIBLE"
> break
> print("Case #{}: {}".format(zz,out))
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/6a674140-a6c6-4074-8508-161566cea344%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAE-ZSdL8C%2B0L-RrRSEUWWv5y%3DhQzosBNqvedrb0XqTK_CiBAxA%40mail.gmail.com.


Re: [gcj] Find maximum sum in an array provided that no elements in a combination can have common digits

2019-05-29 Thread Edward Lockhart
You can do it with a single pass through the list, maintaining the maximum
sum with every possible set of permitted digits (1024 values).

On Wed, 29 May 2019, 00:03 akshit bhatia,  wrote:

> Hello,
>
> I know this is not the right community to ask this coding problem, but
> please if possible, would be great if you can suggest me how to solve the
> following problem.
>
> Yesterday, I was asked a question in the interview where I have to make an
> algorithm that will find the maximum sum in a given array such that no
> elements in a combination have any common digits.
>
> For example our array is: 31,44,46,63,65
>
> So we cant add the elements: 31,63 as 3 is common But we can take up the
> elements 44, 65, 31 as none digits are common in these elements and also 65
> > 63.
>
> Can anyone think of a good approach in this?
>
>
> Thanks in advance. And once again I apologise for the off topic here.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/36b7a4e0-e9dc-4af4-8af6-7ebd4542f82c%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAE-ZSdJ4f7Nrq8LZPQ_2gEW1TU7fTA5QiJH5Ld1CnszqZarRVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] 1C 2016 Problem A

2016-05-08 Thread Edward Lockhart
The analysis covers this case. When there's AABB, you have to take 2 out.

On Sunday, 8 May 2016, Eric Mordezki  wrote:

> Could I get some help as to why my algorithm couldn't solve this exercise?
>
> The problem was to figure a way to let people out without having a party
> with +50% of the total amount of people, so my idea was to always let out
> people from the party with the most people. That way the others would never
> have the majority.
>
> As it said one could print any possible evacuation plan and people can
> leave one by one, I figured we could always let people leave one by one
> until there's only two people, because if only one left, the other party
> would have majority, so the last step would always contain 2 people of
> different parties.
>
> Where did I get it wrong?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com .
> To post to this group, send email to google-code@googlegroups.com
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/4efb1178-42c8-410a-946a-3ae6cc787ad3%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAE-ZSdLcKpu7%2BzuACDG3mA%2B5DzQqECimv-KfoxfuEEfai-0%3D2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] I found solution but I can't prove correctness.

2016-03-26 Thread Edward Lockhart
Correct. This is proved in the contest analysis.
https://code.google.com/codejam/contest/32016/dashboard#s=a=0

> On 26 Mar 2016, at 11:33, Seung Youp Oh  wrote:
> 
> https://code.google.com/codejam/contest/32016/dashboard#s=p0
> 
> I'm solving this problem and found a solution but I can't prove my solution's 
> correctness. Is there anyone can prove this?
> 
> My solution is below:
> 
> 1. Sort two vectors. Two vectors becomes (x1, ..., xn), (y1, ..., yn)
> 2. Minimum product is x1 yn + x2 yn-1 + ... + xn y1
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/0b8deb78-0bf9-46c6-a9c4-d20cd8af3ecd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/49EE376F-DF30-4BEA-A2F1-C85249FC9338%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] a Linear Programming approach to problem B of round 2

2015-06-09 Thread Edward Lockhart
Yes - see for example linguo's solution. 
He solved bilingual as an integer linear programming problem too. 

Edward

 On 9 Jun 2015, at 21:09, bigOnion haibren...@gmail.com wrote:
 
 During round 2 I recognized that problem B can be described as a Linear 
 Programming problem.
 
 There are two restrictions:
 R_1 * t_1 + ... + R_n * t_n = V
 C_1 * R_1 * t_1 + ... + C_n * R_n * t_n = V * X
 
 t_1, ..., t_n are all non-negative
 
 Finally the objective is:
 Minimize (max{t_1, ...,  t_n} )
 
 That's quite a regular LP problem.
 
 I know that obviously coding a solution to LP is much harder than the simple 
 analysis of this specific problem. Nevertheless, I was wondering – did anyone 
 tried to solve it this way? I know that LP might need more time to solve. Is 
 it doable in the GCJ time constraints (i.e., does it take less than 8 minutes 
 to get the full output?) Does anyone know?
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Google Code Jam group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-code+unsubscr...@googlegroups.com.
 To post to this group, send email to google-code@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-code/e782962e-7d0e-4fb0-b46d-d39f850e346b%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
Google Code Jam group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CD8F176F-A884-4F52-8CD6-30C1E8BE60D1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Round 1A Problem C Logging: The size of eps

2015-04-19 Thread Edward Lockhart
For any pair of trees, drawing the line connecting them and then clearing all 
trees on one side of the line will put both of them on the boundary. Checking 
all ways to do that is n^3 naively but can be made n^2 log n by sorting the 
trees clockwise around the tree being considered. 

Edward

 On 19 Apr 2015, at 22:21, Paul Smith p...@pollyandpaul.co.uk wrote:
 
 Is the answer to Logging to find the number of triangles made by triples of 
 other trees that each tree is strictly inside?  Sounds very inefficient.  
 Would love to hear some insight on this whilst I wait for the official 
 analysis :)
 
 Paul Smith
 
 p...@pollyandpaul.co.uk
 
 On Sun, Apr 19, 2015 at 11:17 AM, john.smith john.sm...@arrows.demon.co.uk 
 wrote:
 I was largely defeated by this problem. I hacked an awful convex-hull 
 algorithm, and brute-forced a solution to the small test case. I was 
 interested to look at some of the solutions by the best.
 
 Many of the successful solutions calculate angles between trees using 
 floating point arithmetic expressions based on atan(dx,dy), and compare the 
 angles with expressions like
  while ( ...  a[r] - a[i]  M_PI - eps)
 
 How should eps be set to be large enough to account for all rounding errors, 
 and small enough to distinguish distinct angles?
 
 Suppose we have two angles A and B with tan(A) = ax/ay  and tab(B) = bx/by.
 Then when A and B are close, A-B is close to tan(A-B) = (ax/ay-bx/by) / 
 (1+ax.bx/ay.by).
 Simplify to give tan(A-B) = (ax.by-bx.ay)/(ax.bx+ay.by)
 
 In the current question -2N  ax,bx,ay,by  2N where N=100 so by careful 
 choice of ax,ay,bx,by we find the smallest non-zero value of tan(A-B) is 
 about 1/(8.N^2).  So if you set eps to 1e-13, then you should be OK.
 
 Burunduk1 (rank 1) chose eps = 1e-15, so is safe.
 
 Other values used by those ranked in the top 10 include 1e-12, 1e-10 
 (twice), and 1e-8. All appear to be defeated by a test case of the form
 4
 0 0
 99 100
 -98 -99
 -100 100
 
 A little luck is useful. I've certainly had it in the past. But in case the 
 GCJ team start using even more test-cases exploring dark corners, be very 
 careful how you set your eps.
 
 
 --
 You received this message because you are subscribed to the Google Groups 
 Google Code Jam group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-code+unsubscr...@googlegroups.com.
 To post to this group, send email to google-code@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-code/b9f4d273-cef3-4119-8267-a6625265288a%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Google Code Jam group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-code+unsubscr...@googlegroups.com.
 To post to this group, send email to google-code@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-code/CAJej63Ju7pyf2s0RraBBy2H_2JdJG%2BFLmfyV2TUC4p4sTndS_w%40mail.gmail.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
Google Code Jam group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/44C78232-C530-417A-A67C-A0DB0DAEF263%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Please help me with the Small B. Getting wrong.

2015-04-12 Thread Edward Lockhart
Try a single stack of 9 pancakes. 

Edward

 On 12 Apr 2015, at 09:10, utkarsh gupta guptautkarsh2...@gmail.com wrote:
 
 For small B, what I did was to first divide all the maximum sized pancakes to 
 half giving the extra half to empty plates.Now it will be take special 
 minutes equal to the frequency of maximum sized sized pancake.Check if the 
 new maximum sized pancake + the special minutes added is less than your 
 initial ans, update answer if it less. Now again divide the maximum into two 
 add the special minutes required and check if the new maximum  + special 
 minutes is less the your previous ans . Keep doing it until you have divided 
 each pancake such that every pancake is either = 3 ,because for pancake = 
 1,2,3 answer will be same.
 Any help is appreciated. 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Google Code Jam group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-code+unsubscr...@googlegroups.com.
 To post to this group, send email to google-code@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-code/327a0d00-dc6c-4062-900c-d84da294ee6b%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
Google Code Jam group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/837E4793-FD3E-4ED3-BDC8-00A2AACBAA6D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Problem A solution has a bug? Please correct me where I was wrong. Thank you.

2014-10-13 Thread Edward Lockhart
Perhaps you could list the 4 moves which you believe solve the particular case?

Edward

 On 13 Oct 2014, at 18:46, Shenghua Song songsheng...@gmail.com wrote:
 
 I'm new to Google Code Jam. I am very excited and thank you for providing me 
 this opportunity to learn coding from world top programmers.
 
 I were practicing on the “World Finals 2014” website. It seems that I found 
 the solution for “Problem A” has a bug. I submitted my solution and it always 
 shows “incorrect”. Then I compared my solution with the public programs on 
 the  “World Finals 2014” website. For the small practice test cases, the 
 answers were different only on case #1. So I checked manually and thought my 
 solution is correct. The code jam’s answer on the website did not consider 
 the effect like one row swap after one column swap, for the first row and the 
 first column.
 
 Please correct me where I was wrong. Thank you.
 
 Regards,
 Shenghua
 
 
 
 == Start == My Code, Filename: A.c ==
 
 /**
 
 News:
 http://mashable.com/2014/08/15/teen-from-belarus-wins-google-code-jam-on-his-first-try/
 
 Problems:https://code.google.com/codejam/contest/7214486/dashboard#s=p0
 
 Problem A. Checkerboard Matrix
 
 This contest is open for practice. You can try every problem as many times as 
 you like, though we won't keep track of which problems you solve. Read the 
 Quick-Start Guide to get started.
 
 Small input
 4 points
Solve A-small
 Large input
 9 points
Solve A-large
 
 Problem
 
 When she is bored, Mija sometimes likes to play a game with matrices. She 
 tries to transform one matrix into another with the fewest moves. For Mija, 
 one move is swapping any two rows of the matrix or any two columns of the 
 matrix.
 
 Today, Mija has a very special matrix M. M is a 2N by 2N matrix where every 
 entry is either a 0 or a 1. Mija decides to try and transform M into a 
 checkerboard matrix where the entries alternate between 0 and 1 along each 
 row and column. Can you help Mija find the minimum number of moves to 
 transform M into a checkerboard matrix?
 
 Input
 
 The first line of the input gives the number of test cases, T. T test cases 
 follow. Each test case starts with a line containing a single integer: N. The 
 next 2N lines each contain 2N characters which are the rows of M; each 
 character is a 0 or 1.
 
 Output
 
 For each test case, output one line containing Case #x: y, where x is the 
 test case number (starting from 1) and y is the minimum number of row swaps 
 and column swaps required to turn M into a checkerboard matrix. If it is 
 impossible to turn M into a checkerboard matrix, y should be IMPOSSIBLE.
 
 Limits
 
 1 ≤ T ≤ 100.
 
 Small dataset
 
 1 ≤ N ≤ 10.
 
 Large dataset
 
 1 ≤ N ≤ 10^3.
 
 Sample
 
 Input
 
 3
 1
 01
 10
 2
 1001
 0110
 0110
 1001
 1
 00
 00
 
 Output
 
 Case #1: 0
 Case #2: 2
 Case #3: IMPOSSIBLE
 
 In the first sample case, M is already a checkerboard matrix.
 
 In the second sample case, Mija can turn M into a checkerboard matrix by 
 swapping columns 1 and 2 and then swapping rows 1 and 2.
 
 In the third sample case, Mija can never turn M into a checkerboard matrix; 
 it doesn't have enough 1s.
 
 **/
 
 /**
Below is written by S.H.Song
 **/
 
 #ifdef _MSC_VER
 #define _CRT_SECURE_NO_WARNINGS
 #define ___ITOA _itoa
 #else
 #define ___ITOA itoa
 #endif
 
 #include stdio.h
 #include stdlib.h
 #include string.h
 
 #define T 100
 #define N 1000
 
 void process(FILE* fp_in, FILE* fp_out)
 {
if (fp_in == NULL)
return;

char line[2*N+10];

int max_cases = 0;
int case_number, max_lines, line_number;
int already_impossible = 0;
 
char** matrix = (char**) malloc(2*N*sizeof(char*));
matrix[0] = (char*)malloc((2*N)*(2*N));
for (int i=1; i2*N; ++i)
matrix[i] = matrix[i-1] + 2*N;
 
while(1) {
if (fgets(line, 2*N+10, fp_in) == NULL)
break;
 
if (max_cases == 0) {
max_cases = atoi(line);
if (max_cases = 0 || max_cases  T) {
fputs(Input ERROR MaxCases\n, fp_out);
break;
}
case_number = 0;
max_lines = 0;
line_number = 0;
already_impossible = 0;
continue;
}
 
if (max_lines == 0) {
max_lines = atoi(line);
if (max_lines = 0 || max_lines  N) {
fputs(Input ERROR MaxLines\n, fp_out);
break;
}
case_number++;
max_lines *= 2;
line_number = 0;
already_impossible = 0;
continue;
}
 
if ((strlen(line) != max_lines+1)  (strlen(line) != max_lines)) {
fputs(Input ERROR Line\n, fp_out);
break;
}
int value_invalid = 0;
for (int i=0; 

Re: [gcj] Any hint to solve this easy problem

2013-11-15 Thread Edward Lockhart
This general approach will work if you are careful about defining what your 
variables mean. You may find writing explicit loop invariants helpful. 

To progress though, you'll need to switch from direct simulation of this sort 
to analysing the problem with pencil and paper, finding a simpler way to 
compute the solution, and then implementing that. 

I suggest first rewriting the simulation in exactly the terms specified by the 
problem (ie iterating from 1 to n), and getting that to work. Then try to 
replace the simulation code with a single line containing a simple formula. 

Have fun!

Edward

 On 16 Nov 2013, at 05:23, George R amauryvegzavs...@gmail.com wrote:
 
 Hello
 
 I am a beginner in competitive programming, I having a hard time to solve 
 this problem https://icpcarchive.ecs.baylor.edu/external/40/4071.pdf, it is 
 an easy exercise but I am stuck, any hint to solve this problem?
 This is my code so far, I am trying to do the simulation with a while loop 
 but It is not working because sometimes I get the correct answer, can someone 
 guide me? maybe I am totally lost  
 
 import java.io.*;
 class Main2 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new 
 InputStreamReader(System.in));
int t = Integer.parseInt(bf.readLine());
String n = ;
String nameChosen = ;
int gum = 0;

for(int i = 0; i t; i++){
n = bf.readLine();
nameChosen =bf.readLine();;
gum = Integer.parseInt(bf.readLine());
solve(n,nameChosen, gum);
}

}

public static void solve(String arr,String name, int n){
String[] names = arr.split( );
int pos = 0;
for(int j= 0; j names.length;j++){
if(names[j].equals(name)){
pos = j;
}
}
int k = 0;
String nom = ;
System.out.println(pos  + pos);
System.out.println(length  + names.length);

while(n = 0){
if(pos  names.length -1){
pos = 0;
nom = names[pos];
}else{
nom = names[pos];
System.out.println(nom  + nom);
pos++;
}
n--;
}
System.out.println(nom);
}
 }
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Google Code Jam group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-code+unsubscr...@googlegroups.com.
 To post to this group, send email to google-code@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-code/1e6faac2-9f62-4dcc-96fd-99ba065ff99a%40googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
Google Code Jam group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/06185510-07C4-4376-8D2E-23BA03CEB94A%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.