CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Icoder 2010 » Aqualoo Plants

Aqualoo Plants

Problem code: ICODER3

  • All Submissions

All submissions for this problem are available.

A rectangular garden is divided into square shaped cells where each cell consists of a plant. Some plants depending upon their nature need more water than others and some may not require water at all. Invisible water taps keep teleporting around the garden. Each water tap gives water to a plant for a constant time and then teleports to another( or reappears in the same cell ) to give water to another plant( or the same plant ). To simplify the structure, each water tap moves with respect to a base cell, Row offset set and a Column offset set and keeps repeating through the set. For example:

Consider a 6 X 6 size rectangle:

Therefore,

Total Rows = 6
Total Columns = 6
Total cells = Total plants = 36

Now consider a tap with following properties

1. Base cell: 0
2. Row Offset Set: 0 1 2 0 0
3. Column Offset Set: 1 0 0 1 2

The cell numbers for the garden in this case will be:

0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
18 19 20 21 22 23
24 25 26 27 28 29
30 31 32 33 34 35

This means the tap starts with giving water to cell '1'( Row offset 0, column offset 1 with respect to cell '0' i.e. the base cell ) and then moves to cells 6 -> 12 -> 1 -> 2. The new cell position is with respect to the base cell, the current row and column offset and has got nothing to do with the previous cell positions where water tap was teleported. Also note that the tap would continuously move in the following order 1->6->12->1->2->1->6->12... and so on.

All the water taps are synchronised i.e. all of them change the cells at the same time, give water for the same amount of time and so on. Consequently, there may be such plants, which at some time instant get water from every tap in the garden. These plants are called Aqualoo plants.

Now given the taps and their respective base cell, row offset set and column offset set, you have to give out the total Aqualoo plants in the garden.

Notes
- Remember that for the plant to be Aqualoo, every tap in the garden should water this plant at same time instant.
- Every tap may or may not have a different base cell, row offset and column offset.

Input

1. Number of test cases = 'T' ( 1 <= T <= 300 )
2. For each test case, first line of input contains number of rows = 'R', followed by number of columns = 'C' and total number of water taps = 'N' ( 1 <= R <= 50, 1 <= C <= 50, 1 <= N <= 6 ).
3. For each tap, first line of input contains base cell number = 'B', followed by length of the row offset set and column offset set = 'L' ( 0 <= B < R * C, 1 <= L <= 25 ).
4. Next line contains row offset set, where each value lies in range ( -R, +R )( not inclusive ).
5. Next line contains column offset set, where each value lies in range ( -C, +C )( not inclusive ).

Output

1. Each line of output contains total Aqualoo plants

Example

Input:
2

6 6 2
7 1
2
3
35 1
-2
-1

6 6 2
13 4
0 1 1 0
0 1 2 3
4 3
0 1 2
0 0 0

Output:
1
1

Author: csirubix
Date Added: 20-03-2010
Time Limit: 2.5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

I was just testing the

jeetnihalani @ 21 Mar 2010 02:45 PM

I was just testing the problems, my submission won't count. You can post your queries here...

The contest has been extended

jeetnihalani @ 21 Mar 2010 03:07 PM

The contest has been extended up to 6 p.m.

The contest has been extended

jeetnihalani @ 21 Mar 2010 04:32 PM

The contest has been extended up to 8 p.m.

ok one small question....what

abhishek chandiramani @ 21 Mar 2010 10:26 PM

ok one small question....what if the plants urinate....there would be water loss.....how do u explain that in C++

nd ya hw can d plants live in

abhishek chandiramani @ 21 Mar 2010 10:27 PM

nd ya hw can d plants live in cells....we were being taught they survive in soil....Please think before formulating the problem.....

# include <soil.h>

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com