codeforces 879 D. Teams Formation(思维)
题目链接:http://codeforces.com/contest/879/problem/D
题意:这题题意我反正是看了很久,可能是我的理解能力有点差,就是将一个数组倍增m倍然后将连续的相同的k个删除删到不能再删为止。
题解:这里m有点大肯定不能暴力所以可以考虑两个两个之间相互抵消比如
(1231) (1231) (1231) (1231) (1231)
第一部分的后半和第二部分的前半合并,第二部分后半和第三部分前半合并最后第一部分前半和最后一部分后半合并差不多就是这个意思然后就摸你一下就好
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std;
const int M = 1e5 + ;
typedef long long ll;
ll Stack[M][];
int main() {
int n , k , m , x , top = ;
ll ans = ;
cin >> n >> k >> m;
for(int i = ; i < n ; i++) {
cin >> x;
if(!top || Stack[top][] != x) {
Stack[++top][] = x;
Stack[top][] = ;
}
else {
Stack[top][]++;
}
if(Stack[top][] == k) {
Stack[top--][] -= k;
}
}
ll sum = ;
for(int i = ; i <= top ; i++) {
sum += Stack[i][];
}
int sta = , ed = top;
while(sta < ed && Stack[sta][] == Stack[ed][]) {
if((Stack[sta][] + Stack[ed][]) % k == ) {
sta++ , ed--;
}
else {
Stack[sta][] = (Stack[sta][] + Stack[ed][]) % k;
Stack[ed][] = ;
break;
}
}
if(sta < ed) {
for(int i = sta ; i <= ed ; i++) ans += Stack[i][];
ans *= (m - );
ans += sum;
}
else if(sta == ed) {
if(Stack[sta][] * m % k == ) ans = ;
else {
ans = sum + Stack[sta][] * (m - );
ans -= Stack[sta][] * m - Stack[sta][] * m % k;
}
}
cout << ans << endl;
return ;
}
codeforces 879 D. Teams Formation(思维)的更多相关文章
- 【Codeforces】879D. Teams Formation 思维+模拟
题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...
- 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 ...
- codeforces 478B Random Teams
codeforces 478B Random Teams 解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...
- cf 443 D. Teams Formation](细节模拟题)
cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...
- CodeForces 879D Teams Formation
题意 将一个长度为\(n\)的数组重复\(m\)遍得到一个长度为\(n \times m\)的新序列,然后消掉新序列中连续\(k\)个相同的元素,不断重复这一过程,求最后剩下的序列的长度 分析 首先可 ...
- 443 D. Teams Formation
http://codeforces.com/contest/879/problem/D This time the Berland Team Olympiad in Informatics is he ...
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- codeforces 478B Random Teams 解题报告
题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...
- CodeForces - 427A (警察和罪犯 思维题)
Police Recruits Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
随机推荐
- 【Python-Django】浏览器同源策略
1995年,同源政策由 Netscape 公司引入浏览器.目前,所有浏览器都实行这个政策. 同源策略是浏览器的一个安全功能,不同源的客户端脚本(js文件)在没有明确授权的情况下,不能读写对方资源.只有 ...
- git bash 初始化配置
这里只针对 windows 下,使用git 时的一些初始配置 1. git bash 安装 下载地址: https://git-for-windows.github.io/ 根据提示,一步步安装即可 ...
- 【Python】狂蟒来袭 | 使用Anaconda搭建Python开发环境
这段时间转了一个小圈圈,发现又回来了,瞎忙.想要学习数据挖掘的小伙伴一定得对机器学习有所了解吧,我之前看过几页周志华老师的西瓜书,但终没能坚持下来. 人生处处是起点,什么时候都不晚.记此笔记以分享与督 ...
- Vue系列:.sync 修饰符的作用及使用范例
作用:对传递给子组件的 prop 数据进行“双向绑定”.(正常情况下,prop 的数据都是单向数据流) 代码参考如下: 父组件部分 子组件部分
- CSS: hack 方式一览
本文引自:http://blog.csdn.net/freshlover/article/details/12132801 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...
- Spring 集成Kafka(完整版)
前面的文章我们已经完成了Kafka基于Zookeeper的集群的搭建了.Kafka集群搭建请点我.记过几天的研究已经实现Spring的集成了.本文重点 jar包准备 集成是基于spring-integ ...
- websocket初体验(小程序)
之前上个公司做过一个二维码付款功能,涉及到websocket功能,直接上代码 小程序onShow方法下加载: /** 页面的初始数据 **/ data: { code: "", o ...
- (三十)c#Winform自定义控件-文本框(三)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- centos7单机安装kafka,进行生产者消费者测试
[转载请注明]: 原文出处:https://www.cnblogs.com/jstarseven/p/11364852.html 作者:jstarseven 码字挺辛苦的..... 一.k ...
- linux command line learn - get the absolute path of a file
get the absolute path of a file in linux readlink -f filenme [heshuai@login01 3_Variation_calling]$ ...