nyoj 64-鸡兔同笼 (解二元一次方程)
2024-09-01 14:04:10
64-鸡兔同笼
内存限制:64MB
时间限制:3000ms
Special Judge: No
accepted:26
submit:58
题目描述:
已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡和兔的数目,如果无解,则输出“No answer”(不要引号)。
输入描述:
第一行输入一个数据a,代表接下来共有几组数据,在接下来的(a<10)
a行里,每行都有一个n和m.(0<m,n<100)
输出描述:
输出鸡兔的个数,或者No answer
样例输入:
复制
2
14 32
10 16
样例输出:
12 2
No answer 分析:
1、解方程,需要判断是否能通过整除得到鸡兔的个数(m-2n)%2
2、判断得到的鸡兔个数是否全部为正数 核心代码:
int flag1 = (m-*n) % , temp1 = (m-*n) / , temp2 = n - temp1;
if (flag1 || temp1 < || temp2 < )
printf("No answer\n");
else
printf("%d %d\n", temp2, temp1);
C/C++代码实现(AC):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <set> using namespace std; int main()
{
int t;
scanf("%d", &t);
while(t --)
{
int n, m;
scanf("%d%d", &n, &m);
int flag1 = (m - *n) % , temp1 = (m - *n) / , temp2 = n - temp1;
if (flag1 || temp2 < || temp1 < )
printf("No answer\n");
else
printf("%d %d\n", temp2, temp1);
}
return ;
}
最新文章
- insmod模块的几种常见错误
- [转载]ASP.NET中TextBox控件设立ReadOnly=";true";后台取不到值
- 【iOS】block的使用
- 说说你所熟知的MSSQL中的substring函数
- Linux使用
- 安装xampp后,遇到的各种问题
- STMPClient 发送邮件显示 不允许使用邮件名称.
- Linux下的sort排序命令详解(二)
- UITabBarController 标签栏控制器
- hadoop集群空间使用情况报告脚本
- Tenacity——Exception Retry 从此无比简单
- Python异常处理总结
- 从无到有-在create-react-app基础上接入react-router、redux-saga
- Vim常用配置
- FAT32格式和NTFS格式区别
- 【推荐】使用Ultrapico Expresso学习正则表达式
- C++ stringstream 简化数据类型转换
- Beautifulsoap - request 网络爬虫 (转)
- Android井字游戏(二)游戏界面
- 数据库连接池使用(一):使用C#数据库连接池