Ural 1613 For Fans of Statistics(vector应用)
来源:互联网 发布:linux mutex 实现原理 编辑:程序博客网 时间:2024/06/06 05:21
题目:
这个题想多了。。这个方法想到过,但是想到了一种特殊数据,就是当好多数都一样的时候,然后每次遍历都要遍历好多,这样的话很容易就超时。。。一直没想出更好的办法,就搜了搜题解,结果都是这么做的。。。好吧。。
这题的思路就是哈希,利用vector和取模来解决冲突问题。然后找。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include<algorithm>using namespace std;int a[710000];struct node{ int x, num;};vector <node> vec[110000];const int mod=1e5+7;int main(){ int n, q, i, j, y, l, r, x; scanf("%d",&n); node tmp; for(i=1;i<=n;i++) { scanf("%d",&a[i]); tmp.x=a[i]; tmp.num=i; vec[a[i]%mod].push_back(tmp); } scanf("%d",&q); while(q--) { scanf("%d%d%d",&l, &r, &x); if(a[l]==x||a[r]==x) { printf("1"); continue ; } int len=vec[x%mod].size(), flag=0; for(i=0;i<len;i++) { if(vec[x%mod][i].x==x&&vec[x%mod][i].num>=l&&vec[x%mod][i].num<=r) { flag=1; break; } } if(flag) { printf("1"); } else printf("0"); } printf("\n"); return 0;}
2 0
- Ural 1613 For Fans of Statistics(vector应用)
- Ural 1613-For Fans of Statistics(vector)
- Ural 1613 For Fans of Statistics
- URAL 1613 For Fans of Statistics
- URAL 1613. For Fans of Statistics(STL 数学啊 )
- ural 1613. For Fans of Statistics
- Ural 1613. For Fans of Statistics
- ural 1613. For Fans of Statistics
- For Fans of Statistics——vector
- URAL 1613. For Fans of Statistics 二分+stl
- For Fans of Statistics(STL)
- 1613. For Fans of Statistics
- STL--G - For Fans of Statistics(两个判断条件-二分)
- timus 1613. For Fans of Statistics【该题超时的代码记录】
- scau_10317 Fans of Footbal Teams(并查集)
- statistics script for counting the result of more csv files
- Ural 1548 Sakura and Statistics
- Several address of statistics
- 三极管电阻计算以及旁路电路的选择
- linux:less、more命令
- C语言——结构体、局部变量和全局变量、枚举
- GNU ARM 汇编指令
- MySQL备份与恢复之逻辑备份
- Ural 1613 For Fans of Statistics(vector应用)
- 精通css(4)bug和修复bug
- 关于写的Java书籍进展
- 给页面两侧加浮动广告
- 选择排序算法
- JTAG座子的封装尺寸
- 朋友的一道面试题
- 页面添加浮动广告
- 【Node.js】Nodejs学习路线图