主题链接:

problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2679

Among grandfather��s papers a bill was found:

72 turkeys $_679_

The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are now illegible.
What are the two faded digits and what was the price of one turkey?

We want to write a program that solves a general version of the above problem:

N turkeys $_XYZ_

The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume
that the first digit is nonzero, that the price of one turkey is an integer number of dollars, and that all the turkeys cost the same price.

Given N, X, Y , and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should
be the most expensive one. That is, the program is to report the two faded digits and the maximum price per turkey for the turkeys.

Input

The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. The first line of each test case contains an integer N (0 < N < 100), which
represents the number of turkeys. In the following line, there are the three decimal digits X, Y , and Z, separated by a space, of the original price $_XYZ_.

Output

For each test case, your program has to do the following. For a test case, there may be more than one candidate for the original price or there is none. In the latter case your program
is to report 0. Otherwise, if there is more than one candidate for the original price, the program is to report the two faded digits and the maximum price per turkey for the turkeys. The following shows sample input and output for three test cases.

Sample Input

3
72
6 7 9
5
2 3 7
78
0 0 5

Sample Output

3 2 511
9 5 18475
0

Source: Asia 2003, Seoul (South Korea)

题意:

给出一个n和一个三位数!

要你在这个三位数的首和尾个加入一个数字!组成五位数!要这个五位数能整除 n ,而且要最大!

PS:

直接for两层,枚举首和尾的数字就可以!首尾不能为0!

代码例如以下:

#include <cstdio>
int main()
{
int t;
int n;
int a, b, c;
int flag;
scanf("%d",&t);
while(t--)
{
flag = 0;
scanf("%d",&n);
scanf("%d%d%d",&a,&b,&c);
for(int i = 9; i > 0; i--)
{
for(int j = 9; j >= 0; j--)
{
int tt = i*10000+a*1000+b*100+c*10+j;
if(tt%n == 0)
{
flag = 1;
printf("%d %d %d\n",i,j,tt/n);
break;
}
}
if(flag)
{
break;
}
}
if(!flag)
printf("0\n");
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

ZOJ 2679 Old Bill(数学)的更多相关文章

  1. ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题

    2679:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1679 2952:http://acm.zju.edu.cn/onli ...

  2. zoj 2679 Old Bill

    Old Bill Time Limit: 2 Seconds      Memory Limit: 65536 KB Among grandfather��s papers a bill was fo ...

  3. ZOJ 1494 Climbing Worm 数学水题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...

  4. zoj.3868.GCD Expectation(数学推导>>容斥原理)

    GCD Expectation Time Limit: 4 Seconds                                     Memory Limit: 262144 KB    ...

  5. ZOJ 3903 Ant(数学,推公示+乘法逆元)

    Ant Time Limit: 1 Second      Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...

  6. ZOJ 3702 Gibonacci number(数学推导)

    公式推导题,G(0) = 1,G(1) = t,给出一个 i 和 G(i),要求求出G(j)的值: G(0) = 0*t + 1 G(1) = 1*t + 0; 观察t的系数和常数值可以知道二者都遵循 ...

  7. zoj 1526 Big Number 数学

    Big Number Time Limit: 10 Seconds      Memory Limit: 32768 KB In many applications very large intege ...

  8. ZOJ 1796 Euchre Results 数学水题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1796 题意: 四个人玩游戏,已知三个人的输赢情况,求第四个人的输赢情况. ...

  9. POJ 2363 Blocks (ZOJ 1910) 数学

    杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...

随机推荐

  1. 流行的Python项目汇总

    年有哪些流行的Python项目呢?下面,我们一起来看下. 一.测试和调试 python_koans :Python Koans 算 “Ruby Koans” 的一部分,作为交互式教程,可以学习 TDD ...

  2. WebFetch 是无依赖极简网页爬取组件

    WebFetch 是无依赖极简网页爬取组件,能在移动设备上运行的微型爬虫. WebFetch 要达到的目标: 没有第三方依赖jar包 减少内存使用 提高CPU利用率 加快网络爬取速度 简洁明了的api ...

  3. Struts2 学习笔记16 struts标签 part2

    接下来说一下if标签.下面是结果图. <li><s:if test="#parameters.age[0]<0">error!</s:if> ...

  4. Unity3D 4.x 使用Mecanim实现动画控制

    Unity3D 4.x 版本号之后提供了一种新的动画机制Mecanim,尽管眼下还支持之前的Animation.但看到Unity3D 4.3 预览版里Sprite的动画也是基于Animator的,可知 ...

  5. Flash键盘钢琴谱

    http://hi.baidu.com/%CC%EC%CA%B9%D2%FE%D2%ED/blog/item/e763d4eac3dcfb242cf53468.html <童话>Flash ...

  6. java--方法和成员的继承,访问

    //在调用方法的时候,不是看句柄是哪一个类,而应该看对象是属于哪一个类的,属于哪一个类的,就调用哪一个类的成员和方法. //子类可以添加自己的新方法,但是子类对象的引用赋值给父类句柄之后,不能使用父类 ...

  7. 07-IOSCore - CoreData补充、音频视频

    xml被plist取代了  数据库被coredata取代了 一.Core Data 高级补充 1. Core Data 本质是什么?操作数据库的数据 ORM Object Relationship M ...

  8. 青云B轮获2000万美元VC的背后逻辑:用技术超越巨头

    http://www.lagou.com/gongsi/31164.html http://capital.chinaventure.com.cn/11/7/1389263145.shtml

  9. 自定义类似QMutexLocker的CMutexLocker

    最近做项目遇到一个需求,有一个buttonSlot()执行要耗点时间,为了防止用户无限制的乱点出现问题,考虑加一个互斥锁,使得每次执行完后才允许执行下一次.大概意思是: //QMutex  m_mut ...

  10. WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的?

    原文:WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的? 服务端只有抛出FaultException异常才能被正常地序列化成Fault消息,并实现向客户 ...