• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 省赛傻逼题 G

太可怕了!

 

 

Problem G

Time limit: 1.000 seconds

 

 

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

 

 

 1 #include <map>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <iostream>
 6 #include <algorithm>
 7 using namespace std;
 8 #define maxn 1111
 9 #define ll long long
10 int n,m;
11 char s[maxn][11];
12 int main(){
13     while(~scanf("%d",&n)){
14         int t;
15         for(int i=0;i<n;i++)scanf("%s",s[i]);
16         scanf("%d",&t);
17         while(t--){
18             scanf("%d",&m);
19             m--;
20             for(int i=0;i<n;i++){
21                 if(s[m][0]!='?'){printf("%s\n",s[m]);break;}
22                 if(m-i>=0&&m+i<n&&s[m+i][0]!='?'&&s[m-i][0]!='?'){printf("middle of %s and %s\n",s[m-i],s[m+i]);break;}
23                 if(m-i>=0&&s[m-i][0]!='?'&&(m+i>=n||s[m+i][0]=='?')){for(int j=0;j<i;j++)printf("right of ");printf("%s\n",s[m-i]);break;}
24                 if(m+i<n&&s[m+i][0]!='?'&&(m-i<0||s[m-i][0]=='?')){for(int j=0;j<i;j++)printf("left of ");printf("%s\n",s[m+i]);break;}
25             }
26         }
27     }
28     return 0;
29 }
View Code 2013-10-14 15:12:53 

 

 

 

 

posted @ 2013-10-14 15:12  HaibaraAi  阅读(140)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3