online_judge_1005
2015-12-04 16:17
357 查看
#include <iostream> #include <algorithm> using namespace std; struct Student { int school[101]; int GE,GI,GS; int id; bool operator < (const Student &A) const { return !(GS<A.GS || (GS==A.GS && (GE<A.GE))); } bool operator == (const Student &A) const { if(GE == A.GE && GI == A.GI) { for(int i=0; i<101; ++i) { if(school[i] != A.school[i]) return false; } return true; } return false; } }stu[40001]; struct Result { int schoolID; int studentID; bool operator < (const Result &A) const { return (schoolID < A.schoolID || (schoolID == A.schoolID && studentID < A.studentID)); } }result[40001]; int main() { int n,m,k; int i,j,t,h; int a[101]; while(cin>>n>>m>>k) { for(i=0; i<m; ++i) cin>>a[i]; for(i=0; i<n; ++i) { cin>>stu[i].GE>>stu[i].GI; stu[i].id = i; stu[i].GS = stu[i].GE + stu[i].GI; for(j=0; j<101; ++j) stu[i].school[j] = -1; for(j=0; j<k; ++j) cin>>stu[i].school[j]; } sort(stu, stu+n); h = 0; for(i=0; i<n; ++i) { for(j=0; j<k; ++j) { t = stu[i].school[j]; if(a[t] > 0) { a[t]--; result[h].schoolID = t; result[h].studentID = stu[i].id; ++h; break; } else if(a[t] == 0) { //int s = result[h-1].studentID; if(i == 0) break; if(stu[i-1] == stu[i]) { result[h].schoolID = result[h-1].schoolID; result[h].studentID = stu[i].id; ++h; break; } } } } sort(result, result+h); t = 0; int flag; for(i=0; i<m; ++i) { flag = 0; while(t<h && result[t].schoolID == i) { if(flag++ == 0) { cout<<result[t].studentID; } else cout<<" "<<result[t].studentID; t++; } cout<<endl; } } return 0; }
花了一个半小时才做出来这题,真是太激动了。这个题目以前就不会做。。这次一次通过,很激动……虽然代码写的很乱,但是我的思维还是比较清晰的。。
很多时候真是缺乏锻炼,总是想的多,做得少,这是病,得治。。继续努力。
相关文章推荐
- NSData、 UIImage、ALAsset之间的关系和转化
- C# 使用 StructLayoutAttribute 时 C# /C++ 内存空间分配与成员对齐问题
- ARM和嵌入式系统开发
- No resource found that matches the given name 9png
- Android URI简介
- 百宝云Json与数组新手教程专题解析
- ios开发之消息推送(以信鸽推送为例)
- java网络编程一
- android(12)(简单学生管理系统,包括文件写入SD卡,pull解析xml文件等)
- 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!
- setsockopt()函数使用
- FreeType字体知识
- PyQt5教程(一)——第一个PyQt5程序
- HFSS学习
- iOS开发-多线程-线程安全
- hdu 1397 (素数判定)
- SCP报错:Host key verification failed
- Gulp安装及配合组件构建前端开发一体化(转)
- 8天学通MongoDB——第三天 细说高级操作
- 三级联动(省市区)