题目链接:https://vjudge.net/problem/UVA-12412

题目大意

  略。

分析

  比较大规模的模拟,注意输入输出,浮点数精度,还有排名相同的输出顺序,还有一些边界情况处理。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e4 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; MIS courses = {MP(, "Chinese"), MP(, "Mathematics"), MP(, "English"), MP(, "Programming")}; struct Student{
int cid, scores[], tot = ;
string sid, name;
double avg;
};
vector< Student > stu;
MSI id_stu;
int totScores[], slen; // 所有学生的分数数组和在籍学生人数 void printWelcome() {
printf ("Welcome to Student Performance Management System (SPMS).\n\n");
printf ("1 - Add\n");
printf ("2 - Remove\n");
printf ("3 - Query\n");
printf ("4 - Show ranking\n");
printf ("5 - Show Statistics\n");
printf ("0 - Exit\n\n");
} void add() {
string tmp;
while(cin >> tmp) {
printf ("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
if(tmp == "") break;
if(id_stu.find(tmp) != id_stu.end()) {
Rep(i, ) cin >> tmp;
printf ("Duplicated SID.\n");
continue;
}
Student t;
int cnt = ;
t.sid = tmp;
cin >> t.cid >> t.name;
Rep(i, ) {
cin >> t.scores[i];
t.tot += t.scores[i];
t.avg = t.tot / 4.0;
}
totScores[slen++] = -t.tot; id_stu[tmp] = stu.size();
stu.PB(t);
}
} void del() {
string tmp;
while(cin >> tmp) {
printf("Please enter SID or name. Enter 0 to finish.\n");
if(tmp == "") break;
VI t;
if(isdigit(tmp[])) {
if(id_stu.find(tmp) != id_stu.end()) t.PB(id_stu[tmp]);
}
else foreach(i, id_stu) if(tmp == stu[i->sd].name) t.PB(i->sd);
printf ("%d student(s) removed.\n", t.size());
foreach(i, t) {
id_stu.erase(stu[*i].sid);
--slen;
Rep(j, slen) {
if(totScores[j] == -stu[*i].tot) {
swap(totScores[j], totScores[slen]);
break;
}
}
}
}
} void query() {
sort(totScores, totScores + slen);
string tmp;
while(cin >> tmp) {
printf("Please enter SID or name. Enter 0 to finish.\n");
if(tmp == "") break;
VI t;
if(isdigit(tmp[])) {
if(id_stu.find(tmp) != id_stu.end()) t.PB(id_stu[tmp]);
}
else foreach(i, id_stu) if(tmp == stu[i->sd].name) t.PB(i->sd); sort(ALL(t));
foreach(i, t) {
int rank = lower_bound(totScores, totScores + slen, -stu[*i].tot) - totScores + ;
printf("%d %s %d %s %d %d %d %d %d %.2f\n", rank, stu[*i].sid.c_str(), stu[*i].cid, stu[*i].name.c_str(), stu[*i].scores[], stu[*i].scores[], stu[*i].scores[], stu[*i].scores[], stu[*i].tot, stu[*i].avg + EPS);
}
}
} void show_rank() {
printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
} void show_stat() {
int totS[] = {}, len = ;
int passed[] = {}, failed[] = {}, passedN[] = {};
int x;
printf("Please enter class ID, 0 for the whole statistics.\n");
cin >> x; foreach(i, id_stu) {
if(!x || stu[i->sd].cid == x) {
++len;
int cnt = ;
Rep(j, ) {
totS[j] += stu[i->sd].scores[j];
if(stu[i->sd].scores[j] >= ) {
++passed[j];
++cnt;
}
else ++failed[j];
}
++passedN[cnt];
}
} Rep(i, ) {
printf ("%s\n", courses[i].c_str());
if(len) printf ("Average Score: %.2f\n", 1.0 * totS[i] / len + EPS);
else printf ("Average Score: -nan\n");
printf ("Number of passed students: %d\n", passed[i]);
printf ("Number of failed students: %d\n", failed[i]);
printf ("\n");
}
printf ("Overall:\n");
printf ("Number of students who passed all subjects: %d\n", passedN[]);
printf ("Number of students who passed 3 or more subjects: %d\n", passedN[] + passedN[]);
printf ("Number of students who passed 2 or more subjects: %d\n", passedN[] + passedN[] + passedN[]);
printf ("Number of students who passed 1 or more subjects: %d\n", passedN[] + passedN[] + passedN[] + passedN[]);
printf ("Number of students who failed all subjects: %d\n", passedN[]);
printf ("\n");
} void (*func[])() = {add, del, query, show_rank, show_stat}; int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
int op;
while() {
printWelcome();
cin >> op;
if(op == ) break;
func[op - ]();
}
return ;
}

UVA 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)的更多相关文章

  1. UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 题解

    Content 自己去看题面去. Solution 算不上很繁琐的一道大模拟. 首先,既然是输出 \(0\) 才退出,那么在此之前程序应当会执行菜单 \(\Rightarrow\) 子操作 \(\Ri ...

  2. 【例题4-6 uva12412】A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 训练编程的题. 原题中没有除0的数据,所以别担心你的代码是因为除0错了. 多半跟我一样. 也是因为没有+eps 就是比如你要算tot ...

  3. A Typical Homework(学生信息管理系统)

    A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of ...

  4. uva 1567 - A simple stone game(K倍动态减法游戏)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4342">题目链接:uva 1567 - ...

  5. UVa 10025: The ? 1 ? 2 ? ... ? n = k problem

    这道题仔细思考后就可以得到比较快捷的解法,只要求出满足n*(n+1)/2 >= |k| ,且n*(n+1)/2-k为偶数的n就可以了.注意n==0时需要特殊判断. 我的解题代码如下: #incl ...

  6. 【例题 6-4 UVA - 11988】Broken Keyboard (a.k.a. Beiju Text)

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会链表的插入操作的话.这个就不难了. 放置两个哨兵节点. 然后模拟插入一个节点的过程就好. 实时修改光标就好->即下一个插入的 ...

  7. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  8. Radio Basics for RFID

    Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...

  9. [IR] Compression

    关系:Vocabulary vs. collection size Heaps’ law: M = kTbM is the size of the vocabulary, T is the numbe ...

随机推荐

  1. php Excel导出id

    <form action="{:U('Index/files')}" method="post" enctype="multipart/form ...

  2. Delphi流

      一.流的概念 流简单说是建立在面向对象基础上的一种抽象的处理数据的工具,它定义了一些处理数据的基本操作,如读取数据,写入数据等,程序员只需掌握对流进行操作,而不用关心流的另一头数据的真正流向.其实 ...

  3. Perl 哈希

    Perl 哈希 哈希是 key/value 对的集合. Perl中哈希变量以百分号 (%) 标记开始. 访问哈希元素格式:${key}. 以下是一个简单的哈希实例: 实例 #!/usr/bin/per ...

  4. windows启动redis失败

    # Warning: no config file specified, using the default config. In order to specify a config file use ...

  5. NX二次开发-UFUN所有对象类型的宏定义

    /**************************************************************************** Copyright (c) 2010 Sie ...

  6. 微信-小程序-开发文档-服务端-模板消息:templateMessage.addTemplate

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.addTemplate 1.返回顶部 1. templateMessage.addTemplate 本接口应在 ...

  7. due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.jaxen.util.AncestorAxisIt

    七月 31, 2019 4:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Server version: Apac ...

  8. CometOJ Contest #3 C

    题目链接:https://cometoj.com/contest/38/problem/C?problem_id=1542&myself=0&result=0&page=1&a ...

  9. csv转字典

    with open('filename','r') as csv_f: reader = csv.reader(csv_f) fieldnames = next(reader) csv_reader ...

  10. USACO2008 Roads Around The Farm /// queue oj23321

    题目大意: N (1 ≤ N ≤ 1,000,000,000)牛群在遇到岔路时,若能分为恰好相差 K (1 ≤ K ≤ 1000)的两路,则持续分裂(假设会一直遇到岔路),否则停止开始吃草. Inpu ...