POJ 1047Round and Round We Go——大数乘法+匹配
来源:互联网 发布:png软件下载 编辑:程序博客网 时间:2024/06/05 01:54
题目链接点击打开链接
题意:给定一个n位数,判断该数乘以i (1<=i<=n)是否还由该数的各个位上的数通过改变顺序组成。
思路:很明显,题中的数的位数最多60位,显然要用到大数乘法。不过,这道题是一个大数乘以一个小数,比较简单。如果乘以i后位数变大了,很明显该数就不是cyclic。在位数相同的情况下再判断。只要将得到的大数sort一下,再和初始给的数sort以后的值一位一位比较就可以了。easy~~~
开始时把给的数直接sort了。。。傻逼掉了
AC代码
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<iomanip>#include<algorithm>#include<cmath>using namespace std;int tmp[100],a[1000],acopy[1000],len;bool multi(int n)//大数乘法{ int i,t=0; for(i=0; i<len; i++) { t=a[i]*n+t; tmp[i]=t%10; t/=10; } if(t>0) return false;//判断最后是否会进位 return true;}bool judge(int n){ if(!multi(n))//有进位直接返回false return false; sort(tmp,tmp+len);//开始匹配~~~ for(int i=0; i<len; i++) if(tmp[i]!=acopy[i]) return false; return true;}int main(){ char num[1000]; while(scanf("%s",num)!=EOF) { int cnt=0,flag=1; len=strlen(num); for(int i=len-1; i>=0; i--) { a[cnt]=num[i]-'0'; acopy[cnt]=a[cnt]; cnt++; } sort(acopy,acopy+len);//将给定的数sort for(int i=2; i<=len; i++) { if(!judge(i)) { flag=0; printf("%s is not cyclic\n",num); break; } } if(flag) printf("%s is cyclic\n",num); } return 0;}
0 0
- POJ 1047Round and Round We Go——大数乘法+匹配
- POJ 1047 Round and Round We Go (大数乘法) 水
- POJ Round and Round We Go 大数位乘法
- hdu1313 Round and Round We Go (大数乘法)
- Round and Round We Go POJ 1047
- poj 1047 Round and Round We Go
- poj 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- poj 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- poj 1047-Round and Round We Go
- POJ 1047 Round and Round We GO
- poj 1047 Round And Round We Go
- POJ 1047 Round and Round We Go
- POJ 1049 Round and Round We Go 大数模拟
- POJ Round and Round We Go(核心大数相乘算法)
- POJ 1047 Round and Round We Go 循环数新解
- 那些与鸡缸杯且行且珍惜的人
- hadoop出现ava.lang.ClassNotFoundException: org.codehaus.jackson.map.JsonMappingException
- CUGBACM_Summer_Tranning2【二维线段树】
- IOS-网络请求
- C/C++开发规范之一
- POJ 1047Round and Round We Go——大数乘法+匹配
- 精通安卓性能优化-第七章(三)
- Writing Audit Plugins
- 基本类型 包装类型 堆与栈 的区别
- java 身份证15转18
- 巧用dblink结合oracle快照实现两台服务器的数据同步
- 过滤器,监听器,拦截器的区别
- 关于概率的面试题
- UVA Compromise(最长公共子序列 + 打印路径)