UVA 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
题目链接: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)的更多相关文章
- UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 题解
Content 自己去看题面去. Solution 算不上很繁琐的一道大模拟. 首先,既然是输出 \(0\) 才退出,那么在此之前程序应当会执行菜单 \(\Rightarrow\) 子操作 \(\Ri ...
- 【例题4-6 uva12412】A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 训练编程的题. 原题中没有除0的数据,所以别担心你的代码是因为除0错了. 多半跟我一样. 也是因为没有+eps 就是比如你要算tot ...
- A Typical Homework(学生信息管理系统)
A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of ...
- uva 1567 - A simple stone game(K倍动态减法游戏)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=4342">题目链接:uva 1567 - ...
- UVa 10025: The ? 1 ? 2 ? ... ? n = k problem
这道题仔细思考后就可以得到比较快捷的解法,只要求出满足n*(n+1)/2 >= |k| ,且n*(n+1)/2-k为偶数的n就可以了.注意n==0时需要特殊判断. 我的解题代码如下: #incl ...
- 【例题 6-4 UVA - 11988】Broken Keyboard (a.k.a. Beiju Text)
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会链表的插入操作的话.这个就不难了. 放置两个哨兵节点. 然后模拟插入一个节点的过程就好. 实时修改光标就好->即下一个插入的 ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- Radio Basics for RFID
Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...
- [IR] Compression
关系:Vocabulary vs. collection size Heaps’ law: M = kTbM is the size of the vocabulary, T is the numbe ...
随机推荐
- JAVA SE Download
{ //https://www.oracle.com/technetwork/java/javase/downloads/index.html }
- (转)OC学习笔记 @property的属性 strong 和 weak 理解
在ObjectiveC里,用@property访问所有的实例变量.@property有一对属性:strong 和 weak.官方文档里的解释晦涩难懂:Stack Overflow里的用户RDC (ht ...
- Java--会移动、反弹的球
package firstpack; import java.awt.*; public class MyStar { public static void main(String[] args) { ...
- git学习记录1(本地库管理)
学习参考地址:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 本编随笔只是自己对 ...
- Spring源码由浅入深系列三 refresh
spring中的refresh是一个相当重要的方法.它完成IOC的第一个阶段,将xml中的bean转化为beanDefinition.详细说明如上图所示. 在上图中,创建obtainFreshBean ...
- CodeForces 1152F2 Neko Rules the Catniverse (Large Version)
题目链接:http://codeforces.com/problemset/problem/1152/F2 题目大意 见http://codeforces.com/problemset/problem ...
- CVE-2017-3248简单复现
我是这样操作的 目标跟windows在一个段,linux是另一个段的,我的虚拟机 windows主机上 `java -cp ysoserial.jar ysoserial.exploit.JRMPLi ...
- Spring 源码学习——注册 BeanDefinition
BeanFactory BeanFactory 是 Spring IoC 容器的具体实现,是 Spring 容器的核心接口. DefaultListableBeanFactory XmlBeanFac ...
- Mybatis 使用的 9 种设计模式,真是太有用了~
Java技术栈 ) { name = fullname.substring(0, delim); children = fullname.substring(delim + 1); ...
- 线性可分SVM中线性规划问题的化简
在网上找了许多关于线性可分SVM化简的过程,但似乎都不是很详细,所以凭借自己的理解去详解了一下. 线性可分SVM的目标是求得一个超平面(其实就是求w和b),在其在对目标样本的划分正确的基础上,使得到该 ...