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 ...
随机推荐
- 【git 问题小说说】 git add时候报错:LF will be replaced by CRLF
本文来自:http://blog.csdn.net/loovejava/article/details/22114477 最近工作在window平台,不怎么使用命令行了所以导致很多命令都不熟悉啦 哈哈 ...
- Lrc歌词批量下载助手 MP3歌词批量下载助手
Lrc歌词批量下载助手 MP3歌词批量下载助手 易歌词的服务器已经挂掉,各个主流播放器已不提供明确的下载Lrc服务,当上G的MP3文件遇上苦逼的播放器,二缺就诞生了!本软件就是在这种背景下诞生的 ...
- Python一日一练05----怒刷点击量
功能 自己主动获取CSDN文章列表,并对每篇文章添加点击量. 源代码 import urllib.request import re import time import random from bs ...
- HeadFirst设计模式 之 C++实现(二):Observer(观察者模式)
观察者模式是最经常使用的设计模式之中的一个,[对象之间多对一的依赖关系,当一个对象发生变化时,其会通知全部依赖它的对象].拿订阅报纸和发行报社打例如,报社採集到news制作新的报纸,派送给订阅的客户. ...
- traceroute原理
traceroute原理 ICMP ICMP全称为Internet Control Message Protocol,即,网络控制报文协议. 当一个IP数据报发送失败时,最后一个路由器会向发送发传递一 ...
- js数字精度丢失
http://www.cnblogs.com/snandy/p/4943138.html
- C# XML,XmlDocument简单操作实例
private static string _Store = LocalPathHelper.CurrentSolutionPath + "/data/bookstore.xml" ...
- Gson 简易笔记
#Gson 简易笔记 之前用 fastjson.它连个规矩的文档都没有,而且在github的wiki上写着: gson的g可能是"龟"拼音的缩写,龟速的json库." 各 ...
- FineUI控件之树的应用(二)
一.Tree控件应用 <f:PageManager ID="PageManager1" runat="server" /> <f:Tree I ...
- PDO事务管理DEMO
try { $dsn = "mysql:host=127.0.0.1;port=3306;dbname=dab"; $pdo = new PDO($dsn, 'root', '') ...