ZOJ 3492 模拟循环链表线性查找
WA了好几次最后找到错因是因为数组开小了! = =
string whose length never exceeds 20
所以至少要开到21 = = ,我却一直开20 ╮(╯▽╰)╭
AC代码:
#include <stdio.h>
#include <string.h>
int main(){
int t,n,i,j,flag;
char target[],name[][];
scanf("%d",&t);
while(t--){
scanf("%d%s",&n,target);
for(i=;i<n;i++)
scanf("%s",name[i]);
for(i=;i<n;i++)
if(strcmp(name[i],target) == ) break;
flag = (i + n/)%n;
printf("%s\n",name[flag]);
}
return ;
}
Kagome Kagome
Time Limit: 2 Seconds Memory Limit: 65536 KB
Kagome kagome, kago no naka no tori wa
Itsu itsu deyaru? Yoake no ban ni
Tsuru to kame to subetta.
Ushiro no shoumen daare?
Translation:
Kagome kagome, the bird in the cage,
when will you come out?
In the evening of the dawn,
the crane and turtle slipped.
Who stands right behind you now?
Kagome Kagome is a Japanese children's game. One child is chosen as the oni (literally demon or ogre, but similar to the concept of "it" in tag) and sits blindfolded (or with their eyes covered). The other children join hands and walk in circles around the oni while singing the song for the game. When the song stops, the oni speaks aloud the name of the person behind him, and if he is correct, the person behind will exchange places with the oni.
Higurashi Tewi is playing Kagome Kagome with her n (n is even) friends as the oni now. She peeps to know who is right in front of her. Knowing the order of the children in circle and assuming that they keep distance evenly, it's easy to derive who is right behind her.
Input
There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.
The first line of each test case starts with an even number 1 ≤ n ≤ 100, followed by the name of the child who is right in front of Higurashi Tewi. The second line contains exactly n different names, listed in counterclockwise order. Name is an alphanumeric string whose length never exceeds 20. It's guaranteed that the child in front of Higurashi Tewi is always contained in the list exactly once.
Output
For each test case, output the name of the child who is right behind Higurashi Tewi.
Sample Input
3
2 Alice
Alice Bob
4 inu
inu neko usagi kizune
4 cat
dog cat rabbit fox
Sample Output
Bob
usagi
fox
ZOJ 3492 模拟循环链表线性查找的更多相关文章
- List<T>线性查找和二分查找BinarySearch效率分析
今天因为要用到List的查找功能,所以写了一段测试代码,测试线性查找和二分查找的性能差距,以决定选择哪种查找方式. 线性查找:Contains,Find,IndexOf都是线性查找. 二分查找:Bin ...
- 数组查找算法的C语言 实现-----线性查找和二分查找
线性查找 Linear Search 用户输入学生学号的成绩 二分查找 Binary Search 要求数据表是已经排好序的 程序存在小的瑕疵
- C++泛型线性查找算法——find
C++泛型线性查找算法--find <泛型编程和STL>笔记及思考. 线性查找可能是最为简单的一类查找算法了.他所作用的数据结构为一维线性的空间.这篇文章主要介绍使用 C++ 实现泛型算法 ...
- 算法之二分查找PK线性查找
列表查找(线性查找) 本质就是列表的index() 顺序查找 也叫线性查找,从列表第一个元素开始,顺序进行搜索,知道找到元素或搜索到列表最后一个元素为止. 以下是示例代码: def line_sear ...
- 复习下C 链表操作(单向循环链表、查找循环节点)
循环链表 稍复杂点. 肯能会有0 或 6 字型的单向循环链表. 接下来创建 单向循环链表 并 查找单向循环链表中的循环节点. 这里已6字型单向循环链表为例. //创建 循环链表 Student * ...
- java数组回顾---线性查找最大值最小值---二分查找
import java.util.Scanner; public class ArrayDemo { public static void main(String []args) { //------ ...
- 算法:线性查找(重点isFlag标志)
package com.atguigu; public class Main { public static void main(String[] args) { String[] arr=new S ...
- 【PHP数据结构】线性查找与二分查找
欢迎来到查找的世界,在学习完各种数据结构之后,总算走到了这一步,不知道大家有什么感想呢?反正我是边学边忘,现在让我去说说图的那几个算法还是在蒙圈的状态中.不过学习嘛,就是一步一步的来,暂时搞不懂的东西 ...
- BFPRT(线性查找算法)
BFPRT算法解决的问题十分经典,即从某n个元素的序列中选出第k大(第k小)的元素,通过巧妙的分 析,BFPRT可以保证在最坏情况下仍为线性时间复杂度.该算法的思想与快速排序思想相似,当然,为使得算法 ...
随机推荐
- Xcode - 详解真机测试步骤
第一种从iOS9.0之后推出的免费开发者账号 1.注册开发者 * 注册Apple ID * 使用Apple ID登录苹果开发者中心,注册成为开发者 * 此过程为免费,只是为了让普通的Apple ID具 ...
- linux命令 收集
https://jaywcjlove.github.io/linux-command/ 源码:https://github.com/jaywcjlove/linux-command Linux思维导图 ...
- Centos6.4安装JDK
链接地址:http://www.iteye.com/topic/1130311 1.先看看OpenJDK的安装包 $ rpm -qa |grep javatzdata-java-2013b-1.el6 ...
- 基础算法-查找:线性索引查找(I)
前面介绍的几种查找的算法都是基于数据有序的基础上进行的.但是在实际的应用中,很多数据集可能有惊人的数据量,面对这些海量的数据,要保证记录全部按照当中的某个关键字有序,其时间代价是非常昂贵的,所以这种数 ...
- java虚拟机内存溢出各种场景总结
java堆溢出 java堆用于存储对象实例,只要不断地创建对象,并且保证gc roots到对象之间有可达路径来避免垃圾回收机制来清楚这些对象,那么在 对象到达最大堆的容量限制后就会产生内存溢出溢出. ...
- beta分布
http://blog.csdn.net/sweetrryy/article/details/6436358
- php基本框架
- 三个C++资源链接(大量)
https://github.com/fffaraz/awesome-cpp http://blog.jobbole.com/78901/ https://github.com/programthin ...
- 安装andriod studio时出现Internal error. Please report to https://code.google.com/p/an
有两种方法的哈 一,在文件中添加 disable.android.first.run=true (我试了这种就好使了哈) 1)进入刚安装的Android Studio目录下的bin目录.找到idea ...
- HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...