题目链接:http://codeforces.com/contest/816/problem/B 题意:给出n个范围,q个查询问查询区间出现多少点在给出的n个范围中至少占了k次 题解:很显然的一道题目,可能会想到用莫队,或者分块来写,但是这样会超时.这题有个技巧,可以考虑用前缀和来求. 首先在n个范围中给出了l,r,用一个数组a[],a[l]++,a[r+1]--,然后求前缀表示前i个有多少个超过k的.然后就简单了,具体看一下代码. 总而言之想法很重要. #include <iostream>…
题目链接:http://codeforces.com/contest/816/problem/D 题解:显然一看到这题应该会想到是有什么规律的于是多写几项就会发现偶数列之间是有关系的. 满足a[i][j]=a[i-2][j]+a[i-2][j+2],于是递推到最后第2列a[2][0],a[2][1]就可以用最早出现的偶数列来求的,最后是加还是减只要看n就行了. 由于a[2][0]是有几个最早出现的偶数列的奇数项求的,而且这些奇数项选择的次数符合二项式分布(这个可以通过花一下杨辉三角理解一下).…
题目链接:http://codeforces.com/contest/816/problem/C 题意:给出一个矩阵,问能否从都是0的情况下只将一整行+1或者一整列+1变形过来,如果可以输出需要步数最小的情况.不能输出-1 题解:就是一道模拟题,然后关于最小的只要考虑一种情况,就是当前行可以消除,也可以消除全部列的时候要考虑要删行还是删列,这个取决于n于m的大小 #include <iostream> #include <cstring> #include <cstdio&g…
[题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k个以上的区间覆盖到; 则称之为特殊数字; 给你q个询问区间; 问你这q个区间里面 每个区间里面有多少个特殊数字; [题解] 对于覆盖的区间l,r add[l]++,sub[r+1]++, 然后顺序枚举 now+=add[i]; now-=sub[i]; 如果now>=k则i是一个特殊数字; 写个前缀和O…
题目链接:http://codeforces.com/contest/816/problem/E 题意:有n件商品,每件有价格ci,优惠券di,对于i>=2,使用di的条件为:xi的优惠券需要被使用,问初始金钱为b时 最多能买多少件商品? n<=5000,ci,di,b<=1e9 题解:显然是一道树形dp由于有两种情况就是当前点为根结点的时候选择打折还是不打折,如果选不打折之后的节点都不能打折. 不妨设dp[i][j][flag]表示i为根j为种类数,flag为状态表示选不选打折的最小花…
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time r…
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可用温度(个人翻译),然后给出q次询问,问区间[L2,R2]内的温度,有多少个温度是可用温度(每个整数代表一个温度) 思路:一开始用的是线段树写的,不过姿势不对,TLE了,然后改过来后,发现时间比较长,就考虑一下优化的方法. 比线段树某些功能更优的算法:差分思想,在对某一区间每个位置上的数加上一个值x…
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the opti…
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the opti…
Description To stay woke and attentive(专注的) during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
题目链接:http://codeforces.com/contest/816/problem/B 题目意思:给出 n 个recipes,第 i 个(1<= i <=n)recipes 表明 coffee 调制的推荐温度范围是 [li, ri] 之间.现在有 q 个问题,每个问题需要回答 coffee 在范围 [a, b] 之间,共有多少个数满足至少有 k 个推荐. 题目解析:这题主要是考我们对于大范围(最大200000),如何处理数据.方法是很容易想到的,但要考虑优化,即离线处理.20w *…
LINK 题意:给出n个[l,r],q个询问a,b,问被包含于[a,b]且这样的区间数大于k个的方案数有多少 思路:预处理所有的区间,对于一个区间我们标记其(左边界)++,(右边界+1)--这样就能通过前缀和维护小于某边界的区间个数了 这题也可以用线段树解,但显然不太合算 /** @Date : 2017-07-01 10:02:30 * @FileName: 816B 前缀和 线段树 二分.cpp * @Platform: Windows * @Author : Lweleth (SoungE…
传送门:http://codeforces.com/contest/816/problem/C 本题是一个模拟问题. 有一个n×m的矩阵.最初,这个矩阵为零矩阵O.现有以下操作: a.行操作“row i”:对第i(1≤i≤n)行的所有元素加一: b.列操作“col j”:对第j(1≤j≤m)列的所有元素加一. 经过有限次操作,矩阵变为$G=(g_{i,j})_{m*n}$. 对于给定的矩阵G,试判断G是否可以由零矩阵O通过有限次的“行操作”和“列操作”生成?若可以,则求一个操作步数最小的方案:否…
[题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全部加上1; 问你到达目标矩阵最少需要进行多少次操作; [题解] 从目标矩阵开始减; 直接枚举每一列需要减多少次; 每一行需要减多少次即可; 但有技巧; 比如以下矩阵 1 1 1 1 1 1 1 1 1 1 1 1 应该一列一列地减比较快; 而 1 1 1 1 1 1 1 1 一行一行地删比较快; 所…
[题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如果和原串相同,则为回文串; 模拟就好 [Number Of WA] 0 [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|…
http://codeforces.com/problemset/problem/305/B 题意:就是判断 p / q 等不等于那条式子算出来的值. 思路:一开始看到 1e18 的数据想了好久还是不会,暴力了一发显然错了.后来倒着想,就是 p / q(整除)的值一定要大于等于 a[i],否则就不行,每次判断完之后更新 p / q 即可,注意要判分母是否为0,因为这个RE了一次.思维僵化很严重,如果活跃一点估计很快就想出来了.吸取教训. #include <cstdio> #include &…
题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符合的也行.找不符合的就简单了.找到一个位置i,他的最左边的位置就是a[i]在二进制下是0的最靠近i的位置,所以可以先用pos[j]记录第j位是0的位置.然后最右边的也是同理.这里还处理一下a[l]=a[r]的情况如果这个相同会出现重复考虑所以可以在第一遍找最左边位置的时候做一下处理最左边的位置起码大…
题目链接 :http://codeforces.com/contest/816/problem/B 题意 :给出 n 表示区间个数,限定值 k 以及问询次数 q,当一个数被大于或等于 k 个区间重复覆盖时才算有效数,每一次问询都是以区间方式给出,例如(L, R)问你在这个L~R的范围内有多少个数是有效数(即包含这些数的区间个数>=k). 分析 : 这题可以预先统计哪些数被大于或者等于 k 个原始区间重复覆盖,只要提前将这些满足条件的数递增地编上权值构成前缀和序列,然后对于每段问询只要将前缀和序列…
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价值为s 题解:min(s/n,a)*n+b>=s?YES:NO #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm>…
大家好,欢迎来到codeforces专题. 今天选择的问题是1443场次的D题,这题是全场倒数第三题,截止到现在一共通过了2800余人.这题的思路不算难,但是思考过程非常有趣,这也是这一期选择它的原因. 链接:https://codeforces.com/contest/1443 废话就先说到这里,下面我们就来看题吧. 题意 给定n个整数,对于这n个整数我们可以采取两种操作.第一种操作是在数组左侧选择连续的k个整数减1,第二种操作是选择右侧的连续k个整数减1. 比如假设数组是[3, 2, 2,…
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test:256 megabytes One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually…
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinis…
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全部元素的和可以被3整除,问有多少种方法构建出该数组.答案模1000000007 例 输入 2 1 3 输出 3 note:满足的情况只有[1,2],[2,1],[3,3] 解题思路:用dp[i][j]表示长度为i的数组,元素大小在[L,R]之间,并且元素和模3的余数为j的方案数,我们可以计算出[L,…