P2652 同花顺

P2652 同花顺

题目链接

​ 乱搞的题。

​ 先按花色为第一关键字,以权值大小为第二关键字排个序,然后求出同种花色中最长的连续的牌数,用总的牌数减去即可。

​ 一定要记得去重。

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

inline int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * f;
}

const int N = 1e5 + 5;
int n, cnt, ans;
struct card { int col, num; } a[N], b[N];

int cmp(card a, card b) { if(a.col == b.col) return a.num < b.num; else return a.col < b.col; }

int main() {
	
	n = read();
	for(int i = 1;i <= n; i++) a[i].col = read(), a[i].num = read();
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1;i <= n; i++) {
		if(a[i].col == a[i - 1].col && a[i].num == a[i - 1].num) continue;
		b[++cnt].col = a[i].col; b[cnt].num = a[i].num;
	}
	for(int i = 1;i <= cnt; i++) {
		int tmp = 0;
		for(int j = i;j >= 1; j--) {
			if(b[j].col == b[i].col && b[i].num - b[j].num + 1 <= n) tmp++;
			else break;
		}
		ans = max(ans, tmp);
	}
	printf("%d", n - ans);
	
	return 0;
}
posted @ 2020-09-14 07:20  C锥  阅读(91)  评论(0编辑  收藏  举报