Hdu 5109 Alexandra and A*B Problem(枚举)
来源:互联网 发布:mac网游排行榜 编辑:程序博客网 时间:2024/05/16 09:06
题目链接
Alexandra and A*B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 563 Accepted Submission(s): 136
Problem Description
Alexandra has a little brother. He is new to programming. One day he is solving the following problem: Given two positive integers A and B, output A*B.
This problem is even easier than the last one. Alexandra can't wait to give him another task: Given a positive integer A and a string S(S only contains numbers.), find the minimum positive integer B, such that S is a substring of T, where T is the decimal notation of A*B.
See the sample for better understanding.
Note: S can contain leading zeros, but T can't.
This problem is even easier than the last one. Alexandra can't wait to give him another task: Given a positive integer A and a string S(S only contains numbers.), find the minimum positive integer B, such that S is a substring of T, where T is the decimal notation of A*B.
See the sample for better understanding.
Note: S can contain leading zeros, but T can't.
Input
There are multiple test cases (no more than 500). Each case contains a positive integer A and a string S.
A<=10,000,1<=|S|<=8 .
Output
For each case, output the required B. It is guaranteed that such B always exists.
To C++ programmers: if you want to output 64-bit integers, please use "%I64d" specifier or cout.
To C++ programmers: if you want to output 64-bit integers, please use "%I64d" specifier or cout.
Sample Input
6 896 192 00861 1
Sample Output
3250431
Source
BestCoder Round #19
题意:已知数字a,有数字构成的字符串s。求最小的b,使得T=a*b,且s为T的字串。
题解:T一定为 xsy 的模式,设y的长度为p,s的长度为ls,那么((x*10^ls+s)*10^p+y)%a==0
当p确定的情况下,我们可以枚举x,计算出y,若y<10^p,则符合要求,而x的枚举范围是<=a的,p<=5。所以我们可以枚举p,再枚举x即可。
代码如下:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<string>#include<queue>#include<stack>#include<map>#include<set>#include<stdlib.h>#include<vector>#define inff 0x3fffffff#define nn 6100#define mod 1000000007typedef long long LL;const LL inf64=inff*(LL)inff;using namespace std;int a;char s[10];LL po[20];int main(){ int i,j; po[0]=1; for(i=1;i<=10;i++) po[i]=po[i-1]*10; LL ix,k; while(scanf("%d%s",&a,s)!=EOF) { int ls=strlen(s); LL fc=0; for(i=0;i<ls;i++) { fc=fc*10+s[i]-'0'; } LL ans=inf64; j=0; if(s[0]=='0') j=1; for(;j<=a;j++) { for(i=0;i<=5;i++) { ix=(j*po[ls]+fc)*po[i]; k=ix/a; if(ix%a) k++; if(k*a-ix<po[i]) { ans=min(ans,k); } } } printf("%I64d\n",ans); } return 0;}
0 0
- Hdu 5109 Alexandra and A*B Problem(枚举)
- HDU 5109 Alexandra and A*B Problem
- hdu 5109 Alexandra and A*B Problem
- hdu 5109 Alexandra and A*B Problem
- hdu 5109 Alexandra and A*B Problem(取模,枚举,数学数论)
- 【BestCoder】 HDOJ 5109 Alexandra and A*B Problem
- HDU5109 Alexandra and A*B Problem(数学题)
- hdu 3819 A and B problem
- HDU-3819-A and B Problem
- HDU 3819 A and B Problem
- hdu A + B problem
- HDU 3819 A and B Problem 对字符串进行处理
- HDUOJAlexandra and A*B Problem
- 【CUGBACM15级BC第19场 A】hdu 5108 Alexandra and Prime Numbers
- HDU-#5108 Alexandra and Prime Numbers
- hdu 5110 Alexandra and COS 压线飘过
- 【HDU】5110 Alexandra and COS 分块处理
- HDU 5108 Alexandra and Prime Numbers
- hdu play on words
- 两种强连通分量算法——tarjan和kosaraju
- 纯CSS画的基本图形(矩形、圆形、三角形、多边形、爱心、八卦等),里面很多涉及到CSS3的一些属性。
- HDU 4465 Candy(组合+log优化)
- 视频2.0时代的到来-美国云视链即将登陆中国
- Hdu 5109 Alexandra and A*B Problem(枚举)
- 已知二叉树的先序(前序)遍历及中序遍历,还原该二叉树并输出其后续遍历
- Java如何连接Access数据库(两种方式实例代码)
- 第二题:设计包含min 函数的栈。
- Spring学习(3)Spring注入的三种方式
- 分析:android.location.Geocoder
- 51nod 1133 不重叠的线段(贪心)
- 下一个7年,我是谁?
- 在ListView的onItemClick里面操作list_item.xml里面的控件