223. Chicken_Rabbit
题目描述
已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡的数目和兔的数目。题目保证有解。
解答要求时间限制:1000ms, 内存限制:100MB
输入
一行有两个整数n, m(1 <= n <= 10^5, 1 <= m <= 10^7)。
输出
鸡的数目和兔的数目,用一个空格分开,以回车结尾,末尾不要输出多余的空格。
样例
思路:设鸡有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\n",a); int n,m; scanf("%d%d",&n,&m); printf("%d %d\n",(4*n-m)/2,n-(4*n-m)/2); return 0; }
以大多数人努力程度之低,根本轮不到去拼天赋~