题目链接:http://lightoj.com/volume_showproblem.php?problem=1100 题意是给你n个数,q个询问,每次求出 a 到 b(从0开始)最小差值: 直接暴力就能过: #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> #include<iostream> using namespace std; #defin…
题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数. 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n. 状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1 #include <cstdio> #include <al…
                                                                          1100 - Again Array Queries                                                                                                  ->   Link   <- 又是这种区间查询最值问题,题目意思是要使得这个区间的两个数的差值最小值,…
1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB Given an array with n integers, and you are given two indices i and j (i ≠ j) in the array. You have to find two integers in the range whose diffe…
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 ],size; inline void in(int &am…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
                                                                                                              1082 - Array Queries Time Limit: 3 second(s) Memory Limit: 64 MB Given an array with N elements, indexed from 1 to N. Now you will be given…
You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value…
http://lightoj.com/volume_showproblem.php?problem=1100 刚一看到这题,要询问这么多次,线段树吧,想多了哈哈,根本没法用线段树做. 然后看看数据范围纯暴力的话肯定超时.然后比赛时就liao那了. 今天是补题,然后做这题,前两发傻逼呵呵的想了一种暴力方法,报着也许能过的心态交了,果然没让我失望超时了. 不说这些没用的了,下面说说这题是咋做的. 没用什么高深的算法,好像算法都没用,就纯暴力写的,关键是加入一种常识来优化.传说中的鸽巢原理,其实有点常…
传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #include<cstdio> int n,a[100100],p,k,q,dp[100100][350]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",a+i);…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1100 给你n个数,数的范围是1~1000,给你q个询问,每个询问问你l到r之间数的最小差是多少. 要是l到r的数字个数大于1000,必定会有两个数字重复,所以此时最小差就为0.要是小于等于1000就直接暴力即可. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorit…
Description You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal t…
a is an array of n positive integers, all of which are not greater than n. You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + …
1 #include<stdio.h> 2 #include<string.h> 3 int a[10]; 4 int main(){ 5 for (int x=123;x<=329;x++){ //枚举 6 int i=x,j=x*2,k=x*3; 7 int o=i,p=j,q=k; 8 int flag=0; //清零 9 memset(a,0,sizeof(a)); //使数组a中所有存放内容的值全为0 10 while(i > 0){ //取数 11 a[i%…
题目链接 非常好的一道题目, 分析,如果用暴力的话,时间复杂度是O(q*n)稳稳的超时 如果用二维DP的话,需要O (n*n)的空间复杂度,会爆空间. 那么分析一下,如果k>sqrt(n)的话,不需要sqrt(n) 次就可以达到大于n 而如果k<sqrt(n)的情况下,不妨用DP来处理,时间复杂度和空间复杂度皆为O ( n*sqrt( n ) ) 那么都可以分类处理了. 详细见code #include <iostream> #include <cstdio> #inc…
题目链接:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/#/description   姊妹篇:http://www.cnblogs.com/zpfbuaa/p/6531773.html   给出一个循环有序数组,与其姊妹篇不同的是其中允许元素出现重复多次.给定一个数字target,查找该数字是否存在于该数组中.   姊妹篇中的解决方法是使用折半查找,通过判断nums[left]和nums[mid]以及nums[r…
$dp$预处理,暴力. 如果$k > sqrt(n)$,那么答案不会超过$sqrt(n)$,暴力模拟即可.如果$k <= sqrt(n)$,那么可以$dp$预处理打表. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <queue> #include <stack&…
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问由p和k构成; 会对p进行 p=p+a[p]+k操作若干次; 你要输出p第一次大于n之后操作了多少次; [题解] 部分DP; 这里对于k>400的询问; 我们直接暴力求解; 因为这时暴力所花费的时间已经可以接受了; 而对于剩余的k<=400的询问; 我们写一个记忆化搜索来求解; 很棒的思路吧 [N…
原题连接:http://codeforces.com/problemset/problem/863/D 题意:对a数列有两种操作: 1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i], a[l]=a[r] 2 l r ,[l, r] 区间的数字位置反转. 若干个操作之后输出a[b[i]]. 思路: 由于是在操作结束后输出,且b[i]的个数不多(<=100),所以可以通过反推求出答案. AC代码: #include<iostream> #include<cstrin…
问题 G: 方差 普拉斯 时间限制: 1 Sec  内存限制: 128 MB提交: 94  解决: 17[提交] [状态] [讨论版] [命题人:admin] 题目描述 方差(样本方差)是每个样本值与全体样本值的平均数之差的平方值的平均数.在许多实际问题中,研究方差即偏离程度有着重要意义. 若x1,x2,x3......xn的平均数为k,则方差s^ = /n * [(x1-k)^+(x2-k)^+.......+(xn-k)^] . 给出M个数,从中找出N个数,使这N个数方差最小. 输入 第1行…
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index]. Then, the answer to the i-th query is the sum of the even values of A. (Here, the given index = qu…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找规律 日期 题目地址:https://leetcode.com/problems/sum-of-even-numbers-after-queries/ 题目描述 We have an array A of integers, and an array queries of queries. For the i-th query val = q…
在学习java中的collection时注意到,collection层次的根接口Collection实现了Iterable<T>接口(位于java.lang包中),实现这个接口允许对象成为 "foreach" 语句的目标,而此接口中的唯一方法,实现的就是返回一个在一组 T 类型的元素上进行迭代的迭代器. 一.迭代器Iterator 接口:Iterator<T> public interface Iterator<E>{ boolean hasNext…
003-Tuple.Array.Map与文件操作入门实战 Tuple 各个元素可以类型不同 注意索引的方式 下标从1开始 灵活 Array 注意for循环的until用法 数组的索引方式 上面的for是下标索引(繁琐用的不多) 下面的for是增强for循环的元素遍历索引(推荐) Map 注意左边是Key,右边是Value _(下划线也可以作为占位符,形成结构,但无名称不可以访问) 文件操作 进行了Source包的引入 .fromFile() getLines 使用了Iterator 欢迎广大爱好…
1.关于json JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集.也可以称为数据集和数组类似,能够存数据! //Array数组 //数组的常用语法如下  数组用中括号<[]存储数据> length数组的长度<数组独有!> var Array=[1,3,5,7,9]; //    数组名 Array<数组/保留字,保留字> //alert(Array.length);    弹出当前  A…
从Java5起,在Java中有了for-each循环,可以用来循环遍历collection和array.Foreach循环允许你在无需保持传统for循环中的索引,或在使用iterator /ListIterator(ArrayList中的一种迭代器实现)时无需调用while循环中的hasNext()方法就能遍历collection.for-each循环简化了任何Collection或array的遍历过程.但是使用foreach循环也有两点需要注意. 使用foreach循环的对象,必须实现了Ite…
Atitit  循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 1.1. 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称之为循环. 大部分的递归, 遍历, 迭代, 都是循环.1 1.2. 递归的定义是, 根据一种(几种)基本情况定义的算法, 其他复杂情况都可以被逐步还原为基本情况.1 1.3. 递归的基本概念和特点1 1.4. 迭代(数学): 在循环的基础上, 每一次循环, 都比上一次更为接近结果.2 1.5. 编程语言中的循环…
原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now you have n problems, the i-th problem's difficulty is represented by an integer ai (1≤ai≤109).For some strange reason, you must choose some integer l and r…
  ES5中新增的Array方法详细说明 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=3220 一.前言-索引 ES5中新增的不少东西,了解之对我们写JavaScript会有不少帮助,比如数组这块,我们可能就不需要去有板有眼地for循环了. ES5中新增了写数组方法,如下: forEach (js v1.6) map (js v1.6) filter (js v1…
一.前言-索引 ES5中新增的不少东西,了解之对我们写JavaScript会有不少帮助,比如数组这块,我们可能就不需要去有板有眼地for循环了. ES5中新增了写数组方法,如下: forEach (js v1.6) map (js v1.6) filter (js v1.6) some (js v1.6) every (js v1.6) indexOf (js v1.6) lastIndexOf (js v1.6) reduce (js v1.8) reduceRight (js v1.8) 浏…