For Fans of Statistics(STL)
来源:互联网 发布:ubuntu jdk 1.7 编辑:程序博客网 时间:2024/05/17 06:02
- For Fans of StatisticsCrawling in process...Crawling failedTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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 ton. 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 froml 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, theith 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 109 − 1. In the third line, the number of queriesq is given,0 < q < 70000. The next q lines contain the queries. Each of them is a triple of integersl,r, and x separated with a space; 1 ≤ l ≤r ≤n ; 0 < x < 10 9.
Output
Output a string of length q in which theith symbol is “1” if the answer to theith query is affirmative, and “0” otherwise.
Sample Input
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567
题意:有五个城市以及每个城市的人口数,接下来是五组测试数据
每一组都包括num1,num2,people1,指num1城市到num2城市
有没有people1的人口数,有输出1,没有输出0;
思路“利用哈希的思想,对每个城市的人口哈希;
看的题解- -表示自己想不出来,越改越像题解
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>#include <map>#include <queue>#include <string>#include <iostream>using namespace std;#define inf 99999struct node{ int num;//城市的代号; int people;//城市的人口数;}t;vector<node> v[100010];//声明一个node的容器;int a[700010];int main(){ int n,m,i,j,k,mid; int num1,num2,people1; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); t.num=i; t.people=a[i]; v[a[i]%inf].push_back(t);//将入口哈希,借助v.push_back使数据加在最后; } scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d %d %d",&num1,&num2,&people1); if(a[num1]==people1||a[num2]==people1) { printf("1"); continue; } int l=v[people1%inf].size();//判断相同的城市的人口数目,一一遍历,找出符合的城市; int flag=0; for(j=0;j<l;j++) { if(v[people1%inf][j].people==people1&&v[people1%inf][j].num>num1&&v[people1%inf][j].num<num2) { flag=1; break; } } if(flag==1) printf("1"); else printf("0"); } printf("\n"); return 0;}
10101
0 0
- For Fans of Statistics(STL)
- URAL 1613. For Fans of Statistics(STL 数学啊 )
- URAL 1613. For Fans of Statistics 二分+stl
- 1613. For Fans of Statistics
- STL--G - For Fans of Statistics(两个判断条件-二分)
- 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
- For Fans of Statistics——vector
- Ural 1613 For Fans of Statistics
- Ural 1613-For Fans of Statistics(vector)
- URAL 1613 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
- Several address of statistics
- Webkit statistics of Android
- cf295A. Greg and Array
- 位图算法 C语言
- java coder一名,分享学习经验
- 所愿
- 【运维】小白学数据分析之 日活跃人数分析
- For Fans of Statistics(STL)
- Maven的项目管理(POM)应用和常见问题
- 移动应用崩溃了,你能怎么样?
- tmd123.com
- Linux 路由 学习笔记 之二 路由添加流程分析
- 用XMLRPC开服务进行server/client通信
- 一个简单的MDI示范程序(Delphi)
- linux sleep用法
- C语言 *和不加的区别