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) 数学
杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...
随机推荐
- WEB开发:如何用js来模拟服务器的ajax响应,不依赖服务器来编写前端代码
一.问题的提出 目前web前端开发,主流的思路是: 1)编写静态的html文件(不使用模板技术,与服务器无关) 2)页面通过ajax与服务器交互,进行数据的传输,数据格式为json格式 这里存在一个问 ...
- c# 数据库编程(通过SqlCommand 执行数据库查询)
前面一篇文章,我们介绍了如何在c#中对数据库进行更新操作.主要是利用SqlCommand 对象的ExecuteNonQuery方法. 这篇文章介绍,如何进行查询操作.本文给出的例子仍然是针对sql s ...
- linux stat系统调用,获取文件信息。
stat 函数原型: int stat(const char *path, struct stat *buf); struct stat 说明 struct stat { mode_t st_mode ...
- typedef和define
typedef int INT; #define INTPTR1 (int*) typedef是用来声明类型别名的,在实际编写代码过程使用typedef往往是为了增加代码的可读性. #define是一 ...
- Java --CountDownLatch简介
CountDownLatch 1.类介绍 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.用给定的计数 初始化 CountDownLatch.由于调用了 coun ...
- 基于visual Studio2013解决C语言竞赛题之1008整除数
题目 解决代码及点评 /************************************************************************/ ...
- android开发1:安卓开发环境搭建(eclipse+jdk+sdk)
计划折腾折腾安卓开发了,从0开始的确很痛苦,不过相信上手应该也不会太慢.哈哈 一.Android简介 Android 是基于Linux内核的软件平台和操作系统. Android构架主要由3部分组成,l ...
- c语言,数组和字符串
1. “数组名代表了数组的存储首地址,是一个地址常量”. 对于char *p1 = "A String."; 和 char p2[] = "Another String. ...
- Goodle Clean设计架构
Goodle Clean设计架构 23 * @param <P> the response type 24 */ 25 public abstract class UseCase<Q ...
- Windows窗体透明效果
虚拟机里的win7也想实现透明效果, 使用vitrite这个免费软件就可以了.