QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 20

#5764. Triangle Areas

الإحصائيات

Problem

Ten-year-old Tangor has just discovered how to compute the area of a triangle. Being a bright boy, he is amazed by how many different ways one can compute the area. He also convinced himself that, if all the points of the triangle have integer coordinates, then the triangle's area is always either an integer or half of an integer! Isn't that nice?

But today Tangor is trying to go in the opposite direction. Instead of taking a triangle and computing its area, he is taking an integer A and trying to draw a triangle of area A/2. He restricts himself to using only the integer points on his graph paper for the triangle's vertices.

More precisely, the sheet of graph paper is divided into an

N by M grid of square cells. The triangle's vertices may only be placed in the corners of those cells. If you imagine a coordinate system on the paper, then these points are of the form (x, y), where x and y are integers such that

0 ≤ xN and

0 ≤ yM.

Given the integer A, help Tangor find three integer points on the sheet of graph paper such that the area of the triangle formed by those points is exactly A/2, if that is possible. In case there is more than one way to do this, any solution will make him happy.

Input

One line containing an integer C, the number of test cases in the input file.

The next C lines will each contain three integers N, M, and A, as described above.

Output

For each test case, output one line. If there is no way to satisfy the condition, output

Case #k: IMPOSSIBLE

where k is the case number, starting from 1. Otherwise, output

Case #k: x1 y1 x2 y2 x3 y3

where k is the case number and (x1, y1), (x2, y2), (x3, y3) are any three integer points on the graph paper that form a triangle of area A/2.

Limits

Time limit: 30 2 seconds per test set.

Memory limit: 1GB.

0 ≤ C ≤ 1000

1 ≤ A ≤ 108

Small dataset (Test set 1 - Visible; 5 Points)

1 ≤ N ≤ 50

1 ≤ M ≤ 50

Large dataset (Test set 2 - Hidden; 15 Points)

1 ≤ N ≤ 10000

1 ≤ M ≤ 10000

Sample

3
1 1 1
1 2 64
10 10 1
Case #1: 0 0 0 1 1 1
Case #2: IMPOSSIBLE
Case #3: 1 1 2 3 5 8
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.