题意:

给定一长度为 n 的整数序列 $a$,将其复制m次,并接成一条链,每相邻K个相同的整数会消除,然后其他的整数继续结成一条链,直到不能消除为止,求问最终剩余多少个整数。

解法:

首先将长度为n的序列消干净,然后接下来的消除操作必然是在两个序列相交处进行消除,对于接在中间的序列,原消法等价于序列的左侧和右侧不停消除直到无法继续。

分类讨论:

1.序列左右消干净了,这样答案为0

2.序列消得剩下一种元素,统计该元素的总个数,如果K|sum,则为0,不然为sum%K个加上左右侧剩余元素。

3.序列剩下一段元素:

考虑计算消除了多少个:

(1)首先剩余的元素拼在一起 如果有%K!=0的相同元素接在一起 将会消成sum%K

(2)其次中间序列左右消除的个数。

这样就解决了,效率$O(n)$

const int N = ;

int n,K,m,tot,a0[N],a[N],b[N];

int main() {
cin >> n >> K >> m;
int cnt = n;
FOR(i,,n) scanf("%d", &a0[i]);
b[] = -;
FOR(i, , n)
{
if(a0[i] == b[tot]) a[tot]++;
else
{
if(tot)
{
cnt -= a[tot]-a[tot]%K; a[tot] %= K;
if(a[tot]==) tot--;
}
if(!tot || a0[i] != b[tot]) a[++tot] = , b[tot] = a0[i];
else a[tot]++;
}
}
cnt -= a[tot]-a[tot]%K;
a[tot] %= K;
if(a[tot]==) tot--;
if(!tot)
{
cout << << endl;
return ;
}
// FOR(i,1,tot) cout<<a[i]<<'-'<<b[i]<<endl;
int l=, r=tot;
while(l<r)
{
if(b[l]!=b[r] || (a[l]+a[r])%K) break;
l++,r--;
}
// debug(l);
// debug(r);
// debug(cnt);
if(l>r)
{
cout << << endl;
return ;
}
else if(l==r)
{
if(1ll*a[l]*m%K==) cout << << endl;
else cout << cnt-a[l]+1ll*a[l]*m%K << endl;
}
else
{
LL ans = 1ll*m*cnt,tmp = cnt;
FOR(i,l,r) tmp -= a[i];
ans -= 1ll*(m-)*tmp;
if(b[l]==b[r]) ans -= 1ll*(m-)*((a[r]+a[l]) - (a[r]+a[l])%K);
cout << ans << endl;
}
return ;
}

Teams Formation的更多相关文章

  1. Codeforces Round #443 (Div. 1) B. Teams Formation

    B. Teams Formation link http://codeforces.com/contest/878/problem/B describe This time the Berland T ...

  2. cf 443 D. Teams Formation](细节模拟题)

    cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...

  3. 443 D. Teams Formation

    http://codeforces.com/contest/879/problem/D This time the Berland Team Olympiad in Informatics is he ...

  4. CodeForces 879D Teams Formation

    题意 将一个长度为\(n\)的数组重复\(m\)遍得到一个长度为\(n \times m\)的新序列,然后消掉新序列中连续\(k\)个相同的元素,不断重复这一过程,求最后剩下的序列的长度 分析 首先可 ...

  5. 【Codeforces】879D. Teams Formation 思维+模拟

    题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...

  6. codeforces 879 D. Teams Formation(思维)

    题目链接:http://codeforces.com/contest/879/problem/D 题意:这题题意我反正是看了很久,可能是我的理解能力有点差,就是将一个数组倍增m倍然后将连续的相同的k个 ...

  7. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  9. 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏

    Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

随机推荐

  1. 转载 ---资深HR告诉你:我如何筛选简历与选择人员的

    资深HR告诉你:我如何筛选简历与选择人员的   有个公司HR看简历 先直接丢掉一半 理由是不要运气不好的应聘者. 当然这可能只是某些HR面对太多的简历产生了偷懒的情绪,但是不论是Manager,亦或是 ...

  2. IntelliJ IDEA打可执行jar包

    <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <config ...

  3. JS基础常识理解

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 1355: [Baltic2009]Radio Transmission[循环节]

    1355: [Baltic2009]Radio Transmission Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 796  Solved: 538 ...

  5. MySQL集群搭建

    在集群中的所有主机上安装提供集群功能的软件包 官网上下载的  mysql-cluster-gpl-7.3.12-linux-glibc2.5-x86_64.tar.gz 规划了5台服务器,10.10. ...

  6. MongoDB API java的使用

    1.创建一个MongoDB数据库连接对象,它默认连接到当前机器的localhost地址,端口是27017. Mongo mongo=new Mongo(); 2.获得与某个数据库(例如“test”)的 ...

  7. HDFS relaxes a few POSIX requirements to enable streaming access to file system data

    https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html Introduction [ ...

  8. cookie和session的原理机制

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  9. mongoDB多级子文档查询

    db.getCollection('product').find({'coverage':{'$elemMatch':{'plan':{'$elemMatch':{'iscoverage':{'$in ...

  10. Android 修改Menu字体颜色和背景

    我们知道,在Android中修改TextView的字体颜色,一般是通过setTextColor()方法.虽说Android的Menu菜单项的每一项都是由TextView组成,但是Android的sdk ...