codeforces 371A K-Periodic Array
很简单,就是找第i位、i+k位、i+2*k位...........i+m*k位有多少个数字,计算出每个数出现的次数,找到出现最多的数,那么K-Periodic的第K位数肯定是这个了。这样的话需要替换的就是除出现最多的数之外的数了。
#include <stdio.h>
#include <algorithm> using namespace std; int a[105]; int main()
{
int n, k;
while (scanf("%d %d", &n, &k) != EOF)
{
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int x = n/k;
int ans = 0;
for (int i = 1; i <= k; i++)
{
int m = 0;
for (int j = i; j <= n; j+= k)
{
int cnt = 0;
for (int l = j; l <= n; l += k)
{
if (a[j] == a[l])
cnt++;
if (cnt > m)
m = cnt;
}
}
ans += (x-m);
}
printf("%d\n", ans);
}
return 0;
}
codeforces 371A K-Periodic Array的更多相关文章
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- FB面经Prepare: Merge K sorted Array
Merge K sorted Array 跟Merge K sorted lists不同在于,从PQ里poll出来以后不知道下一个需要被加入PQ的是哪一个 所以需要写一个wrapper class p ...
- Codeforces 371A K-Periodic Array(模拟)
题目链接 K-Periodic Array 简单题,直接模拟即可. #include <bits/stdc++.h> using namespace std; #define REP(i, ...
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Educational Codeforces Round 11A. Co-prime Array 数学
地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...
- Codeforces 295A Greg and Array
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
随机推荐
- Java多线程同步工具类之Semaphore
Semaphore信号量通常做为控制线程并发个数的工具来使用,它可以用来限制同时并发访问资源的线程个数. 一.Semaphore使用 下面我们通过一个简单的例子来看下Semaphore的具体使用,我们 ...
- SqlHelper(基础)
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- RQNOJ193 造路行动
题目转移 详见最小生成树讲解 Kruskal #include<cstdio> #include<algorithm> using namespace std; ; int n ...
- python初识(3)
bool 字符串 for循环 bool 数字非零全都是True 字符串非空全都是True 字符串 索引 从0开始 0 切片选取 [x:y] 左闭右开区间 [x:y:z] 选取x到y之间 每隔z选取一次 ...
- JPA自定义实体的id
背景:继上一篇文章,已经实现客户端数据库数据,存入服务器,但是,两张表的id不一样,应该是id设置自增了,所以虽然从客户端查出的实体带id,但是存入服务器时id被抹掉,按照服务端表的id序号向上自增, ...
- 用SpringBoot+MySql+JPA实现对数据库的增删改查和分页
使用SpringBoot+Mysql+JPA实现对数据库的增删改查和分页 JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述 ...
- mysql查询语句出现sending data耗时解决
在执行一个简单的sql查询,表中数据量为14万 sql语句为:SELECT id,titile,published_at from spider_36kr_record where is_analyz ...
- 哈工大计算机网络Week3-传输层
目录 学习目标 传输层服务概述 传输层服务和协议 传输层 vs. 网络层 Internet传输层协议 多路复用和多路分用 多路复用/分用 分用如何工作? 无连接分用(UDP) 面向连接的分用 面向连接 ...
- Spring MVC中使用FastJson自定义注解
最近在做.net转译成Java.其中遇到一个很蛋疼的问题.以前.net属性名都是首字母大写.造成返回给客户端的JSON字符串属性名称都是首字母大写.为了和前端对接我们以前都是如下图所示做法 publi ...
- 【bfs基础】①
bfs,即广度优先搜索,主要通过队列(queue)进行操作. 稍微解释一下,队列是一种基础数据结构,其形态类似于一支长长的队伍,大概如下: 在C++中,队列的头文件定义为:#include<qu ...