牛客第二场 J farm】的更多相关文章

White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The plant in the j-th column of the i-th row belongs the a[i][j]-th type.White Cloud wants to help White Rabbit fertilize plants, but the i-th plant can onl…
链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. White Cloud can walk meters or run k meters per second. Since White Cloud is tired,it can't run for two or more continuous seconds. White Cloud will mov…
链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to n. White Rabbit wants to visit these stores to n. The store numbered i has a price a[i] representing that White Rabbit can spend a[i] dollars to buy…
题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较方便,用for(int i = 0;i < q[i].size();i++)的话,是会有一些弊端的,虽然对于这道题应该没什么影响,但最好规范下. 耗时:2072ms 实现代码: #include<bits/stdc++.h> using namespace std; ; vector<…
题意:一个n×m的农田, 每个小格子都有一种作物, 现在喷t次农药,每次农药覆盖一个矩形, 该矩形里面与农药类型不同的植物都会死掉, 求最后植物的死亡数是多少. 题解:二维树状数组. 每次喷农药的时候将这个覆盖的区间加一. 然后对于[1,n*m]的植物, 先删除同种植物的同种农药对区间的影响, 然后查询该种植物的是否被标记过了 即 该位置的值 > 1, 最后处理完这种植物再把这种植物的农药再加回去. 代码: #include<bits/stdc++.h> using namespace…
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add(x2+1,y1,-z); 我们会想为什么和一维的差这么多,我们不妨这样看 add(x1,y1,z);的更新效果 add(x2+1,y2+1,z);的更新效果 那么这个下半区有两个,我们再更新 add(x1,y2+1,-z);的更新效果 add(x2+1,y1,-z);的更新效果 最后用红的去剪掉黄色…
题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa sy…
题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d).问飞机旅程与最后一个云层相交的x坐标.不存在 分析: 可以确定两直线联立后解得交点x=(b-d)/(a-c). 可以看做是点(a,b)和(c,d)的斜率的负数. 要求的最大的x,那么就变成了求得最小的斜率,答案最后再乘-1即可. 就是求每个(c,d)点到(a,b)的斜率,可以把每一个(a,b)看…
思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream>//pair #include <…
LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我的. \(k\sqrt{A}=p\)即\(A^{\frac{1}{k}}=p\) 设当前置换大小为r 那么有 \(A^r=I\)其中I为单位置换. \(A^{r+1}=A\)那么有\(A^{ar+1}=A\) 原式等于\(A^{\frac{ar+1}{k}}=P\) 那么只需要随便找个a满足\(k|…