hdu 1061 Rightmost Digit解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061

本来是个水题 却被数组下标为0折磨的痛苦万分 中间出了很多差错 花了好长时间看其他解题报告 哎 水啊水啊水

具体思路:就求末尾 和其他位置无关 所以可以对10取余数 来得到乘法的数

然后通过计算看出 四个数是一个循环: 

1 1 1 1 1

2 4 8 6 2

3 9 7 1 3

4 6 4 6 4

5 5 5 5 5

6 6 6 6 6

7 9 3 1 7

8 4 2 6 8

9 1 9 1 9

当然 这是找到的顺序 要是用数组存得话得将数向后移动一位(数组下标为0太坑爹了)

得到的数组如下

0 1 2 3//数组下标

1 1 1 1

6 2 4 8

1 3 9 7

6 4 6 4

5 5 5 5

6 6 6 6

1 7 9 3

6 8 4 2

9 1 9 1 //好不容易想到了最后一组还写烦了 WA了一次 哎

数组的0号位存原来循环的最后一位(这么简单还想了半天)

粘代码:

View Code
 1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4 int main()
5 {
6 int m,r,p,i,ncase,a,b;
7 int ans[10][4]={{0,0,0,0},{1,1,1,1},{6,2,4,8},{1,3,9,7},{6,4,6,4},{5,5,5,5},{6,6,6,6},{1,7,9,3},{6,8,4,2},{1,9,1,9}};
8 while(scanf("%d",&ncase)!=EOF)
9 {
10 for(i=0;i<ncase;i++)
11 { scanf("%d",&m);
12 a=m%10;
13 b=m%4;
14 printf("%d\n",ans[a][b]);
15 }
16
17 }
18 system("pause");
19 return 0;
20 }
原文地址:https://www.cnblogs.com/yujiaao/p/2229128.html