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; }
以大多數人努力程度之低,根本輪不到去拼天賦~

浙公網安備 33010602011771號