Three cups of water

Source: Internet
Author: User

Determines whether a number is an integer: if (A==int (a))

The description gives three cups, varying in size, and only the largest cup of water is filled, the remaining two are empty cups . Three cups of water are poured between each other, and the cups are not identified and can only be calculated according to the volume of the cups given . You are now asked to write a program that outputs the minimum number of times that the initial state reaches the target State .

Input
The
first line an integer n (0<n<50) represents the n set of test data
Next, each set of test data has two lines, the first line gives three integers V1 V2 V3 (v1>v2>v3 v1<100 v3>0) represents the volume of three cups.
The second line gives three integers E1 E2 E3 (volume less than equal to the corresponding Cup volume) represents the final state we need
Output
each row outputs the minimum number of water pours for the corresponding test data. If the target status output is not reached-1
Sample input
26 3 14 1 19 3 27 1 1
Sample output
3-1

First: output n for loop output three cups a[0],b[0],d[0] open to 50//or record output with a[]
Second: The premise: v1=e1+e2+e3 (according to this equation V1 known if E2 and E3 can meet E1 will be able to find out)!!!
The final state of the V3 can only be full or empty.
The final state of the V2 is either full or V3 multiples or empty (full itself is also a multiple of V3)//But when full, consider different methods.
The final state of the V1 is full or empty or!!!!!!! The wrong idea
The right thought: as long as the above situation V1 must be able to achieve the final state!!!!
The third E3 is 0 E2 0 0 times
    E3 is 0  E2 is a multiple of V3 V1 to give V3 a V3 to give V2 multiples times  + 1 times!!!!! Errors such as  5 3 2 and 2 3 0 only once
Correct: v2/v3 is not an integer when calculating multiples n1 from V1 to V3 to V2 to 2xn1 times
V2/v3 is an integer when calculating multiples n2= (v2-e2)/v3 from V1 to V2 to V3 to 2n2 +1 compared to 2n1

E3==v3 e2=0 1 times
E3=v3 E2 is a multiple of V3 V1 give V3 a V3 to V2 fold several times V1 again pour to V3 a multiplier + 2 times/Error
That's right
Misunderstanding: Both directions can be poured from the V3 to V2 can also be poured from the V2 to V3  things to the bidirectional nature

# include<stdio.h>
int main ()
{
int n,i,n1,n2,t,a[50]={0};
int v1,v2,v3,e1,e2,e3;
scanf ("%d", &n);
for (i=0;i<n;i++)
{
scanf ("%d%d%d", &v1,&v2,&v3);
scanf ("%d%d%d", &e1,&e2,&e3);
if (V1==E1+E2+E3)
{
if (e3==0 && e2==0)
{
a[i]=0;
}
else if (e3==v3 && e2==0)
{
A[i]=1;
}
else if (e3==0 && e2*1.0/v3 = = Int (e2*1.0/v3))
{
if (V2*1.0/v3==int (V2*1.0/V3))
{
N1= E2/v3; N2= (V2-E2)/v3
if (N1&GT;N2)
{t=n1;n1=n2;n2=t;}
A[I]=N1;
}
Else
{
A[i]=e2*1.0/v3 +1;
}
}
else if (E3 ==v3 && e2*1.0/v3 = = Int (e2*1.0/v3))
{

if (V2*1.0/v3==int (V2*1.0/V3))
{
N1= E2/v3; N2= (V2-E2)/v3
if (N1&GT;N2)
{t=n1;n1=n2;n2=t;}
A[I]=N1;
}
Else
{
A[i]=e2*1.0/v3 +2;
}

}

Else
{
A[i]=-1;
}
}
Else
A[i]=-1;
}
for (i=0;i<n;i++)
{
printf ("%d\n", A[i]);
}
return 0;
}

Three cups of water

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.