Codeforces 474B. Worms】的更多相关文章

主题链接:http://codeforces.com/contest/474/problem/B #include <iostream> #include <cmath> #include <algorithm> #include <cstdio> using namespace std; template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar()…
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are label…
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n, m; cin >> n; for(int i = 1; i <= n; +…
CodeForces 474B Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u Description It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile co…
题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai-1+ai] 接着输入一个整数m,之后有m个数,问你这m个数,每个数所在的区间编号. 分析: 可以采用计数排序,建立一个数组,将第i段区间[ai-1+1,ai-1+ai]赋值为i,这样输入一个数很快就可以输出它所在的区间编号; 因为区间中的值是有序的,所以还可以采用二分查找法. 代码如下: //方法一…
474B Worms time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms su…
http://codeforces.com/problemset/problem/474/B B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Ma…
题目链接:http://codeforces.com/contest/474/problem/B 解题报告:给你n个堆,第i个堆有ai个物品,物品的编号从1开始,第一堆的编号从1到a1,第二堆编号从a1+1到a1+a2.......,现在有m次查询,给你一个编号,让你求出这个编号的物品在第几个堆. 离线算法,先把m次查询按照编号从小到大排序,然后全部求出来之后按照输入的顺序排序就行了. #include<cstdio> #include<cstring> #include<i…
一.题目链接 http://codeforces.com/contest/960/problem/B 二.题意 给定三个数字$N, k1, k2$,接下来给出两组数$a[]$和$b[]$,每组数$N$个,对$a$组数操作$k1$次,对$b$组数操作$k2$次,每次操作都可以从指定的数组中选择任意一个数加$1$或减$1$.求操作完$k1$和$k2$之后,最小的差分平方和$\sum\limits_{i=1}^{N}(a_i - b_i)^2$. 三.思路 其实思路很简单,只是当时时间比较晚了,几乎精…
B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such…