PAT (Advanced) 1075. PAT Judge (25)
2014-03-10 20:45
387 查看
下面这个代码最后一个3分测试样例始终无法通过,搞得人非常无语。如果你发现了其中的bug,请留言告诉我。非常感谢!
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> using namespace std; struct User { int user_id; int rank; int total_score; int problem_score[5]; bool tried_to[5]; bool perfectly_solved[5]; int total_tried; int total_perfect; }user[10001]; bool cmp(const User &a, const User &b) { if (a.total_score != b.total_score) return a.total_score > b.total_score; else { if (a.total_perfect != b.total_perfect) return a.total_perfect > b.total_perfect; else return a.user_id < b.user_id; } } int main() { freopen("in.txt", "r", stdin); int N, K, M; cin >> N >> K >> M; int *full_mark = new int[K]; for (int i = 0; i < K; i++) cin >> full_mark[i]; int u_id, p_id, part_score; for (int i = 0; i < M; i++) { cin >> u_id >> p_id >> part_score; user[u_id - 1].user_id = u_id - 1; if (part_score != -1) { if (part_score > user[u_id - 1].problem_score[p_id - 1]) { user[u_id - 1].total_score = user[u_id - 1].total_score - user[u_id - 1].problem_score[p_id - 1] + part_score; user[u_id - 1].problem_score[p_id - 1] = part_score; } if (part_score == full_mark[p_id - 1]) user[u_id - 1].perfectly_solved[p_id - 1] = true; user[u_id - 1].total_tried++; } user[u_id - 1].tried_to[p_id - 1] = true; } for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { if (user[i].perfectly_solved[j] == true) user[i].total_perfect++; } } sort(user, user + N, cmp); user[0].rank = 0; for (int i = 1; i < N; i++) { if (user[i].total_score == user[i - 1].total_score) user[i].rank = user[i - 1].rank; else user[i].rank = i; } int i = 0; while (user[i].total_tried > 0) { printf("%d %05d %d", user[i].rank + 1, user[i].user_id + 1, user[i].total_score); for (int j = 0; j < K; j++) { if (user[i].tried_to[j] == true) printf(" %d", user[i].problem_score[j]); else printf(" -"); } printf("\n"); i++; } }
相关文章推荐
- PAT (Advanced Level) 1075. PAT Judge (25)
- PAT Advanced 1075. PAT Judge (25)
- PAT (Advanced) 1075. PAT Judge (25)
- PAT (Advanced Level) 1075. PAT Judge (25) PAT排名 结构体排序
- 1075. PAT Judge (25)【排序】——PAT (Advanced Level) Practise
- PAT Advanced Level 1075. PAT Judge (25)
- 【PAT】【Advanced Level】1075. PAT Judge (25)
- Pat(A) 1075. PAT Judge (25)
- PAT - 甲级 - 1075. PAT Judge (25)(排序)
- PAT 1075. PAT Judge (25) 排序题,细节处理题
- PAT 1075. PAT Judge (25) 多重排序。已解决
- PAT-A 1075. PAT Judge (25)
- PAT(A) - 1075. PAT Judge (25)
- 1075. PAT Judge (25) pat的排名算法
- PAT 1075. PAT Judge (25)
- 【PAT】1075. PAT Judge (25)
- PAT 1075. PAT Judge (25)(pat排名)(待修改)
- PAT 甲级 1075. PAT Judge (25)
- PAT 1075. PAT Judge (25)
- 【PAT甲级】1075. PAT Judge (25)