Good Teacher

Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

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
Sample Output
left of D
H
middle of D and H
right of right of H

题解:老师点名,由于一些同学不认识名字,所以要找离他最近的同学代替,题中的I call his CLOSEST student instead;

还有一点就是两个同学中间,但是这两个同学间不能有人。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
string name[];
map<int, string> ans;
int p[];
bool js(int i){
if(ans.count(i) == )
return true;
else
return false;
}
int main(){
int n, q;
while(~scanf("%d", &n)){
int tp = ;
ans.clear();
for(int i = ; i <= n; i++){
cin >> name[i];
if(name[i] != "?"){
ans[i] = name[i];
p[tp++] = i;
}
}
for(int i = ; i < tp - ; i++){
if((p[i + ] + p[i]) % == && js((p[i + ] + p[i])/))
ans[(p[i + ] + p[i])/] = "middle of " + name[p[i]] + " and " + name[p[i + ]]; }
for(int i = ; i <= n; i++){
if(ans.count(i) == ){
int x = lower_bound(p, p + tp, i) - p;
int cnt, cnt1;
if(x == ){
cnt = p[] - i;
while(cnt--){
ans[i] = "left of " + ans[i];
}
ans[i] += name[p[]];
}
else{
cnt = i - p[x - ];
if(x < tp)cnt1 = p[x] - i;
if(x == tp || cnt < cnt1){
while(cnt--){
ans[i] = "right of " + ans[i];
}
ans[i] += name[p[x - ]];
}
else{
while(cnt1--){
ans[i] = "left of " + ans[i];
}
ans[i] += name[p[x]];
}
}
}
}
int q, x;
scanf("%d", &q);
while(q--){
scanf("%d", &x);
cout << ans[x] << endl;
}
}
return ;
}

Good Teacher(模拟)的更多相关文章

  1. 【模拟】HDU 5762 Teacher Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 题目大意: 给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距 ...

  2. 采用dom4j和反射模拟Spring框架的依赖注入功能

    Spring的依赖注入是指将对象的创建权交给Spring框架,将对象所依赖的属性注入进来的行为.在学习了dom4j后,其实也可以利用dom4j和反射做一个小Demo模拟Spring框架的这种功能.下面 ...

  3. js模拟类

    ECMAScript6已经支持了class,但之前版本都不支持类,但是可以通过一些方法来模拟类. js中的类,既是重点,也是难点,很多时候都感觉模棱两可. 首先强调一下js中很重要的3个知识点:thi ...

  4. Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. HDU-1034(简单模拟)

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. C#7.2——编写安全高效的C#代码 c# 中模拟一个模式匹配及匹配值抽取 走进 LINQ 的世界 移除Excel工作表密码保护小工具含C#源代码 腾讯QQ会员中心g_tk32算法【C#版】

    C#7.2——编写安全高效的C#代码 2018-11-07 18:59 by 沉睡的木木夕, 123 阅读, 0 评论, 收藏, 编辑 原文地址:https://docs.microsoft.com/ ...

  7. HDU5399-多校-模拟

    Too Simple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. python模拟老师授课下课情景

    # -*- coding:utf-8 -*- import time class Person(object): ''' 定义父类:人 属性:姓名,年龄 方法:走路(打印:姓名+“正在走路”) ''' ...

  9. Codeforces Round #385 (Div. 2)A B C 模拟 水 并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. Android_HTML解析器_jsoup

    jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据. Jsou ...

  2. poj 3009 Curling 2.0 (dfs )

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11879   Accepted: 5028 Desc ...

  3. NYOJ128 前缀式计算 【栈】

    前缀式计算 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 先说明一下什么是中缀式: 如2+(3+4)*5这样的我们最常见的式子就是中缀式. 而把中缀式按运算顺序加上 ...

  4. 内存测试工具memtester

    Memtester是用户态工具,用于测试内存子系统的故障.非常方便,支持32位 或64位Unix-like系统.对于硬件开发开发者来说,memtester可以定位到物理地址. 1. 安装 下载地址ht ...

  5. ASE中的主要数据库

    Adaptive Server包括多种类型数据库: 必需数据库. “附加功能”数据库 .例子数据库 .应用数据库 1.必需数据库 master 数据库包含系统表,这些系统表中存储的数据被用来管理,有 ...

  6. 关闭程序 提示 C#

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dr = MessageBox ...

  7. AVD启动不了 ANDROID_SDK_HOME is defined but could not find *.ini

    报错提示______________________________________________________________________ Starting emulator for AVD ...

  8. 医院设置 codevs 2577

    Floyd+二叉树 #include<iostream>#include<cstdlib>#include<cstdio>#include<cstring&g ...

  9. K60的DMA多路脉冲计数

    最近在做飞思卡尔的智能车,由于要用到两路脉冲计数,但是由于K60只有3个FTM, 一个分给电机,一个分给舵机,另一个用于正交解码. 所以FTM用不到了,只能另行办法.LPT虽然也可以计数,但是却只能计 ...

  10. GetClientRect()和GetWindowRect()

    GetClientRect()   是得到客户区坐标系下客户区的RECT GetWindowRect()是得到屏幕坐标系下整个窗口的RECT GetSystemMetrics()是获得屏幕分辨率大小 ...