#Codeforces Round #687 Div. 2_B. Repainting Street

B. Repainting Street

题目链接在此!

B. Repainting Street
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There is a street with 𝑛 houses in a line, numbered from 1 to 𝑛. The house 𝑖 is initially painted in color 𝑐𝑖. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street beautiful. Tom’s painting capacity is defined by an integer, let’s call it 𝑘.

On one day, Tom can do the following repainting process that consists of two steps:

He chooses two integers 𝑙 and 𝑟 such that 1≤𝑙≤𝑟≤𝑛 and 𝑟−𝑙+1=𝑘.
For each house 𝑖 such that 𝑙≤𝑖≤𝑟, he can either repaint it with any color he wants, or ignore it and let it keep its current color.
Note that in the same day Tom can use different colors to repaint different houses.

Tom wants to know the minimum number of days needed to repaint the street so that it becomes beautiful.

Input
The first line of input contains a single integer 𝑡 (1≤𝑡≤10^4), the number of test cases. Description of test cases follows.

In the first line of a test case description there are two integers 𝑛 and 𝑘 (1≤𝑘≤𝑛≤10^5).

The second line contains 𝑛 space-separated integers. The 𝑖-th of these integers represents 𝑐𝑖 (1≤𝑐𝑖≤100), the color which house 𝑖 is initially painted in.

It is guaranteed that the sum of 𝑛 over all test cases does not exceed 105.

Output
Print 𝑡 lines, each with one integer: the minimum number of days Tom needs to make the street beautiful for each test case.

Example
inputCopy
3
10 2
1 1 2 2 1 1 2 2 2 1
7 1
1 2 3 4 5 6 7
10 3
1 3 3 3 3 1 2 1 3 3
outputCopy
3
6
2
Note
In the first test case Tom should paint houses 1 and 2 in the first day in color 2, houses 5 and 6 in the second day in color 2, and the last house in color 2 on the third day.

In the second test case Tom can, for example, spend 6 days to paint houses 1, 2, 4, 5, 6, 7 in color 3.

In the third test case Tom can paint the first house in the first day and houses 6, 7, and 8 in the second day in color 3.

题意分析:

其实没啥好讲的,染色问题。一个数字代表一个颜色,总共最多100个颜色。1e5的元素。区间k,问最少要染色多少次。

其实看数据量这个样子,直接暴力遍历,每个颜色都用来做统一色染他个遍。

反正遇到的第一个未染色的数字肯定是要被染色的。然后此后k个全部统一,最后min一下。

还想着要不要用队列维护,维护个头,这是div2的B题,暴力就完事了,太亏了这题。做快点的话可以上分的!!

不过有个教训也好。

代码:

#include <iostream>
#include <stdio.h>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define ll long long
#define inf 1<<30
using namespace std;
const int maxn = 1e5 + 9;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    int vis[maxn];
    cin >> T;
    while (T--) {
        int a[maxn],b[maxn],c[maxn];
        int n,k,cnt,oy=1e6;
        cin>>n>>k;
        for(int i=1;i<=n;i++){
            cin>>c[i];
            a[i]=c[i];
        }
        for(int j=1;j<=100;j++) {
            cnt=0;
            for(int i=1;i<=n;i++){
                a[i]=c[i];
            }
            for (int i = 1; i <= n; i++) {
                if(a[i]!=j) {
                    for(int sn=i;sn<=n,sn<i+k;sn++)
                        a[sn]=j;
                    cnt++;
                }


            }
            oy>cnt?oy=cnt:oy;
        }
        cout<<oy<<endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值