CF1201A Important Exam
题目大意
有 \(n(1 \le n \le 1000)\) 个学生在考试,共有 \(m(1 \le m \le 1000)\) 道单选题,每道单选题的待选项均为 \(A~B~C~D~E\)。
每道单选题的分值为 \(a_{i}(1 \le a_{i} \le 1000)\)。现在给出第 \(i\) 个学生的作答 \(s_{i}(\) 保证 \(s_{i}\) 的长度为 \(m\),且每道单选题均已作答 \()\),\(s_{i}\) 的第 \(j\) 个字母代表学生 \(i\) 在第 \(j\) 个选择题的作答选项。
求 \(n\) 个学生的总分的最大值是多少。
题目分析
我们要求总分的最大值,自然要让所有答题者每道题出现频度最高的选项成为答案。
所以我们统计一下每个学生做第 \(i\) 到题时 \(A,B,C,D\) 和 \(E\) 出现的个数。
求出第 \(i\) 道题出现次数最多的字母,选之即可。最后每道题的最大分值的和即为答案。
代码
//2021/11/18
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <climits>//need "INT_MAX","INT_MIN"
#include <algorithm>
#include <cstring>
#define enter() putchar(10)
#define debug(c,que) cerr<<#c<<" = "<<c<<que
#define cek(c) puts(c)
#define blow(arr,st,ed,w) for(register int i=(st);i<=(ed);i++)cout<<arr[i]<<w;
#define speed_up() std::ios::sync_with_stdio(false)
namespace Newstd
{
inline int read()
{
char c;
bool flag=false;
while((c=getchar())<'0' || c>'9')
{
if(c=='-') flag=true;
}
int res=c-'0';
while((c=getchar())>='0' && c<='9')
{
res=(res<<3)+(res<<1)+c-'0';
}
return flag?-res:res;
}
inline void print(int x)
{
if(x<0)
{
putchar('-');x=-x;
}
if(x>9)
{
print(x/10);
}
putchar(x%10+'0');
}
}
using namespace Newstd;
using namespace std;
const int MA=1005;
char mp[MA][MA];
int a[MA];
int n,m;
int main(void)
{
speed_up();
cin>>n>>m;
for(register int i=1;i<=n;i++)
{
cin>>mp[i];
}
for(register int i=1;i<=m;i++)
{
cin>>a[i];
}
int ans(0);
for(register int i=0;i<m;i++)
{
static int cnt[105];
memset(cnt,0,sizeof(cnt));
for(register int j=1;j<=n;j++)
{
cnt[mp[j][i]]++;
}
ans+=a[i+1]*max({cnt['A'],cnt['B'],cnt['C'],cnt['D'],cnt['E']});
}
printf("%d\n",ans);
return 0;
}

浙公网安备 33010602011771号