1073 多选题常见计分法 (20 分)

1073 多选题常见计分法 (20 分)

题意描述:

批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。

输入格式:

输入在第一行给出两个正整数 N(≤1000)和 M(≤100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 (选中的选项个数 选项1 ……),按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。

输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后 1 位。最后输出错得最多的题目选项的信息,格式为:错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 Too simple。

输入样例 1:

3 4 
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)

输出样例 1:

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

输入样例 2:

2 2 
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

输出样例 2:

5.0
5.0
Too simple

解题思路:
Bob: 啊,又超时了,!!!∑(゚Д゚ノ)ノ
Alice: emm, 我觉得你是已经碰到了天花板了,你该再学点Python了,自己总结一下怎么才能把Python程序写的更快,更简洁,更优雅。
Bob: 你说的对,不过这可能要比较长的时间了,现在是处在瓶颈期了。
Alice: ヾ(◍°∇°◍)ノ゙加油。


Bob: 我昨天把这题做出来了!!
Alice: 用的C++,以前的代码有Bug吗?
Bob: 对,以前的代码应该是有Bug的,有一种情况没有考虑到。就是错误最多的题目分两种,一种是学生选了错误的选项,另一种是正确的选项学生没有选。
Alice: 之前的代码没有考虑第二种情况:正确的选项学生没有选!!
Bob: 对,奇怪的是这份代码应该没法通过题目里给的第一个测试样例的,但是提交结果居然只有超时!
Alice: 说明在报错之前,超时了。
Bob: 嗯嗯,现在来看,我把这题写复杂了,后面的那个排序是不必要的。而且,改卷子的逻辑也没有写清楚。
Alice: 快给我看看新的代码,ヽ(゚∀゚)メ(゚∀゚)ノ
Bob: 好,有时间我要把Python这份重新以下,超时不是语言的锅,┓( ´∀` )┏。
Bob: 没写注释,看起来会有点辛苦。


代码:

  • Python Version:
from functools import cmp_to_key


def main():
    N, M = (int(x) for x in input().split())
    std_answer = []
    tot_scores = []
    for x in range(M):
        temp = [z for z in input().split()]
        tot_scores.extend([int(temp[0])])
        std_answer.extend([set(temp[3:])])
        
    wrongs = {}
    for index, _ in enumerate(std_answer):
        for x in std_answer[index]:
            wrongs["{}{}".format(index + 1, x)] = N


    for x in range(N):
        stu_answer = get_stu_answer(input())
        score = 0.0

        for index, _ in enumerate(stu_answer):
            if stu_answer[index] == std_answer[index]:
                score += tot_scores[index]
            elif stu_answer[index] < std_answer[index]:
                score += tot_scores[index] / 2.0

            for char in stu_answer[index]:
                temp_key = "{}{}".format(index + 1, char)
                if char not in std_answer[index]:
                    wrongs.setdefault(temp_key, 0)
                    wrongs[temp_key] += 1
                else:
                    wrongs[temp_key] -= 1
        print("{:.1f}".format(score))

    max_value = wrongs[max(wrongs, key=wrongs.get)]
    if max_value == 0:
        print("Too simple")
    else:
        ready = []
        for key in wrongs:
            if wrongs[key] == max_value:
                ready.extend([[int(key[0]), key[1]]])
        answers = sorted(ready, key=cmp_to_key(compare), reverse=False)
        for answer in answers:
            print("{} {}-{}".format(max_value,
                                    answer[0], answer[1]))


def compare(a, b):

    if a[0] != b[0]:
        return a[0] - b[0]
    else:
        if a[1] < b[1]:
            return -1
    return 1


def get_stu_answer(string):
    # 从string中提取出一位学生的答案,返回一个set的列表,每一个set存储一道题的答案。
    answer = []
    for x in string:
        if x == '(':
            flag = True
            temp = set()
            continue

        if flag:
            if is_alphabet(x):
                temp.add(x)

        if x == ')':
            answer.extend([temp])
            flag = False
            
    return answer


def is_alphabet(x):
    # 判断一个字符是不是英文小写字母
    return ord(x) >= ord('a') and ord(x) <= ord('z')

if __name__ == '__main__':
    main()

  • C++ Version:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

#define QUESTION_N 100
#define STUDENT_N 1000

int answers[QUESTION_N][8];
int error_recorder[QUESTION_N][5];
int stu_answers[QUESTION_N][5];
float stu_scores[STUDENT_N]; 

int main(void){
	
	//freopen("in.txt", "r", stdin);
	
	int N;
	int M;
	int std_score;
	int option_n;
	int std_option_n;
	char std_option;
	
	scanf("%d %d", &N, &M);
	
	for(int i=0; i<M; ++i){
		scanf("%d %d %d", &std_score, &option_n, &std_option_n);
		
		answers[i][0] =  std_score;
		answers[i][1] =  option_n;
		answers[i][2] =  std_option_n;
		
		for(int j=0; j<std_option_n; ++j){
			scanf(" %c", &std_option);     // mind the input with a space
			answers[i][int(std_option) - int('a') + 3] = 1;
		}
	}
	
	
	char line_feed[10];
	//gets(line_feed);
	cin.getline(line_feed, 10);
	
	string stu_answer;
	int question_index = 0;
	for(int i=0; i<N; ++i){
		getline(cin, stu_answer);
		question_index = 0;
		// vetcorize the student answer
		for(int j=0; j<stu_answer.length(); ++j){
			if(stu_answer[j] == ')'){
				question_index += 1;
			}else if(int(stu_answer[j]) >= 'a' && int(stu_answer[j]) <= 'e'){
				stu_answers[question_index][int(stu_answer[j]) - int('a')] = 1;
			} 
		}

		int correct_option_n;
		bool cannot;
		
		for(int k=0; k<M; ++k){
			correct_option_n = 0;
			cannot = false;
			for(int j=0; j<5; ++j){
				if(stu_answers[k][j] == 1 && answers[k][j+3] == 1){
					if(cannot == false){
					    correct_option_n++;	
					}
				}else if(stu_answers[k][j] == 1 && answers[k][j+3] != 1){
					error_recorder[k][j]++;
					correct_option_n = 0; 
					cannot = true;       // one false option, zero score, no more add.
				    //break; not ok
				}else if(stu_answers[k][j] == 0 && answers[k][j+3] == 1){
					error_recorder[k][j]++;
				}
				
			}
			
			if(correct_option_n == 0){
				;
			}else if(correct_option_n < answers[k][2]){
				stu_scores[i] += answers[k][0] / 2.0;
			}else if(correct_option_n == answers[k][2]){
			    stu_scores[i] += answers[k][0];
			}
			
		}
		printf("%.1f\n", stu_scores[i]);
		memset(stu_answers, 0, sizeof(stu_answers));
	} 
	int max_error_n = 0;
	for(int i=0; i<M; ++i){
		for(int j=0; j<5; ++j){
			if(error_recorder[i][j] > max_error_n){
				max_error_n = error_recorder[i][j];
			}
		}
	}
	if(max_error_n > 0){
		for(int i=0; i<M; ++i){
			for(int j=0; j<5; ++j){
				if(error_recorder[i][j] == max_error_n){
					printf("%d %d-%c\n", max_error_n, i+1, char(j+int('a')));
				}
			}
		}
	}else{
		printf("Too simple\n");
	}
	
	return 0;
} 

易错点:

  • 题目的编号可能是两位数,上面的代码应该是有bug的,(ᇂдᇂ )ノ┬─┬ノ┻━┻ ,(扶我起来,我还能改,(¦3」∠)
  • 用Python 容易超时啊 😭 。

总结:

  • 待定
  • 待定
    answer

海


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值