hdu 5109 Alexandra and A*B Problem
来源:互联网 发布:cst软件价格 编辑:程序博客网 时间:2024/05/17 23:20
枚举乘积长度,再枚举s串位置,再枚举s串前的大小,即可得出s串后的大小。学一下这种写法。
#include<iostream>#include<cstring>#include<cstdio>#include<ostream>#include<istream>#include<algorithm>#include<queue>#include<string>#include<cmath>#include<set>#include<map>#include<stack>#include<vector>#define fi first#define se second#define pii pair<int,int>#define ll long long#define inf (1ll<<60)#define eps 1e-8using namespace std;const int maxn=210005;ll a;char s[100];ll base[100];ll ans;bool work(int c,int len){ int l=strlen(s+1); ll Min=inf; for(int i=1;i+l-1<=len;i++) { for(int j=c;j<base[i-1];j++) { ll u=j*base[len-i+1]+ans*base[len-(i+l-1)]; if(u%a==0) Min=min(Min,u); else { if(a-u%a<base[len-(i+l-1)]) Min=min(Min,u+(a-u%a)); } } } if(Min!=inf) { printf("%I64d\n",Min/a); return true; } return false;}int main(){ base[0]=1; for(int i=1;i<=15;i++) base[i]=base[i-1]*10; while(~scanf("%I64d%s",&a,s+1)) { ans=0; for(int i=1;i<=strlen(s+1);i++) ans=ans*10+s[i]-'0'; if(s[1]!='0') { if(ans%a==0) { printf("%I64d\n",ans/a); continue; } } for(int i=strlen(s+1)+1;;i++) { if(work(s[1]=='0',i)) break; } } 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
- Java 面试试题及其解答
- Hibernate——Hql实例+详解
- 关于pkg: /data/local/tmp/com.example.zy.deyijia Failure [INSTALL_FAILED_OLDER_SD问题
- leetcode 151: Reverse Words in a String
- Mac下最好用的离线词典-欧陆词典破解版
- hdu 5109 Alexandra and A*B Problem
- POJ 2299 Ultra-QuickSort(求逆序数)
- Sorting It All Out
- 代写代做程序设计 国外算法编程 VB/C语言/C++/数据结构/Java/PHP/Python
- 关于support design包中behaviour的使用
- 知行合一
- 疯狂Java讲义中的程序,使用代理服务器来获取网上的资源
- 火狐访问博客园报400错误问题解决
- centos常用命令