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) 数学
杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...
随机推荐
- 3DShader之投影贴图(Projective Texturing)
相信大家都应该玩过CS或者CF吧,游戏里面有个喷图功能,就是按一个T键就能在墙上或者地板上喷出自己预先设定的图案. 而刚好这就是我们这个Shader所需实现的内容.由于没有潜伏者的贴图,我只有从这个图 ...
- (csdn高校俱乐部编程挑战)2的补码
题目详情 在计算机中,整数是以2的补码的形式给出的. 给出整数A和B,如果计算机是32位机.求从A到B之间的全部二进制数中,一共用了多少个1. 输入格式: 多组数据,每组数据一行,由两个整数A,B, ...
- c-大量经典的c算法---ShinePans
经典的100个c算法 算法 题目:古典问题:有一对兔子.从出生后第3个月起每一个月都生一对兔子.小兔 子长到第三个月后每一个月又生一对兔子,假如兔子都不死,问每一个月的兔子总数 为多少? _____ ...
- Android模拟器的文件目录介绍
文件存放在 .avd文件夹下 .ini为对应的配置文件 打开.avd文件夹 *.lock文件夹保存的是模拟器的一下数据,当模拟器正常关闭时这些文件夹都会被自动删除. 当模拟器无法开启的时候可以 ...
- CheckBoxList控件
主要介绍:自定义数据.绑定数据库数据.全选,取消全选. 这种方法是绑定已经给定(自定义)的字段(这种方法是绑定给定的值,就是在编写控件时给Text赋的值): 前台代码: <asp:CheckBo ...
- 关于QT的系统总结(非常全面,非常好)
源地址:http://www.cnblogs.com/wangqiguo/p/4625611.html 阅读目录 编译环境与开发流程 QT项目的构成及原理 QT中的布局 QT中的通用控件 QVaria ...
- mysql 表级锁
表级锁:分为读锁和写锁: lock tables table_name read;//其他事务只能读,不能加写锁,要等待更新. SESSION 50 执行: mysql> update test ...
- 基于visual Studio2013解决C语言竞赛题之0907删除记录
题目
- 物理Data Guard主备切换步骤
物理Data Guard角色转换步骤 Step 1 验证主库是否能执行角色转换到备库(原主库执行) SQL> SELECT SWITCHOVER_STATUS FROM V$DATAB ...
- TCP拥塞控制算法内核实现剖析(十)
内核版本:3.2.12 主要源文件:linux-3.2.12/ net/ ipv4/ tcp_veno.c 主要内容:Veno的原理和实现 Author:zhangskd @ csdn blog 概要 ...