标签:span min ++i ble turn 模拟 log ref codeforce
题目链接 K-Periodic Array
简单题,直接模拟即可。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define REP(i,n) for(int i(0); i < (n); ++i) 6 #define rep(i,a,b) for(int i(a); i <= (b); ++i) 7 const int N = 100000 + 10; 8 9 int a[N]; 10 int n, k; 11 int ans; 12 int b[N], c[N]; 13 int x; 14 15 int main(){ 16 17 scanf("%d%d", &n, &k); 18 rep(i, 1, n) scanf("%d", a + i); 19 rep(i, 1, n){ 20 x = i % k; 21 if (a[i] == 1) b[x]++; else c[x]++; 22 } 23 24 25 REP(i, k) ans += min(b[i], c[i]); 26 printf("%d\n", ans); 27 return 0; 28 29 }
Codeforce 371A K-Periodic Array(模拟)
标签:span min ++i ble turn 模拟 log ref codeforce
原文地址:http://www.cnblogs.com/cxhscst2/p/6359053.html