Problem A
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的
考生,并将他们的成绩按降序打印。
Input
< 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一
名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
Output
到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考
号的升序输出。
Sample Input
4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0
Sample Output
3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20
Hint
Huge input, scanf is recommended.
#include "iostream"
#include "stdio.h"
#include "algorithm"
#include <string.h>
using namespace std;
const int MAXN = 11;
const int MAX = 22;
int point[MAXN];
struct Student
{
char num[MAX];
int pro_num[MAXN];
int pnt ;
};
bool cmp(const Student &a,const Student &b)
{
if (a.pnt == b.pnt)
return strcmp(a.num,b.num) < 0 ? 1 : 0;
else return a.pnt > b.pnt;
}
int main()
{
int N, sum;
while (scanf("%d",&N) != EOF)
{
sum = 0;
if (N == 0) break;
int M, G;
scanf("%d%d",&M,&G);
int i;
int max;
for(i = 0; i < M; i++)
{
scanf("%d",&point[i]);
}
Student stu[1001];
for(i = 0; i < N; i ++)
{
scanf("%s",&stu[i].num);
stu[i].pnt = 0;
int slv, j;
scanf("%d",&slv);
for (j = 0; j < slv; j++)
{
scanf("%d",&stu[i].pro_num[j]);
stu[i].pnt = stu[i].pnt + point[stu[i].pro_num[j] - 1];
}
}
for (i = 0; i < N; i++)
{
if (stu[i].pnt >= G) sum++;
}
printf("%d\n",sum);
sort (stu,stu + N,cmp);
for (i = 0; i < sum; i++)
{
printf("%s %d\n", stu[i].num,stu[i].pnt);
}
}
system ("pause");
return 0;
}
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
7 2 23 12 -4 3
Sample Output
111 1B -11
#include <cstdlib>
using namespace std;
void change(int n,int r)
{
if(n < r)
{
if(n == 10)
printf("A");
else if(n == 11)
printf("B");
else if(n == 12)
printf("C");
else if(n == 13)
printf("D");
else if(n == 14)
printf("E");
else if(n == 15)
printf("F");
else
printf("%d",n);
}
else
{
change(n / r,r);
change(n % r ,r);
}
}
int main()
{
int n,r;
while(scanf("%d%d",&n,&r) != EOF)
{
if(n < 0)
{
n *= -1;
printf("-");
}
change(n,r);
printf("\n");
}
return 0;
}
Problem C
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
![](https://i-blog.csdnimg.cn/blog_migrate/e07a7819adc3fce5ee075d011a0a1d3a.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/3ed5e24625225c0a75f84ac6dbeceabe.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/b72889e34d63c9ba1c9624e8d50888c9.jpeg)
Input
Output
Sample Input
3 123 321 3 123 312
Sample Output
Yes. in in in out out out FINISH No. FINISH
Hint
For the first Sample Input, we let train 1 get in, then train 2 and train 3.
So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.
Now we can let train 3 leave.
But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.
So we output "No.".
#include<stack>
#include<cstring>
using namespace std;
int main(){
int n,j,i,k,flag[50];
char in[15],out[15];//入栈顺序和出栈顺序
while(~scanf("%d %s %s",&n,in,out)){
stack <char> sta;
memset(flag,-1,sizeof(flag));//为1表示压入栈,为0表示输出栈,记录进出栈过程
j=k=0;
for(i=0;i<n;i++){//输入的位置的变化
sta.push(in[i]);//入栈
flag[k++]=1;
while(!sta.empty()&&sta.top()==out[j]){//当栈不空并且栈顶元素与当前要出栈元素相等时出栈,否者入栈
flag[k++]=0;//为0表示输出栈
j++;
sta.pop();
}
}
if(j==n){
printf("Yes.\n");
for(i=0;i<k;i++){
if(flag[i]) printf("in\n");//为1表示压入栈,为0表示输出栈
else printf("out\n");
}
}
else printf("No.\n");
printf("FINISH\n");
}
return 0;
}
Problem D
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
1 + 2 4 + 2 * 5 - 7 / 11 0
Sample Output
3.00 13.36
#include<cstring>
#include<stack>
using namespace std;
stack <double> num;//数字栈
stack <char> sta;//字符栈
double math(char c){//变量为识别的运算符
double a,b;//结果
a=num.top(); num.pop();
b=num.top(); num.pop();
switch(c){
case '*': return b*a;
case '/': return b/a;
case '+': return b+a;
case '-': return b-a;
}//注意这里 a,b 顺序不能反
}//只进行一次运算
int main(){
char oper,str[210];
int len,i;
double nnum;
memset(str,0,sizeof(str));
while(gets(str)&&strcmp(str,"0")!=0){
len=strlen(str);
/********************** for *******************/
for(i=0;i<len;i++){
while(str[i]==' ') i++; //略过空格
/************下面为转换数字**********/
nnum=0;
while(str[i]>='0'&&str[i]<='9'&&i<len){
nnum=nnum*10+str[i]-'0';
i++;
} //将数字由char转换为double
num.push(nnum); //数字进栈
/************下面为略过空格**********/
while(str[i]==' ') i++;//略过空格
/************下面为判断操作符**********/
if(str[i]=='+'||str[i]=='-'){
while(!sta.empty()){
num.push(math(sta.top()));
sta.pop();
}
sta.push(str[i]);
}//运算符为‘+’,‘-’就清栈
else if(str[i]=='*'||str[i]=='/'){
if(!sta.empty()&&(sta.top()=='*'||sta.top()=='/')){
num.push(math(sta.top()));
sta.pop();
}
sta.push(str[i]);
}//运算符为‘*’,‘/’时,先判断前方是否是‘*’,‘/’,若是就按运算顺序算前一个运算符,否者此运算符进栈
}
/*********************** for *************************/
while(!sta.empty()){
nnum=math(sta.top());
sta.pop();
num.push(nnum);
}//清空剩余栈
printf("%.2lf\n",num.top());
num.pop();
memset(str,0,sizeof(str));
}
return 0;
}
Problem E
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。
现在就请你帮助医院模拟这个看病过程。
Input
每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
接下来有N行分别表示发生的事件。
一共有两种事件:
1:"IN A B",表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
2:"OUT A",表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)
Output
诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从1开始编号。
Sample Input
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
Sample Output
2 EMPTY 3 1 1
#include<string.h>
#include<stdlib.h>
struct patient{//病人信息数据结构定义;
int id;//病人编号;
int prior;//病人优先级;
}p[3][2001];//3个队列,对应3个医生;
int main(){
int N;
while(scanf("%d",&N)!=EOF){
int i,j,cnt=0;//记录病人编号;
int count[3]={0};//记录各医生队列长度;
for(i=0;i<N;i++){
int A,B;//A:医生,B:优先级;
char s[4];
getchar();//接受回车符;
scanf("%s",s);
if(strcmp(s,"IN")==0){//输入IN事件;
scanf("%d %d",&A,&B);
//printf("%s %d %d/n",s,A,B);
cnt++;//病人编号增1;
//printf("%d**********/n",cnt);
if(count[A-1]==0){//病人队列为空;
p[A-1][0].id=cnt;
p[A-1][0].prior=B;
}
else{
for(j=count[A-1]-1;j>=0;j--){//数组元素移动;
if(p[A-1][j].prior>=B)break;
p[A-1][j+1].id=p[A-1][j].id;
p[A-1][j+1].prior=p[A-1][j].prior;
}
//插入病人记录;
p[A-1][j+1].id=cnt;
p[A-1][j+1].prior=B;
}
count[A-1]++;//病人队列长度增加1;
}
else{
scanf("%d",&A);
if(count[A-1]==0){//医生A队列空;
printf("EMPTY\n");
}
else{
printf("%d\n",p[A-1][0].id);
for(j=0;j<count[A-1]-1;j++){
p[A-1][j].id=p[A-1][j+1].id;
p[A-1][j].prior=p[A-1][j+1].prior;
}
p[A-1][count[A-1]].id=0;
p[A-1][count[A-1]].prior=0;
count[A-1]--;//病人数量减一;
}
}
}
}
}
Problem F
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
用()表示一个盒子,B表示礼物,Vayko想让你帮她算出愚人指数,即最少需要拆多少个盒子才能拿到礼物。
Input
每组测试包含一个长度不大于1000,只包含'(',')'和'B'三种字符的字符串,代表Vayko设计的礼物透视图。
你可以假设,每个透视图画的都是合法的。
Output
Sample Input
((((B)()))()) (B)
Sample Output
4 1
int main()
{ int i,n;
char a[1000];
while(scanf("%s",&a)!=EOF){
for(i=0,n=0;;i++)
{ if(a[i]==')') n--;
if(a[i]=='(') n++;
if(a[i]=='B') break;}
printf("%d\n",n);}}
Problem G
Time Limit : 1000/500ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
Output
Sample Input
1 100
Sample Output
1 5050
int main()
{
int n,sum;
while(scanf("%d",&n)!=EOF)
{
if(n%2==0)
sum=n/2*(n+1);
else
sum=(n+1)/2*n;
printf("%d\n\n",sum);
}
return 0;
}