只会写暴力,求调
查看原帖
只会写暴力,求调
852144
Loser_Syx楼主2023/5/1 10:42

T 飞了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define int long long
#define f(W, X, Y, Z) for(int W = X; W <= Y; W += Z)
#define F(W, X, Y, Z) for(int W = X; W >= Y; W -= Z)
#define debug puts("QAQ")
inline int read(){
	register int x = 0, s = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') s = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = (x << 1) + (x << 3) + (c ^ '0');
		c = getchar();
	}
	return x * s;
}
inline void write(int x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x > 9) write(x / 10);
	putchar((x % 10) + '0');
}
struct INF{
	string name;
	int lists;
	int __;
	map<string, bool> MAP;
}_[114514];
string S[1145];
signed main(){
	int n = read();
	f(i, 1, n, 1){
		cin >> _[i].name;
		//cout << _[i].name << '\n' << '\n';
		_[i].lists = read();
		//cout << _[i].name << ' ' << _[i].lists;
		f(j, 1, _[i].lists, 1){
			string s;
			cin >> s;
			//cout << " " << s;
			_[i].MAP[s] = 1;
		}
		//cout << _[i].name << ' ' << _[i].lists;
		//cout << '\n';
	}
	int m = read();
	f(I, 1, m, 1){
		printf("Diagnosis #%lld:\n", I);
		int T = read(), MAX = 0;
		f(i, 1, T, 1){
			cin >> S[i];
		}
		f(i, 1, n, 1){
			_[i].__ = 0;
			f(j, 1, T, 1){
				if(_[i].MAP[S[j]] == 1){
					_[i].__++;
					//cout << _[i].__ << '\n';
				}
			}
			MAX = max(MAX, _[i].__);
			//cout << _[i].__ << '\n' << MAX << '\n' << '\n'; 
		}
		f(i, 1, n, 1){
			//cout << _[i].__ << '\n' << '\n';
			if(_[i].__ == MAX){
				cout << _[i].name;
				putchar('\n');
			}
		}
	}
	return 0;
}

给个不用暴力的思路也行/kel

2023/5/1 10:42
加载中...