hdu 5109(构造数+对取模的理解程度)
Alexandra and A*B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 802 Accepted Submission(s): 211
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.
A≤10,000,1≤|S|≤8.
To C++ programmers: if you want to output 64-bit integers, please use "%I64d" specifier or cout.
96 19
2 0086
1 1
2
5043
1
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
LL a;
char s[];
while(scanf("%lld%s",&a,s)!=EOF){
int len = strlen(s);
if(strcmp(s,"")==){
printf("0\n");
continue;
}
LL ls = ,mid=;
for(int i=;i<len;i++) ls*=;
for(int i=;i<len;i++){
mid = mid*+s[i]-'';
}
LL ans = -;
for(LL i=;i<=;i*=){
for(LL j=(s[]=='');j<a;j++){
LL t = (j*ls+mid)*i;
LL y = (a-t%a)%a;
if(y>=i) continue;
if(ans<) ans = t+y;
else ans = min(t+y,ans);
}
}
printf("%I64d\n",ans/a);
}
return ;
}
hdu 5109(构造数+对取模的理解程度)的更多相关文章
- hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值
pog loves szh II Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4704 Sum 超大数幂取模
很容易得出答案就是2^(n-1) 但是N暴大,所以不可以直接用幂取模,因为除法操作至少O(len)了,总时间会达到O(len*log(N)) 显然爆的一塌糊涂 套用FZU1759的模板+顺手写一个大数 ...
- W - Doom HDU - 5239 线段树 找取模的规律+求一个很大的数的平方对一个数取模的写法 特别的模数==2^63-2^31
这个题目一开始感觉还是有点难的,这个模数这么大,根本就不知道怎么写,然后去搜了题解,知道了怎么去求当x很大的时候x的平方对一个数取模怎么样不会爆掉. 然后还顺便发现了一个规律就是当一个数更新一定次数之 ...
- HDU 1212 大整数的取模运算
因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...
- C#取模的理解:为什么当a<b,a%b=a?
一,取模a%b 1,如果a>b,例如10%7=3,这是什么原因呢?可以根据下面的理解 10 =7*1+3,则模就是3 2,如果a<b,例如7%10 = 7,这时怎么得到的呢?根据下面来理解 ...
- HDU 4869 (递推 组合数取模)
Problem Turn the pokers (HDU 4869) 题目大意 有m张牌,全为正面朝上.进行n次操作,每次可以将任意ai张反面,询问n次操作可能的状态数. 解题分析 记正面朝上为1,朝 ...
- ACM-较大的数乘法取模技巧*
比如模数是1e15这种,相乘的时候爆LL了,但是又不想用大数,咋办呢? long long ksc(long long a, long long b, long long mod){ ; while( ...
- POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】
一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模
D. The Child and Sequence At the children's day, the child came to Picks's house, and messed his h ...
随机推荐
- W/System.err: at android.view.ViewConfiguration.get(ViewConfiguration.java:369)
*11-09 11:48:38.558 13887-13900/? W/System.err: at android.view.WindowManagerGlobal.getWindowManager ...
- python 学习分享-线程
多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长时间的程序中的任务放到后台去处理. 用户界面可以更加吸引人,这样比如用户点击了一个按钮去触发某些事件的处理,可以弹出一个进 ...
- iterm2+vim使用
iterm2+vim 终端切换为iterm2+zsh+oh my zsh,确实好用. I term2常用快捷键记录 新建标签:cmd+t 关闭标签:cmd+w 切换标签:cmd+数字, 切换全屏:cm ...
- 爬虫:Scrapy13 - 发送 email
虽然 Python 通过 smtplib 库使得发送 email 变得非常简单,Scrapy 仍然提供了自己的实现.该功能十分易用,同时由于采用了 Twisted 非阻塞式(non-blocking) ...
- oracle定时job粗解
其中一篇随笔我写了oracle的存储过程大概的介绍,存储过程除了自身有in的param,来进行程序调用处理之外,还可以通过定时任务的方式调用来执行. 应用场景: 数据同步:有两个显示菜单,“信息编辑” ...
- SQL 唯一标识 写法
创建唯一标识的方法~16位唯一标识 SELECT LTRIM(STR(CONVERT(varchar(100), GETDATE(), 112)))+right(cast(power(10,6) as ...
- Spring 对属性文件的加密与解密
一般用于配置密码等敏感信息 解密/加密工具类 package com.baobaotao.placeholder; import sun.misc.BASE64Decoder; import sun. ...
- P2215 [HAOI2007]上升序列
题目描述 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1<x2<…<xm) 且(ax1<ax2<…<a ...
- BZOJ1233 [Usaco2009Open]干草堆tower 【单调队列优化dp】
题目链接 BZOJ1233 题解 有一个贪心策略:同样的干草集合,底长小的一定不比底长大的矮 设\(f[i]\)表示\(i...N\)形成的干草堆的最小底长,同时用\(g[i]\)记录此时的高度 那么 ...
- GDB调试——经验总结
GDB调试的一些很有用经验: 1. gdb调试,如果有参数,可以在run命令后加,也可以使用set args :如果是使用gdbserver+gdb的远程调试方式,参数可以在gdbserver后面加. ...