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 ...
随机推荐
- 使用C++11实现无锁stack(lock-free stack)
前几篇文章,我们讨论了如何使用mutex保护数据及使用使用condition variable在多线程中进行同步.然而,使用mutex将会导致一下问题: 等待互斥锁会消耗宝贵的时间 — 有时候是很多时 ...
- ios浅谈关于nil和 NIL区别及相关问题(转)
转自:http://blog.csdn.net/guozh/article/details/8469131 个就是将引用技术减1,所谓的引用计数就是看看有多个指针指向一块内存实体,当release一次 ...
- Fantageek翻译系列之《使用Autolayout显示变化高度的UITableViewCell》
这篇博客主要在于,解释如何通过仅仅使用Autolayout很很少的代码,显示高度不同的Cell.虽然标题说的是TableView,但是CollectionView同样适合.但是,这种方法只使用iOS7 ...
- 配置错误--分析器错误消息: 无法识别的属性“targetFramework”。请注意属性名称区分大小写。
在部署网站的时候,很容易遇到这个一样错误:分析器错误消息: 无法识别的属性“targetFramework”.请注意属性名称区分大小写. 错误如图: 错误原因: 部署网站时,使用的应用程序池版本不对 ...
- .NET程序猿 - 提升幸福感的组件一览
1.Newtonsoft.Json.net 操作JSON最简便的方式. .Net 3.5开始,Framework集成Json序列化器:JavaScriptSerializer,然而Json.net给 ...
- EF中的约定
优先级:Fluent API >数据注释>约定 CodeFirst约定 主键约定 如果类的属性名为"ID"(不区分大小写)或类名的后面跟有"ID", ...
- ASP.NET 动态编译、预编译和 WebDeployment 项目(转)
概述 在 Web 服务器上,既可以部署源文件,也可以部署编译后程序集. 若部署源文件,则当用户访问时,Web 应用程序会被动态编译,并缓存该程序集,以便下次访问. 否则,若部署程序集,Web 应用程序 ...
- Oracle decode函数 除数为零
decode (expression, search_1, result_1)如果 expression结果=search_1结果,则返回result_1,类似 if elsedecode (expr ...
- 此项目的默认Web访问模式设置为文件共享, 但是无法从路径(此为转贴)
故障现象: 当你打开ASP.NET Web项目时,如果出现这样的错误提示:提示窗口标题: Web访问失败提示内容: 此项目的默认Web访问模式设置为文件共享, 但是无法从路径“...”打开“...”处 ...
- PDO事务管理DEMO
try { $dsn = "mysql:host=127.0.0.1;port=3306;dbname=dab"; $pdo = new PDO($dsn, 'root', '') ...