Multi-solution to the same cage problem of chicken and rabbit
I still remember that there was a question about the cage of chicken and rabbit in a running male, saying that the chicken and rabbit were in the same cage, with a total of 35 heads and 94 legs. How many chickens were there? How many rabbits are there?
Today, I want to use the recently learned java k
Content: Total number of heads in the same cage, total number of feet, and how many rabbits
Input description:
Two integers in one row represent the total number of headers and feet respectively (ensure that there is a solution, of course, it may be solved as 0)
Output description:
One row and two integers indicate the numbers of chickens and rabbits. Example: if the question is not specified, read the data in multiple groups or refer to a001.
Tags: style blog Io color OS for SP strong data Chicken and rabbit cage
Description
The total number of chickens and rabbits is n and the total number of legs is M. Input N and M, and output the numbers of chickens and rabbits in sequence. If there is no solution, output "No answer" (do not quote the quotation marks ).
Input
Input a data in the first row indicates that there are several groups of data in the next row. In th
C # calculate the total number of chickens and rabbits in the same cage, the total number of feet is x, and how many chickens and rabbits are each ?,
Question: Chicken and rabbit are in the same cage. It is known that the total number of chickens and rabbits is y, and the total number of feet is x. How many chickens and rabbits are there?Solution 1:
1 static void Main (string [] args) 2 {3 for (int ji = 1
Title: Portal.Test instructions: The plane hasNPoint and ask if there are four points(A,B,C,D)(AB , C D , A ≠ C o R B ≠ D) make ab The absolute value of the horizontal ordinate difference and equals The absolute value of the horizontal ordinate difference of the CD and , n, the coordinates of the point m . The problem: The complexity of the surface is O (n^2) will time out, and in fact these coordinate difference absolute value and maximum is
Title: Total number of chickens and rabbits: N, total number of legs: M. input n,m, output the number of chickens and rabbits respectively; no solution output "no answer"Sample Output 1:14 32Sample Output 1:12 2Sample Input 2:10 16Sample Output 2:No AnswerFirst, declare two variables n,m corresponding total and total leg number, and then declare two variables for the number of chickens and rabbits each, a, b1 int n,m,a,b;Input n,m:scanf ("%d%d", n,m);Through simultaneous equations:A+b=n2a+4b=mHa
Import Java.util.Scanner;public class Jitutonglong{static int j,t;public static int Qiongju (int head,int foot){int re,x,y;re=0;for (x=0;x{Y=head-x;if (x*2+y*4==foot){re=1;J=x;T=y;}}return re;}public static void Main (String args[]){int re,head,foot;System.out.println ("Poor lifting method for chicken and rabbit cage Problem:");System.out.println ("Please enter the number of heads:");Scanner input=new Scanner (system.in);Head=input.nextint ();System.o
Article title: Linux running Java services in security settings -- build a safe cage for Tomcat. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Linux and Java platforms have a long history but often experience twists and turns. While building high-performance virtual machines, we must keep up with the increasi
The total number of chickens and rabbits is known to be n and the total number of legs is m. Enter N and M, and in turn output the number of chickens and the number of rabbits. If there is no solution, the output is no answer. Sample input: 14 32 Sample output: 12 2 Sample input: 10 16 Sample output: No answer Package Solve;import Java.util.scanner;public class solve{static Scanner scan = new Scanner (system.in);p ublic static void Main (string[] args) {int n = scan.nextint (), M = Scan.nextin
Question link: Portal
Idea: this is the topic of the concept of pigeon cage... After reading this principle, we can understand it in three ways ..
The number of C representatives, and N represents the number of families ..
[1] First, the prefix and the remainder are required. First, if the remainder is 0, the first N conditions are met, this is a set of feasible solutions...
[2] But what if there is no 0 ?? So let's look at the remainder .. What does
intuition lies in the inherent nature of human beings. Just like the descriptions of human bias raised in the poor Charlie's book, these prejudices actually come from human's natural intuition.
The reason why cool people refer to them as cool people, that is, the constant improvement and expansion of their ideological realm, and the difference between classical physics and modern physics is only within some limits, standing at the peak of classical physics does not mean that modern physics does
Since I bought a monthly ticket to Tianhe park one day, I have been happy to get through it almost every day. Living nearby for several years has never had any feelings for it. In my impression, Tianhe park is a feeling of weeds, few people, and the wind and the grass are low. Now, I seem to be more happy to have a day in the Process of walking to and from work.
In the morning, Tianhe park is full of vigor and various activities are filled with various corners. The walking, tai chi, dancing, si
The chicken and rabbit are in the same cage.AlgorithmDesign Issues. Many people use this question to explain the application of "circular statements" and "exhaustive methods.
Here, I turn to a super-powerful and super-funny "Chicken and rabbit cage" algorithm:
Original post address: http://www.lzhi.org/views/509008
[Algorithm description]
Assuming that chickens and rabbits are well trainedBlow a whistle and they raise one foot (40-15 = 25)Blow
/*describes the total number of chickens and rabbits known to be n and the total number of legs m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks). Enter the first line to enter a data a, representing the next few sets of data, in the next (a*//*2 2 No answer*/#includeintMainintargcConst Char*argv[]) { //Insert code here ... intn,m,flag=0, num; scanf ("%d",num); while(num--) {scanf ("%d%d",n,m); for(intx=0;x -
Describes the total number of chickens and rabbits known to be n and the total number of legs m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks).
Input
The
first line enters a data A, representing the next few sets of data, in the next (a
in line A, each row has an N and M. (0
Output
output the number of chicken rabbits, or no answe
Title AddressDescribe:The total number of chickens and rabbits is known to be n and the total number of legs is m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks).Analysis: The column equation is a two-dimensional array, and the official Code of Excellence simply sets the equation to a simple output.Code:#include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced
In fact, many people have considered such a similar question:
The chickens and rabbits are in the same cage, with 15 heads and 40 feet. How many chickens and rabbits are there?
When I was in elementary school, some children would count like this. If there was one chicken, there would be 14 rabbits, and there would be 58 legs, so there are 13 rabbits and 56 legs ...... And so on until there are 10 chickens, 5 rabbits, and 40 legs. This is a stupid
Title Address: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=64?DescriptionThe total number of chickens and rabbits is known to beN,the total number of legs ism. InputNand them,output the number of chickens and rabbits in turn, and if there is no solution, the output"No Answer" (No quotes). inputThe first line enters a dataA,The next few sets of data are represented in the next(AAline, each row has aNand theM. (0Outputoutput the number of chicken rabbits, orNo AnswerSample Input214 3210 16
The main idea is to solve the problem.
# Include # include # include # include # include # include using namespace STD; int main () {int N; CIN> N; while (n --) {int num_elements, num_foot; CIN> num_elements> num_foot; double ans_rabbit =
Link: HuangJing
Idea: I think like this. If you think of candy of other colors as a baffle plate, there will be n too, then you can form N + 1 positions, so if n + 1 is greater than the largest sugar fruit tree, you can eat all the different sweets,
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.