hdu 5701(区间查询思路题)】的更多相关文章

中位数计数 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 999    Accepted Submission(s): 383 Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在多少个包…
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305<< 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A)     sum = 0     for i = 1 to A.length         for j = i+1 to A.length  …
思路: 思路题 题目诡异地给了一组可行匹配 肯定有用啊-. 就把那组可行的解 女向男连一条有向边 如果男喜欢女 男向女连一条有向边 跑一边Tarjan就行了 (这个时候 环里的都能选 "增广环"嘛) 嗯 就搞定了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 4005 int first[N…
传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的点,然后就和树链剖分一样\(dfs\)一遍,把那些链的顶端的\(sum\)值放到一个数组排个序. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include&…
传送门 解题思路 比较好想的思路题.首先肯定要把原序列转化一下,大于\(k\)的变成\(1\),小于\(k\)的变成\(-1\),然后求一个前缀和,还要用\(cnt[]\)记录一下前缀和每个数出现了几次,然后统计答案的时候从\(1\)循环到\(k\),每次转化为前缀和相减即可. 代码 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN = 10…
中位数计数 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 909    Accepted Submission(s): 346 Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在多少个包…
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1614    Accepted Submission(s): 566 Problem Description Mr Potato is a coder.Mr Potato is the BestCoder. One night, an amazing…
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.   Input 输入若干组数据.每组数据包括:导弹总个数(正…
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn't been so wealthy any more. The merchan…
中位数计数 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 764    Accepted Submission(s): 309 Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在多少个包…
Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 932    Accepted Submission(s): 382 Problem Description You are given a string S consisting of lowercase letters, and your task is cou…
题目: Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M. 思路: 刚开始做写了一个尺取法,脑抽的一批.(这几天心情真的是颓的很,连带脑瓜也不好用了,抓紧调整~~~~) 其实可以根据等差数列求和公式求出这个子序列的长度的一个大致的范围为k=sqrt(2*m),然后根据m和k求出首项a1,然后将a1…
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include<string.h> #define N 1100 int c[N][N],visit[N][N],n; int number(int x) { return x&-x; } void insert(int x,int y,int z) { int i,j; for(i=x;i<=N;…
摘自题解: 若没有边权,则对点权从大到小排序即可.. 考虑边,将边权拆成两半加到它所关联的两个点的点权中即可. ..因为当两个人分别选择不同的点时,这一权值将互相抵消. 代码如下: #include <cstdio> #include <cstring> #include <algorithm> #define LL long long #define INF 0x7fffffff #define M 100010 using namespace std; int co…
题意:在[a,b]  [c,d] 之间,和模p等于m的对数 详见代码 #include <stdio.h> #include <algorithm> #include <string.h> #include<cmath> #define LL long long using namespace std; int T; LL a,b,c,d,p,m; LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } LL…
题目链接 Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在多少个包含其的区间中是中位数. Input 多组测试数据 第一行一个数n(n≤8000) 第二行n个数,0≤每个数≤109, Output N个数,依次表示第i个数在多少包含其的区间中是中位数. Sample Input 5 1 2 3 4 5 Sample Output 1 2 3 2…
假设删除第k位,把整数A表示成如下形式: A = a * 10^(k+1) + b * 10 ^k + c; 则: B = a * 10^k + c; N = A + B = (11*a+b)*10^k + 2*c; 显然: 11*a+b = N / (10^k) 2*c = N % (10^k) 但是c有可能产生进位,产生的影响为: 11*a+b+1 = N/(10^k)[b+1最多为10,不会影响到11*a的值] 2*c = N % (10^k) + 10^k; 把这两种情况分别考虑一下.…
Building Blocks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2209    Accepted Submission(s): 509 Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build block…
考虑对立情况,不漂亮的串的形式必然为GGGGR……R……RGGGG 相邻R之间的距离为奇数且相等. #include <cstdio> #include <cstring> #include <cstdlib> #define LL long long int using namespace std; ; ; char str[MAXN]; int main() { int T; scanf( "%d", &T ); while ( T--…
Select Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1599    Accepted Submission(s): 443 Problem Description One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting…
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 842    Accepted Submission(s): 288 Problem Description You have an array consisting of n integers: a1=1,a2=2,a3=3,…,an=n. T…
Conturbatio Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 786    Accepted Submission(s): 358 Problem Description There are many rook on a chessboard, a rook can attack the row and column it be…
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1171    Accepted Submission(s): 402 Problem Description Recently, Goffi is interested in squary partition of integers.…
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 893    Accepted Submission(s): 407 Problem Description Hanamichi is taking part in a programming contest, and he is assigned to sol…
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1445    Accepted Submission(s): 632 Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence if and on…
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把所有点投影到y轴上),毕竟走的时候只能向上下或者向左右走 3 4 这里以投影到x轴上为例,设这些点是a1...an,且是排过序的(这里以升序为例) 5 当n==2的时候,那么在区间[a1,a2]上的任意一个点都可以满足题意,例如a1=1,a2=2的时候,你取1.5或1.6或1.7...... 6 你…
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others) Total Submission(s): 1120    Accepted Submission(s): 579 Problem Description There are N cities in our country, and M one-way roads connecting them. Now L…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2586 题目大意:在一个无向树上,求一条链权和. 解题思路: 0 | 1 /   \ 2      3 设dist[i]为i到根0的链和,求法(Dfs过程中dist[v]=dist[u]+e[i].w) 对于树中任意两点形成的链,可以通过LCA最近公共祖先剖分. 比如2->3,就可以经过LCA点1:  2->1->3 链和=dist[u]+dist[v]-2*dist[LCA[u,v]] (…
1.HDU  1102  Constructing Roads    最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b using na…
UVa 11572 - Unique Snowflakes 问一个数组中,无重复数字的最长子串长度是多少. 用map维护某数字上次出现的位置.另外用变量last表示上次出现数字重复的位置. 如果出现重复数字,且map[val]>last时,计算当前区间长度,然后last变为map[val]+1. 其他时候增长区间长度即可. 每次遍历一个元素都要更新map[val],用区间长度更新最优解. #include<iostream> #include<vector> #include…