主题链接:

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. 简单实用的下拉菜单(CSS+jquery)

    原文 简单实用的下拉菜单(CSS+jquery) 没什么可以说的,直接上例子 html+jquery代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  2. 基于visual Studio2013解决C语言竞赛题之0522和为素

     题目

  3. hdu 1528 Card Game Cheater ( 二分图匹配 )

    题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...

  4. 获取java byte的无符号数值

    byte a = (byte)234; System.out.println(a); 上面的代码,结果是-22,因为java中byte是有符号的,byte范围是-128~127. 如果想输出234,该 ...

  5. 分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map

    原文:分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map import java.util.Map; import org.apache.commons.lang.Ar ...

  6. 获取证书以用于 Windows Azure 网站 (WAWS)

    编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 近年来,随着网络犯罪的上升,使用 SSL 保护网站逐渐成为一项备受追捧的功能,Windows A ...

  7. Service的开启和停止以及生命周期

    1.清单文件 <service android:name=".TestService"></service> 2.开启Service Intent inte ...

  8. Flash, Flex, Air, Flashplayer之间的相互关系是什么?

    著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:曾嵘链接:http://www.zhihu.com/question/20001256/answer/15565376来源:知 ...

  9. 动态Pivot(2)

    原文  http://book.51cto.com/art/200710/58875.htm 存储过程sp_pivot的实现包含糟糕的编程习惯和安全隐患.就像我在本章的前面提到的,微软强烈建议不要在用 ...

  10. 基于visual Studio2013解决C语言竞赛题之1028平均值

          题目 解决代码及点评 /* 已知有9个数,请求出这些数中的最大值.最小值及平均值,以及有多少个数等于平均值? */ #include<stdio.h> ...