码迷,mamicode.com
首页 > 系统相关 > 详细

ICPC 2017 Daejeon-Slot Machines

时间:2018-10-05 12:26:51      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:php   bit   target   icpc   csr   space   存储   链接   pre   

题目链接http://exam.upc.edu.cn/problem.php?id=9318&csrf=7XM2JJN7Kfq71alBWM0ZzOTygvRIv1oG

求最小循环节,只不过倒序存储一下

 1 #include<bits/stdc++.h>
 2  
 3 using namespace std;
 4 const int maxn=1e6+5;
 5 int a[maxn],nxt[maxn],n;
 6 void fun()
 7 {
 8     nxt[1]=0;
 9     for(int i=2,j=0;i<=n;i++)
10     {
11         while(j>0&&a[i]!=a[j+1])    j=nxt[j];
12         if(a[i]==a[j+1])    j++;
13         nxt[i]=j;
14     }
15 }
16 int main()
17 {
18     scanf("%d",&n);
19     for(int i=1;i<=n;i++)   scanf("%d",&a[n-i+1]);
20     fun();
21     int pp=2*n,kk=2*n,p,k;
22     for(int i=1;i<=n;i++)
23     {
24         p=i-nxt[i],k=n-i;
25         if(p+k<pp+kk||(p+k==pp+kk&&p<pp))
26             pp=p,kk=k;
27     }
28     printf("%d %d\n",kk,pp);
29     return 0;
30 }

 

ICPC 2017 Daejeon-Slot Machines

标签:php   bit   target   icpc   csr   space   存储   链接   pre   

原文地址:https://www.cnblogs.com/scott527407973/p/9744279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!