×

# RECTSQ, am I unable to understand?

 0 https://www.codechef.com/problems/RECTSQ My Code: #include int ans; int finder (int a, int b) { if(b > a) { a += b; b = a-b; a = a-b; } int k = a/b; ans += k; if(a-(k*b)) finder((a-(k*b)),b); else return 0; } int main() { int t; scanf(" %d",&t); while(t--) { int a, b; scanf(" %d%d",&a,&b); ans = 0; finder(a,b); printf("%d\n",ans); } }  I know it is giving output as 3 even for the sample testcases given in the question, while the desired ones are 6 and 6. But I want to ask that if we have to return the minimum number of square plots then why is this incorrect? Take the first case 10, 15 for example, Square 1: 10x10 (5x10 remains from original 10x15) Square 2: 5x5 (5x5 remains from original 5x10) Square 3: 5x5 (Return to main) So Minimum is 3 squares, why is 6 the answer? I think maybe I understood the question wrong, please help. Thank You asked 06 Jun '17, 22:28 1★vehemos 35●6 accept rate: 0% How are you able to ask questions with low karma ? Amazing :D (07 Jun '17, 02:03) Karma requirement to ask Q is just 3, thats why :p (07 Jun '17, 02:49) Okay got it @vijju123 (07 Jun '17, 15:43)

 1 He wants "minimum possible square plots to maximize profits". Bit ambiguous but what the problem asks is, divide the land into minimum number of squares of Same size. so 10 x 15 can be divided into 6 5x5 blocks and 4 x 6 into 6 2x2 blocks I hope i was clear enough, if not feel free to comment. answered 06 Jun '17, 22:43 768●1●8 accept rate: 23% Thanks! :D (06 Jun '17, 23:14) vehemos1★
 1 In all these cases, one reference to some of the AC codes always helps. The problem statement, by all means, is ambiguous because it doesnt state that the squares are of same size. However, if you have a look at few AC codes, you will instantly get what the problem is about. Its always better to give one of the codes a look to see if you can instantly get an answer to your query (because you might have to wait in discuss forums for someone to answer- though you got lucky this time XD) answered 06 Jun '17, 23:14 15.4k●1●20●66 accept rate: 18% 1 I looked at 2 codes one of them had something like a^=b^=c and the other one will win #1 in world obfuscation challenge cuz of its indentation xD Then I gave up on reading others code, but in past whenever I got stuck that's what I used to (and will keep doing :P) (07 Jun '17, 01:52) vehemos1★ Lol hahaha. Sad luck! I got the simplest code possible in first try. Well, on average, it takes around 6-7 tries to get an understandable code. Or, keep track of some good coders and see if one of them solved the question. (07 Jun '17, 02:48)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,646
×9
×4

question asked: 06 Jun '17, 22:28

question was seen: 586 times

last updated: 18 Jan, 19:06