解题代码
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
struct que {
int weight, sum, cnt;
set< char > s;
} q[ 100 ] ;
struct wrong {
int index, cnt;
} w[ 100 ] ;
bool cmp ( wrong a, wrong b) {
if ( a. cnt != b. cnt) return a. cnt > b. cnt;
return a. index < b. index;
}
int main ( ) {
int n_stu, n_que, temp, M = 0 ;
char c;
scanf ( "%d %d" , & n_stu, & n_que) ;
for ( int i = 0 ; i < n_que; i++ ) {
scanf ( "%d %d %d" , & q[ i] . weight, & q[ i] . sum, & q[ i] . cnt) ;
for ( int j = 0 ; j < q[ i] . cnt; j++ ) {
scanf ( " %c" , & c) ;
q[ i] . s. insert ( c) ;
}
}
for ( int i = 0 ; i < 100 ; i++ ) w[ i] . index = i + 1 ;
for ( int i = 0 ; i < n_stu; i++ ) {
int score = 0 ;
for ( int j = 0 ; j < n_que; j++ ) {
getchar ( ) ; getchar ( ) ;
scanf ( "%d" , & temp) ;
set< char > s1;
for ( int k = 0 ; k < temp; k++ ) {
getchar ( ) ;
scanf ( "%c" , & c) ;
s1. insert ( c) ;
}
getchar ( ) ;
if ( s1 != q[ j] . s) {
w[ j] . cnt++ ;
M = max ( w[ j] . cnt, M) ;
}
else score + = q[ j] . weight;
}
if ( i) printf ( "\n" ) ;
printf ( "%d" , score) ;
}
if ( M) {
printf ( "\n%d" , M) ;
sort ( w, w + n_que, cmp) ;
for ( int i = 0 ; i < n_que; i++ ) {
if ( w[ i] . cnt != M) break ;
printf ( " %d" , w[ i] . index) ;
}
}
else printf ( "\nToo simple" ) ;
return 0 ;
}
测试结果
问题整理
1.不太基础的题目。
2.得知一位名叫柳神的算法大佬。
3.该题可以借鉴的优秀代码片段:
vector< set< char >> right ( m) ;
vector< int > total ( m) , wrongCnt ( m) ;