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:

  1. 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

  1. 10
  2. A ? ? D ? ? ? H ? ?
  3. 4
  4. 3
  5. 8
  6. 6
  7. 10

Output for the Sample Input

  1. left of D
  2. H
  3. middle of D and H
  4. right of right of H

The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan

  打好基础,顺序查找,没有什么高端算法,就是希望在某些情况下少用各种break ,多用函数return ,这样好一点,少犯些错误。

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <queue>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <vector>
  7. #include <queue>
  8. #include <set>
  9. #include <algorithm>
  10. #include <map>
  11. #include <stack>
  12. #include <math.h>
  13. #define Max(a,b) ((a)>(b)?(a):(b))
  14. #define Min(a,b) ((a)<(b)?(a):(b))
  15. using namespace std ;
  16. typedef long long LL ;
  17. int N ;
  18. string str[] ;
  19. void gao(int id){
  20. if(str[id]!="?"){
  21. cout<<str[id]<<endl ;
  22. return ;
  23. }
  24. int L ,R ;
  25. L=R= ;
  26. int left=id- ;
  27. int right=id+ ;
  28. str[]=str[N+]="?" ;
  29. while(left>=&&str[left]=="?"){
  30. R++ ;
  31. left-- ;
  32. }
  33. while(right<=N&&str[right]=="?"){
  34. L++ ;
  35. right++ ;
  36. }
  37. if(L==R&&str[left]!="?"&&str[right]!="?"){
  38. printf("middle of %s and %s\n",str[left].c_str(),str[right].c_str()) ;
  39. return ;
  40. }
  41. if((str[left]!="?"&&str[right]!="?"&&L>R)||str[right]=="?"){
  42. for(int i=;i<=R;i++)
  43. printf("right of ") ;
  44. cout<<str[left]<<endl ;
  45. return ;
  46. }
  47. if((str[left]!="?"&&str[right]!="?"&&L<R)||str[left]=="?"){
  48. for(int i=;i<=L;i++)
  49. printf("left of ") ;
  50. cout<<str[right]<<endl ;
  51. return ;
  52. }
  53. }
  54. int main(){
  55. int M ,id ;
  56. cin>>N ;
  57. for(int i=;i<=N;i++)
  58. cin>>str[i] ;
  59. cin>>M ;
  60. while(M--){
  61. cin>>id ;
  62. gao(id) ;
  63. }
  64. return ;
  65. }

The Ninth Hunan Collegiate Programming Contest (2013) Problem G的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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. ...

  4. 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: ...

  5. 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, ...

  6. 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 ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

  8. 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 的连续子区间. ...

  9. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

随机推荐

  1. mysql中的null字段值的处理及大小写问题

    在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...

  2. Ruby Exception

    begin #可能发生异常的地方 rescue #如何处理异常 end rescue,哈哈,太有爱的一个单词了... begin #可能发生异常的地方 rescue => exception # ...

  3. C# & SQL Server大数据量插入方式对比

    以下内容大部分来自: http://blog.csdn.net/tjvictor/article/details/4360030 部分内容出自互联网,实验结果为亲测. 最近自己开发一个向数据库中插入大 ...

  4. 【Log4j】 log4j.properties 使用

    一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session丢失 INFO 为一般要显示的信息,比如 ...

  5. MIT牛人解说数学体系(转载)

    原文网址:http://www.guokr.com/post/442622/ 在过去的一年中,我一直在数学的海洋中游荡,research进展不多,对于数学世界的阅历算是有了一些长进. 为什么要深入数学 ...

  6. VB中的+与&符号的区别

    字符串运算符和字符串表达式 字符串运算符的作用是将两个字符串连接成一个字符串,经常形象的叫做连接符. 在VB中就提供了两种连接用的字符串运算符 “&”.“+” 例如  “VB”+“编程入门” ...

  7. HTML5 中已经可以用 Ajax 上传文件了,而且代码非常简单,借助 FormData 类即可发送文件数据。

    <?phpif (isset($_POST['upload'])) { var_dump($_FILES); move_uploaded_file($_FILES['upfile']['tmp_ ...

  8. 删除指定的文件.bat

    @echo offattrib -s -h -r /s /d C:\*Thumbs.dbattrib -s -h -r /s /d D:\*Thumbs.dbattrib -s -h -r /s /d ...

  9. mvc 控制器,视图,Razor 语法

    mvc 控制器controller:响应用户请求,并修改模型model;输入数据的处理,输出view数据的提供: url入控制器的方法有关联:MVC提供的是方法调用结果: mvc model:是对应用 ...

  10. [Android Exception A] – 1-The following classes could not be instantiated

    http://stackoverflow.com/questions/26575815/the-following-classes-could-not-be-instantiated-android- ...