Problem G
Good Teacher
I want to be a good teacher, so at least I need to remember all the student names. However, there are too many students, so I failed. It is a shame, so I don't want my students to know this. Whenever I need to call someone, I call his CLOSEST student instead. For example, there are 10 students:
A ? ? D ? ? ? H ? ?
Then, to call each student, I use this table:
Pos | Reference |
1 | A |
2 | right of A |
3 | left of D |
4 | D |
5 | right of D |
6 | middle of D and H |
7 | left of H |
8 | H |
9 | right of H |
10 | right of right of H |
Input
There is only one test case. The first line contains n, the number of students (1<=n<=100). The next line contains n space-separated names. Each name is either ? or a string of no more than 3 English letters. There will be at least one name not equal to ?. The next line contains q, the number of queries (1<=q<=100). Then each of the next q lines contains the position p (1<=p<=n) of a student (counting from left).
Output
Print q lines, each for a student. Note that "middle of X and Y" is only used when X and Y are both closest of the student, and X is always to his left.
Sample Input
10
A ? ? D ? ? ? H ? ?
4
3
8
6
10
Output for the Sample Input
left of D
H
middle of D and H
right of right of H
The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan
打好基础,顺序查找,没有什么高端算法,就是希望在某些情况下少用各种break ,多用函数return ,这样好一点,少犯些错误。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
int N ;
string str[] ;
void gao(int id){
if(str[id]!="?"){
cout<<str[id]<<endl ;
return ;
}
int L ,R ;
L=R= ;
int left=id- ;
int right=id+ ;
str[]=str[N+]="?" ;
while(left>=&&str[left]=="?"){
R++ ;
left-- ;
}
while(right<=N&&str[right]=="?"){
L++ ;
right++ ;
}
if(L==R&&str[left]!="?"&&str[right]!="?"){
printf("middle of %s and %s\n",str[left].c_str(),str[right].c_str()) ;
return ;
}
if((str[left]!="?"&&str[right]!="?"&&L>R)||str[right]=="?"){
for(int i=;i<=R;i++)
printf("right of ") ;
cout<<str[left]<<endl ;
return ;
}
if((str[left]!="?"&&str[right]!="?"&&L<R)||str[left]=="?"){
for(int i=;i<=L;i++)
printf("left of ") ;
cout<<str[right]<<endl ;
return ;
}
}
int main(){
int M ,id ;
cin>>N ;
for(int i=;i<=N;i++)
cin>>str[i] ;
cin>>M ;
while(M--){
cin>>id ;
gao(id) ;
}
return ;
}
The Ninth Hunan Collegiate Programming Contest (2013) Problem G的更多相关文章
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem A
Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem H
Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem I
Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
-
The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
-
2018 Arab Collegiate Programming Contest (ACPC 2018) G. Greatest Chicken Dish (线段树+GCD)
题目链接:https://codeforces.com/gym/101991/problem/G 题意:给出 n 个数,q 次询问区间[ li,ri ]之间有多少个 GCD = di 的连续子区间. ...
-
German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
随机推荐
-
linux ntp 服务器和用户端
ntp 服务器 1.输入 rpm -qa|grep ntp 查看是否安装了ntp服务器 2.如果没安装 yum -y install ntp 安装 3.修改 /etc/ntp.conf 将原serve ...
-
关于VS2010中一打字,换行,拖控件便出现卡死的问题的解决方案
大家好,这是我第一篇博文. 最近一个月都是静静的观看,想发帖子很久了. 最近实习完刚换了份工作,入职之后啊先是装了一堆软件.然后,便出现问题,就是VS2010上码字和切换页面的时候会卡.开始的时候每次 ...
-
Linq 查询 与方法调用
通常,使用linq查询时需要一个实现IQueryable<T> 的查询对象 public class DataA<T> : IQueryable<T> {....} ...
-
bzoj2006
论将区间和转化为前缀和的重要性这题一旦转化为前缀和就非常明了了一段区间[l,r]的美妙程度就等于s[r]-s[l-1]对于这种无法计算出所有方案而取前k大的题目,我们一般分类别然后利用类别内的单调性用 ...
-
linux命令之crontab定时执行任务
一.crond简介 crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动c ...
-
Python爬虫01——第一个小爬虫
Python小爬虫——贴吧图片的爬取 在对Python有了一定的基础学习后,进行贴吧图片抓取小程序的编写. 目标: 首先肯定要实现图片抓取这个基本功能 然后实现对用户所给的链接进行抓取 最后要有一定的 ...
-
tomcat调试之固定步骤自动化
前端开发,使用tomcat调试,大致需要进行如下几个步骤.其中,第一步,进入项目所在目录敲sbt命令来打包,第二步,拷贝lib文件夹,第四步重启tomcat,反反复复已经让我不胜其烦,那么做个简单的b ...
-
了解java虚拟机—堆相关参数设置(3)
堆相关配置 -Xmx 最大堆空间 -Xms 初始堆空间大小,如果初始堆空间耗尽,JVM会对堆空间扩容,其扩展上限为最大堆空间.通常-Xms与-Xmx设置为同样大小,避免扩容造成性能损耗. -Xmn 设 ...
-
Golang之单元测试
文件名必须以_test.go结尾 使用go test 执行单元测试 例 package main func add(a, b int) int { return a + b } func sub(a, ...
-
scrapy实战2,使用内置的xpath,re和css提取值
以伯乐在线文章为爬取目标blog.jobbole.com,发现在"最新文章"选项中可看到所有文章 一般来说,可以用scrapy中自带的xpath或者css来提取数据,定义在 ...