生活随笔
收集整理的這篇文章主要介紹了
对局匹配
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
小明喜歡在一個圍棋網站上找別人在線對弈。這個網站上所有注冊用戶都有一個積分,代表他的圍棋水平。
小明發現網站的自動對局系統在匹配對手時,只會將積分差恰好是K的兩名用戶匹配在一起。如果兩人分差小于或大于K,系統都不會將他們匹配。
現在小明知道這個網站總共有N名用戶,以及他們的積分分別是A1, A2, ... AN。
小明想了解最多可能有多少名用戶同時在線尋找對手,但是系統卻一場對局都匹配不起來(任意兩名用戶積分差不等于K)? ?
輸入
----
第一行包含兩個個整數N和K。
第二行包含N個整數A1, A2, ... AN。 ?
對于30%的數據,1 <= N <= 10
對于100%的數據,1 <= N <= 100000, 0 <= Ai <= 100000, 0 <= K <= 100000
輸出
----
一個整數,代表答案。
樣例輸入:
10 0
1 4 2 8 5 7 1 4 2 8?
樣例輸出:
6
再比如,
樣例輸入:
10 1
2 1 1 1 1 4 4 3 4 4
樣例輸出:
8
?
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<sstream>
#include<cassert>
using namespace std;
const int maxn = 100000 + 5;
const int INF = 10000000;
typedef long long ll;
int n;
int vis[maxn];
int d[maxn],t[maxn],k,v[maxn];int main() {while (cin >> n>>k && n) {int num,ans=0;for (int i = 1; i <= n; i++) { cin >> num; t[num]++; }if (k == 0) {for (int i = 0; i <= n; i++)if (t[i])ans++;}else {for (int i = 0; i < k; i++) {int l = 1;for (int j = i; j < n; j += k) {v[l++] = t[j];}d[0] = 0; d[1] = v[1];for (int j = 2; j < l; j++) {d[j] = max(d[j - 1], d[j - 2] + v[j]);}ans += d[l - 1];}}cout << ans << endl;}return 0;
}
?
總結
以上是生活随笔為你收集整理的对局匹配的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。