The Ninth Hunan Collegiate Programming Contest (2013) Problem G
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; ; ...
随机推荐
- mysql中的null字段值的处理及大小写问题
在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...
- Ruby Exception
begin #可能发生异常的地方 rescue #如何处理异常 end rescue,哈哈,太有爱的一个单词了... begin #可能发生异常的地方 rescue => exception # ...
- C# & SQL Server大数据量插入方式对比
以下内容大部分来自: http://blog.csdn.net/tjvictor/article/details/4360030 部分内容出自互联网,实验结果为亲测. 最近自己开发一个向数据库中插入大 ...
- 【Log4j】 log4j.properties 使用
一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session丢失 INFO 为一般要显示的信息,比如 ...
- MIT牛人解说数学体系(转载)
原文网址:http://www.guokr.com/post/442622/ 在过去的一年中,我一直在数学的海洋中游荡,research进展不多,对于数学世界的阅历算是有了一些长进. 为什么要深入数学 ...
- VB中的+与&符号的区别
字符串运算符和字符串表达式 字符串运算符的作用是将两个字符串连接成一个字符串,经常形象的叫做连接符. 在VB中就提供了两种连接用的字符串运算符 “&”.“+” 例如 “VB”+“编程入门” ...
- HTML5 中已经可以用 Ajax 上传文件了,而且代码非常简单,借助 FormData 类即可发送文件数据。
<?phpif (isset($_POST['upload'])) { var_dump($_FILES); move_uploaded_file($_FILES['upfile']['tmp_ ...
- 删除指定的文件.bat
@echo offattrib -s -h -r /s /d C:\*Thumbs.dbattrib -s -h -r /s /d D:\*Thumbs.dbattrib -s -h -r /s /d ...
- mvc 控制器,视图,Razor 语法
mvc 控制器controller:响应用户请求,并修改模型model;输入数据的处理,输出view数据的提供: url入控制器的方法有关联:MVC提供的是方法调用结果: mvc model:是对应用 ...
- [Android Exception A] – 1-The following classes could not be instantiated
http://stackoverflow.com/questions/26575815/the-following-classes-could-not-be-instantiated-android- ...