Teams Formation
题意:
给定一长度为 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的更多相关文章
- 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 ...
- cf 443 D. Teams Formation](细节模拟题)
cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...
- 443 D. Teams Formation
http://codeforces.com/contest/879/problem/D This time the Berland Team Olympiad in Informatics is he ...
- CodeForces 879D Teams Formation
题意 将一个长度为\(n\)的数组重复\(m\)遍得到一个长度为\(n \times m\)的新序列,然后消掉新序列中连续\(k\)个相同的元素,不断重复这一过程,求最后剩下的序列的长度 分析 首先可 ...
- 【Codeforces】879D. Teams Formation 思维+模拟
题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...
- codeforces 879 D. Teams Formation(思维)
题目链接:http://codeforces.com/contest/879/problem/D 题意:这题题意我反正是看了很久,可能是我的理解能力有点差,就是将一个数组倍增m倍然后将连续的相同的k个 ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-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 ...
随机推荐
- scrollview gridview
package com.fangdamai.salewinner.ui.customer; import android.content.Context;import android.content. ...
- python 基础 1.4 python运算符
一. 布尔值: 1>True 2>False 二.关系运算符 “=” (a=b):把b的值赋给a.等号赋值 “==”(a==b): 判断a与b是否相等.返回Trule或Fl ...
- 24、Cocos2dx 3.0游戏开发找小三之网格动作:高炫酷的3D动作
重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/37596763 网格动作类似于动作特效,能够实现翻转. ...
- GIT笔记:将项目发布到码云
GIT笔记:将项目发布到码云 发布步骤 1.码云创建项目 记录下项目的远程地址: https://gitee.com/mrsaber/ms_supplyAndSale.git 2.在本地创建GIT仓库 ...
- EF异常捕捉
try{// 写数据库}catch (DbEntityValidationException dbEx){ }
- 《机器学习实战》学习笔记第七章 —— AdaBoost元算法
主要内容: 一.提升方法与AdaBoost算法的简介 二.AdaBoost算法 三.代码解释 一.提升方法与AdaBoost算法的简介 1.提升方法:从弱学习算法出发,反复学习,得到一系列弱分类器(又 ...
- java--List判断是否为空
list.isEmpty()和list.size()==0 没有区别 isEmpty()判断有没有元素,size()返回元素个数 如果判断一个集合有无元素,用isEmpty()方法. 这就相当与,你要 ...
- js面向(基于)对象编程-三大特征
①抽象 js提供以下几种控制方法和属性的访问权限: (1)公开级别:对外公开 (2)私有级别:类本身可以访问,不对外公开 案例如下所示: function Person(name,age,sal){ ...
- 安装与设置hexo
普通用户(非全局)安装nodejs和npm wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh nvm ins ...
- 机器学习 Regularization and model selection
Regularization and model selection 假设我们为了一个学习问题尝试从几个模型中选择一个合适的模型.例如,我们可能用一个多项式回归模型hθ(x)=g(θ0+θ1x+θ2x ...