HDU ACM 1066 Last non-zero Digit in N!
#include<iostream>
using namespace std; int mod[20]={1,1,2,6,4,2,2,4,2,8,4,4,8,4,6,8,8,6,8,2};
char s[1010]; //字符串
int num[1010]; //转换为数字 int sovle()
{
int len,i,c,ans; len=strlen(s);
ans=1;
for(i=0;i<len;i++)
num[i]=s[len-i-1]-'0';
while(len)
{
len-=!num[len-1];
ans=ans*mod[num[1]%2*10+num[0]]%10;
for(i=len-1,c=0;i>=0;i--)
{
c=c*10+num[i];
num[i]=c/5; //倍数
c%=5; //余数
}
}
return ans;
} int main()
{
while(scanf("%s",s)==1)
{
printf("%d\n",sovle());
}
return 0;
}
參考了网上的思路搞的,这题真难搞懂。
HDU ACM 1066 Last non-zero Digit in N!的更多相关文章
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- hdu acm 1166 敌兵布阵 (线段树)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu acm 2082 找单词
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU ACM 1325 / POJ 1308 Is It A Tree?
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU ACM 1134 Game of Connections / 1130 How Many Trees?(卡特兰数)
[题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1134 [解题背景]这题不会做,自己推公式推了一段时间,将n=3和n=4的情况列出来了,只发现第n项与 ...
- HDU ACM Eight
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 解题背景: 看到八数码问题,没有任何的想法,偶然在翻看以前做的题的时候发现解决过类似的一道题,不 ...
- HDU ACM 1690 Bus System (SPFA)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU ACM 1224 Free DIY Tour (SPFA)
Free DIY Tour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- Android中获取系统的时间
activity代码 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); set ...
- Android ScrollView嵌套HorizontalScrollView 滑动问题 ScrollView包括GridView显示问题
今天项目使用到ScrollView嵌套HorizontalScrollView,ScrollView里包括GridView,发现几个问题非常经典.在此记录: 问题1.ScrollView嵌套Horiz ...
- spring和mybatis整合进行事务管理
1.声明式实现事务管理 XML命名空间定义,定义用于事务支持的tx命名空间和AOP支持的aop命名空间: <beans xmlns="http://www.springframewor ...
- C++对C语言的非面向对象特性扩充(3)
今天要讲的是C++作用域运算符"::",强制类型转换的扩充,C++中相对于C中malloc和free函数的运算符new和delete,以及C++对C的一个重要扩充:引用(refer ...
- mysql存储过程详解[转]
1. 存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储 ...
- (Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- [转载]MySql常用命令总结
原文:http://www.php100.com/html/webkaifa/database/Mysql/2009/0910/3288.html1:使用SHOW语句找出在服务器上当前存在什么数据库: ...
- Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
@Configuration public class HttpSessionConfig { @Bean public static ConfigureRedisAction configureRe ...
- UNIX 缩写风格
构建于图形界面之上的操作系统,使用鼠标作为主输入设备, 是否使用缩写并不重要.比如 Windows 系统中的目录,几乎都是全称…… 点击两次鼠标进入文件夹 pf, 并不意味着点击13次才能进入文件夹 ...
- BeanUtils数据封装与表单JavaBean
一.BeanUtils工具的解释 (1)Apache的Commons组件中.提供了一个实用的工具类BeanUtils,利用它可以方便的将表单数据值填充值Bean中: (2)javax.servlet. ...