只做了1001 1002 1005 1006。剩下2题可能以后补?

http://acm.hdu.edu.cn/search.php?field=problem&key=2016%22%B0%D9%B6%C8%D6%AE%D0%C7%22+-+%B3%F5%C8%FC%A3%A8Astar+Round2A%A3%A9&source=1&searchmode=source

Solved Pro.ID Title Author Source (AC/Submit)Ratio
2016百度之星 初赛2A ABEF 5690 All X   2016"百度之星" - 初赛(Astar Round2A) (438/912)48.03%
2016百度之星 初赛2A ABEF 5691 Sitting in Line   2016"百度之星" - 初赛(Astar Round2A) (255/566)45.05%
  5692 Snacks   2016"百度之星" - 初赛(Astar Round2A) (148/689)21.48%
  5693 D Game   2016"百度之星" - 初赛(Astar Round2A) (70/212)33.02%
2016百度之星 初赛2A ABEF 5694 BD String   2016"百度之星" - 初赛(Astar Round2A) (214/477)44.86%
2016百度之星 初赛2A ABEF 5695 Gym Class   2016"百度之星" - 初赛(Astar Round2A) (266/668)39.82%

题面看不清楚的可以去下面这个比赛网址看,但是交题要去上面这些交。

http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=701

都是题面很明显的中文题,我就不写题意了。

1001 All X

题解:

2种解法:1.矩阵快速幂 2.找循环节。我用的是找循环节。

1.快速幂解法:乘十加一这个操作可以转化为乘上一个2*2的矩阵的操作,用快速幂把一大堆矩阵算完,就无敌了。

2.找循环节,观察MOD数不到1W,所以算着算着肯定会出现重复的数,然后就会循环,我们可以跳过若干循环,直接算最后不到1W步的地方。

设y,循环使y=(y*10+1)%MOD,将每个y记录,a[y] = step。a数组初始化-1,当发现a[y]不为-1时,就循环了。

注意有地方要用long long。

代码:

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 
14 #define MZ(array) memset(array, 0, sizeof(array))
15 #define MF1(array) memset(array, -1, sizeof(array))
16 #define MINF(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define ROF(i,x,y) for(i=(x);i>=(y);i--)
20 #define RD(x) scanf("%d",&x)
21 #define RD2(x,y) scanf("%d%d",&x,&y)
22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
23 #define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
24 #define WN(x) printf("%d\n",x);
25 #define RE  freopen("D.in","r",stdin)
26 #define WE  freopen("huzhi.txt","w",stdout)
27 #define MP make_pair
28 #define PB push_back
29 #define PF push_front
30 #define PPF pop_front
31 #define PPB pop_back
32 #define lowbit(x) ((x)&(-x))
33 template<class T>inline void OA(const T &a,const int &st,const int &ed) {
34     if(ed>=st)cout<<a[st];
35     int i;
36     FOR(i,st+1,ed)cout<<' '<<a[i];
37     puts("");
38 }
39 typedef long long LL;
40 typedef unsigned long long ULL;
41 const double PI=acos(-1.0);
42 const double EPS=1e-10;
43 inline int sgn(double &x) {
44     if(fabs(x) < EPS)return 0;
45     if(x < 0)return -1;
46     else return 1;
47 }
48 
49 const int MAXN=111111;
50 const int MAXM=33;
51 
52 LL x,k,c;
53 LL m;
54 
55 LL h[11111];
56 
57 bool farm() {
58     LL y = 0;
59     LL l = 0;
60     MF1(h);
61     h[0] = 0;
62     while(l<m) {
63         y = y*10+x;
64         y %= k;
65         l++;
66         if(h[y]!=-1) {
67             break;
68         }
69         h[y] = l;
70     }
71     if(l<m) {
72         LL st = h[y];
73         LL ed = l;
74         LL step = ed - st;
75         LL jump = (m-l)/step;
76         l += jump*step;
77         while(l<m) {
78             y = y*10+x;
79             y %= k;
80             l++;
81         }
82     }
83 
84     return y==c;
85 }
86 
87 int main() {
88     int i;
89     int T,t=1;
90     RD(T);
91     while(T--) {
92         cin>>x>>m>>k>>c;
93         printf("Case #%d:\n",t++);
94         if(farm())puts("Yes");
95         else puts("No");
96     }
97     return 0;
98 }
View Code

相关文章: