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 ;
}

最新文章

  1. insmod模块的几种常见错误
  2. [转载]ASP.NET中TextBox控件设立ReadOnly=&quot;true&quot;后台取不到值
  3. 【iOS】block的使用
  4. 说说你所熟知的MSSQL中的substring函数
  5. Linux使用
  6. 安装xampp后,遇到的各种问题
  7. STMPClient 发送邮件显示 不允许使用邮件名称.
  8. Linux下的sort排序命令详解(二)
  9. UITabBarController 标签栏控制器
  10. hadoop集群空间使用情况报告脚本
  11. Tenacity——Exception Retry 从此无比简单
  12. Python异常处理总结
  13. 从无到有-在create-react-app基础上接入react-router、redux-saga
  14. Vim常用配置
  15. FAT32格式和NTFS格式区别
  16. 【推荐】使用Ultrapico Expresso学习正则表达式
  17. C++ stringstream 简化数据类型转换
  18. Beautifulsoap - request 网络爬虫 (转)
  19. Android井字游戏(二)游戏界面
  20. 数据库连接池使用(一):使用C#数据库连接池

热门文章

  1. Halcon一日一练:获取图像属性
  2. std::shared_future/future
  3. php函数分为哪两种?
  4. Ubuntu 16.04下配置 Nginx 与 Node.js 以及服务的部署
  5. linux 中 NTP 对时过程记录
  6. .NET 任务调度 ,基于Quartz.Net
  7. Java IO编程——File文件操作类
  8. 史上最详细的IDEA优雅整合Maven+SSM框架(详细思路+附带源码)
  9. vue 请求图片方法
  10. 怎样通过excel录入来批量造数据