元素查找
来源:互联网 发布:ios和mac 编辑:程序博客网 时间:2024/05/16 12:34
http://codevs.cn/problem/1230/
输入一串数,输入查询,看这个数否存在。
题很假单。我第一个想法是桶排。看了下标题,是哈希表,以及线性结构,然后自己自从学过哈希表从来就没写过,写一个练练吧。
从线性表角度看,是应优先队列,貌似如果是数组,再加一个快排,应该也是稳稳的。
#include<iostream>#include<stdio.h>#include<cmath>#include<algorithm>#include<stack>#include<string>using namespace std;int a[100005] = { 0 };int main(){ int n, k; cin >> n >> k; int x; for (int i = 0; i < n; i++) { scanf_s("%d",&x); int weizhi = x % 100005; while (a[weizhi]!=x) { if (!a[weizhi]) a[weizhi] = x; else { weizhi++; if (weizhi == 100005) { weizhi = 0; } } } } for (int i = 0; i < k; i++) { scanf_s("%d",&x); int weizhi = x % 100005; int biaozhi = 1; while (a[weizhi] != x) { if (!a[weizhi]) { biaozhi = 0; break; } else { weizhi++; if (weizhi == 100005) { weizhi = 0; } } } if (biaozhi) printf("YES\n"); else printf("NO\n"); } system("pause"); return 0;}
0 0
- 查找元素
- 元素查找
- 查找元素
- 查找元素
- 查找元素
- 查找元素
- 元素查找
- 元素查找
- 元素查找
- 元素查找
- 元素查找
- 元素查找
- 元素查找
- 模糊查找元素个数
- 算法:查找过半元素
- Jqurey查找页面元素
- 单链表内元素的查找
- jquery查找元素
- Codeforces Round #250 (Div. 1) B. The Child and Zoo(排序+并查集)(常规好题)
- 【小熊刷题】Two Sum II - sorted array
- muduo::EventLoopThread、EventLoopThreadPool分析
- Android下创建一个SQLite数据库
- Javascript高级程序设计第八九章
- 元素查找
- Spring(三): 事务
- 欢迎使用CSDN-markdown编辑器
- 巨幕和徽章
- poj 3620 Avoid The Lakes
- Java学习笔记(十)collections框架概述
- 初学OC控件拖动操作
- Android复习笔记(12)- listView的使用
- C语言变量类型