I Wanna Be The Very Best

I Wanna Be The Very Best

In order to become the very best Pokenom trainer, Bash needs to prepare a team of Pokenom to participate in the Pokenom world championship.

Bash has N Pokenoms. Each Pokenom has 3 stats: Attack, Defense and Health. Bash wants to select K Pokenoms with highest attack, K Pokenoms with highest defense and K Pokenoms with highest Health.

After selection, Bash found something strange: his team have less than 3×K Pokenoms!

Bash looks carefully at N=4 Pokenoms he has:

‘Chikapu’: Attack = 100, Defense = 100, Health = 100

‘Batterfly’: Attack = 10, Defense = 10, Health = 10

‘Mewthree’: Attack = 200, Defense = 200, Health = 80

‘Dragonon’: Attack = 150, Defense = 150, Health = 90

When Bash selects Pokenom with K=1, only ‘Mewthree’ and ‘Chikapu’ are selected! This is because ‘Mewthree’ has highest attack and highest defense!

Your task is simple, you are given the stats of all N Pokenoms and the number K. Calculate how many different Pokenoms are there in Bash’s team.

Input
The first line of input contains 2 integers N and K (1≤K≤N≤1000).

In the next N lines, the i-th line contains 3 integers: Ai, Di and Hi, representing the 3 stats of the i-th Pokenom. Ai, Di and Hi are unsigned 32-bit integers.

It is guaranteed that no 2 Pokenom have same Attack, no 2 Pokenom have same Defense, and no 2 Pokenoms have same Health.

Output
Output one line containing exactly one integer: the number of Pokenom in Bash’s team.

Sample Input 1

4 1
100 100 100
10 10 10
200 200 80
150 150 90

Sample Output 1

2

本题题意很简单,给定N个精灵,数据分别为攻击,防御,生命,给定一个K,找出K个精灵,分别为攻击力最大的K个精灵,防御力最大的K个精灵与生命最大的K个精灵,因为有些精灵攻击防御或生命有可能同时最大,所以,达不到3K个这样的精灵,那么我们只需要将攻击排序,找出K个攻击最大,防御排序找出K个防御最大,生命排序找出K个生命最大,然后将这3K个精灵中重复的部分去掉,即是最后的答案。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
	long long int a, b, c,d;
}PK[1005];
bool cap(Node a, Node b)
{
	return a.a > b.a;
}
bool cbp(Node a, Node b)
{
	return a.b > b.b;
}
bool ccp(Node a, Node b)
{
	return a.c > b.c;
}
int main()
{
	int N, K;
	int a[5005];
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> PK[i].a >> PK[i].b >> PK[i].c;
		PK[i].d = i;
	}
	sort(PK, PK + N, cap);
	int KK = 0, cnt = 0;
	for (int i = 0; i < K; i++)
		a[KK++] = PK[i].d;
	sort(PK, PK + N, cbp);
	for (int i = 0; i < K; i++)
		a[KK++] = PK[i].d;
	sort(PK, PK + N, ccp);
	for (int i = 0; i < K; i++)
		a[KK++] = PK[i].d;
	sort(a, a + (3 * K));
	for (int i = 0; i < 3 * K - 1; i++)
		if (a[i] != a[i + 1])
			cnt++;
	cout << cnt+1 << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值