ZOJ 2679 Old Bill(数学)
主题链接: 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(数学)的更多相关文章
- 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 ...
- zoj 2679 Old Bill
Old Bill Time Limit: 2 Seconds Memory Limit: 65536 KB Among grandfather��s papers a bill was fo ...
- ZOJ 1494 Climbing Worm 数学水题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...
- zoj.3868.GCD Expectation(数学推导>>容斥原理)
GCD Expectation Time Limit: 4 Seconds Memory Limit: 262144 KB ...
- ZOJ 3903 Ant(数学,推公示+乘法逆元)
Ant Time Limit: 1 Second Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...
- 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的系数和常数值可以知道二者都遵循 ...
- zoj 1526 Big Number 数学
Big Number Time Limit: 10 Seconds Memory Limit: 32768 KB In many applications very large intege ...
- ZOJ 1796 Euchre Results 数学水题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1796 题意: 四个人玩游戏,已知三个人的输赢情况,求第四个人的输赢情况. ...
- POJ 2363 Blocks (ZOJ 1910) 数学
杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...
随机推荐
- eclipse中build workspace的相关优化
网上流传的各种的eclipse的调优的方法都大同小异,但是调优的基本上针对eclipse或者myclipse的本身,比如关掉validate和启动项,文件拼写,和自动构建等,调过之后,等个eclips ...
- c语言中scanf()、printf()函数
函数调用scanf(“%d”, &weight) 包含两个参数:“%d” 和&weight.C用逗号来隔开函数调用中的多个参数: 但是printf()和scanf()函数比较特殊,其 ...
- Windows VS下搭建cocos2d-x环境搭建
VS2010以上版本(eg:VS2012/VS2013,这里本人用VS2013) 1.环境.安装包准备 2.python安装 3.cocos2d-x安装包解压安装 4.环境变量配置 5.执行setup ...
- Hibernate 多对多映射
package com.entity.manytomany; import java.util.List; import javax.persistence.Entity; import javax. ...
- JVM --java 字节码的结构解析
Java字节码文件的主体结构分为一下几个部分:Class文件头部.常量池区域.当前类的描述信息.字段列表.方法列表.属性列表. Class文件头部 任何的class文件的前四个字节的内容就是CA FE ...
- Savitzky-Golay滤波器(2)
前几天写过一篇介绍 Savitzky-Golay滤波器的文章, 没想到最近做项目还真的用上了. 因此就顺便写了个 C 语言的自动计算生成 SG 滤波器系数的程序.利用这里的代码可以生成任意阶数的 SG ...
- 创建用于编译和运行Java程序的批处理文件
创建用于编译和运行Java程序的批处理文件 每次编译或运行Java程序时,都要在DOS命令行中输入很长的javac或java命令,悟空觉得太麻烦,就编写了一个适用于Windows操作系统的批处理文件b ...
- 在开发 ExtJS 应用程序常犯的 10 个错误
这是 CNX 公司在开发 ExtJS 项目中总结的需要特别注意的 10 个地方.有时候,我们完全是自己使用 ExtJS 从零开始构建的新的应用程序,但有时候我们的客户会要求我们使用他们自己的代码,并且 ...
- Bee Framework_百度百科
Bee Framework_百度百科 Bee Framework 编辑 目录 1详细信息 简介 特性 2工作 主要模块 编译要求 运行要求 目录结构 运行例程 安装步骤 1详细信息 简介 ...
- Linux下可执行程序调试信息的分离及release程序的调试
前两天在群里看到在讨论如何把debug版中的符号表加到release版本中,觉得这个非常有用,所以学习一下. 使用的工具是objcopy. 如果要生成单独的调试信息文件,命令如下: objcopy ...