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(模拟)的更多相关文章
- 【模拟】HDU 5762 Teacher Bo
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 题目大意: 给n个点,坐标范围0~m(n,m<=105),求是否存在2个点对满足哈夫曼距 ...
- 采用dom4j和反射模拟Spring框架的依赖注入功能
Spring的依赖注入是指将对象的创建权交给Spring框架,将对象所依赖的属性注入进来的行为.在学习了dom4j后,其实也可以利用dom4j和反射做一个小Demo模拟Spring框架的这种功能.下面 ...
- js模拟类
ECMAScript6已经支持了class,但之前版本都不支持类,但是可以通过一些方法来模拟类. js中的类,既是重点,也是难点,很多时候都感觉模棱两可. 首先强调一下js中很重要的3个知识点:thi ...
- 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 ...
- HDU-1034(简单模拟)
Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 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/ ...
- HDU5399-多校-模拟
Too Simple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- python模拟老师授课下课情景
# -*- coding:utf-8 -*- import time class Person(object): ''' 定义父类:人 属性:姓名,年龄 方法:走路(打印:姓名+“正在走路”) ''' ...
- 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 ...
随机推荐
- Wince修改系统时间问题
当我们需要修改到系统时间的时候,需要用到下面四个函数:SetLoaclTime,GetLocalTime,SetSystemTime,GetSystemTime.这四个函数是用来修改或者 ...
- Cortex-A9 UART
一.Exynos4412 UART 的特性 Exynos4412 中UART,有4 个独立的通道,每个通道都可以工作于中断模式或DMA 模式,即 UART 可以发出中断或 DMA 请求以便在UART ...
- SpringTest2
Spring 框架第二天 AOP切面编程 今天重点内容: 1. 什么是AOP ? AOP实现原理是怎样的? AOP相关术语 2. AOP底层实现 (了解) ----- JDK动态代理. Cglib动态 ...
- Linq to Entities不识别方法
db.UserValidates.Include(a => a.User).Where(uv => u.UserValidates.Contains(uv, c)).ToList(); 执 ...
- WebApi2官网学习记录---单元测试
如果没有对应的web api模板,首先使用nuget进行安装 例子1: ProductController 是以硬编码的方式使用StoreAppContext类的实例,可以使用依赖注入模式,在外部指定 ...
- Lanucherr 默认显示第几屏
Launcher.java static final int SCREEN_COUNT = 5;static final int DEFAULT_SCREEN = 2;//第一页是从0开始计数,这里是 ...
- 0301——UItableView
- (void)viewDidLoad { [super viewDidLoad]; self.myTableView = [[UITableView alloc]initWithFrame:CGRe ...
- window.open() | close()方法
Window对象的open()方法可以打开一个新的浏览器窗口(或标签页),window.open()载入指定的URL到新的或已存在的窗口中,返回代表那个窗口的window对象,它有4个可选的参数 1. ...
- <c:if>标签
<c:if>的用途就和我们一般在程序中用的if一样. 语法 语法1:没有本体内容(body) <c:if test="testCondition" var=&qu ...
- 转载:CPU的位数和操作系统的位数
1. 32位系统最大只能使用3.5G的内存,而64位系统最大能够使用128G内存. 2. 32位CPU只能安装和使用32位.16位的系统和软件,无法使用64位系统及软件. 3. 64位可以安装64位系 ...