223. Chicken_Rabbit

题目描述

已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡的数目和兔的数目。题目保证有解。

解答要求时间限制:1000ms, 内存限制:100MB
输入

一行有两个整数n, m(1 <= n <= 10^5, 1 <= m <= 10^7)。

输出

鸡的数目和兔的数目,用一个空格分开,以回车结尾,末尾不要输出多余的空格。

样例

输入样例 1 复制

14 32

输出样例 1

12 2
提示样例 1
 


思路:设鸡有a只,兔有b只,则a + b = n, 2a + 4b = m, 求得 a = (4n - m) / 2, b = n - a。
代码:
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.

int main()
{
    // please define the C input here. For example: int n; scanf("%d",&n);
    // please finish the function body here. 
    // please define the C output here. For example: printf("%d
",a);    
    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d %d
",(4*n-m)/2,n-(4*n-m)/2);
    return 0;
}
以大多数人努力程度之低,根本轮不到去拼天赋~
原文地址:https://www.cnblogs.com/gcter/p/15470532.html