For Fans of Statistics——vector
来源:互联网 发布:农业银行软件官方下载 编辑:程序博客网 时间:2024/06/05 01:55
For Fans of Statistics
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
Have you ever thought about how many people are transported by trams every year in a city with a ten-million population where one in three citizens uses tram twice a day?
Assume that there are n cities with trams on the planet Earth. Statisticians counted for each of them the number of people transported by trams during last year. They compiled a table, in which cities were sorted alphabetically. Since city names were inessential for statistics, they were later replaced by numbers from 1 to n. A search engine that works with these data must be able to answer quickly a query of the following type: is there among the cities with numbers from l to r such that the trams of this city transported exactly x people during last year. You must implement this module of the system.
Input
The first line contains the integer n, 0 < n < 70000. The second line contains statistic data in the form of a list of integers separated with a space. In this list, the ith number is the number of people transported by trams of the ith city during last year. All numbers in the list are positive and do not exceed 10 9 − 1. In the third line, the number of queries q is given, 0 < q < 70000. The next q lines contain the queries. Each of them is a triple of integers l, r, and x separated with a space; 1 ≤ l ≤ r ≤ n ; 0 < x < 10 9.
Output
Output a string of length q in which the ith symbol is “1” if the answer to the ith query is affirmative, and “0” otherwise.
Sample Input
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567
10101
题意:有5各城市,每个城市的人口用表格表现出来,接下来有5组测试数据,1,5表示用1城市到5城市的人数有没有后面出现的。有可能两个不同的城市人数是相同的。
解析:利用哈希的思想,对每个城市的人口哈希,有相同的借助链表往后接。具体解析看代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#define MAX 100007using namespace std;int a[700100];struct node{ int id;//表示城市的代号 int zhi;//表示城市的人口数};vector<node> v[100007];//声明一个node型的容器int main(){ int n,m,i,j,k,x,y,z,mid; struct node c; scanf("%d",&n); for(i = 1;i <= n;i++) { scanf("%d",&a[i]); c.id = i; c.zhi = a[i]; v[a[i]%MAX].push_back(c);//将人口哈希,借助v.push_back在最后加入数据 } scanf("%d",&m); for(i = 1;i <= m;i++) { scanf("%d%d%d",&x,&y,&z); if(a[x] == z || a[y] == z) { printf("1"); continue; } int l = v[z%MAX].size();//判断相同人口的城市的数目,并一一遍历,查找符合条件的城市 int bj = 0; for(j = 0;j < l;j++) { if(v[z%MAX][j].zhi == z && v[z%MAX][j].id > x && v[z%MAX][j].id < y) { bj = 1; break; } } if(bj == 1) printf("1"); else printf("0"); } printf("\n"); return 0;}
0 0
- For Fans of Statistics——vector
- Ural 1613-For Fans of Statistics(vector)
- Ural 1613 For Fans of Statistics(vector应用)
- 1613. For Fans of Statistics
- ural 1613. For Fans of Statistics
- Ural 1613. For Fans of Statistics
- ural 1613. For Fans of Statistics
- For Fans of Statistics(STL)
- 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 二分+stl
- STL--G - For Fans of Statistics(两个判断条件-二分)
- timus 1613. For Fans of Statistics【该题超时的代码记录】
- statistics script for counting the result of more csv files
- Several address of statistics
- Webkit statistics of Android
- R project for statistics
- 3.6-栈内部排序
- volatile,可变参数,memset,内联函数,宽字符窄字符,国际化,条件编译,预处理命令,define中##和#的区别,文件缓冲,位域
- 多校练习赛 第五场
- ConcurrentHash Map 深入分析 (锁分离,提高效率,final key ,next域 保持线程安全)
- hd 2009 求数列的和
- For Fans of Statistics——vector
- Objective-c中的占位符,打印BOOL类型数据
- virtualbox for mac安装
- 线段树
- HDU 4911 Inversion(归并求逆序对)
- OGengine学习之一 开发环境搭建
- oralce共享连接和专用连接
- Windows下zlib库和libPng库的编译和使用
- 好的软件人员必看的书