D. Maximum Value     You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided byaj), where 1 ≤ i, j ≤ n and ai ≥ aj. Input The first line contains integer n — the length of the sequence…
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/B Description You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), whe…
就是一种筛法思想的应用. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #include<…
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优的值,用它模x更新.一旦最优值是最后一个元素,那么更新完后break;对数组排序完后对每个元素进行如上操作.(跳过1),复杂度为n/2+n/3+......=n(1/2+1/3+......)=nlogn.不过超时了.因为如果数组中全是2,最后一个为99999,复杂度为n/2+n/2+......=…
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/484/D Description In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child wi…
B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/375/B Description You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is…
A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Description Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries…
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> #include<stdbool.h> using namespace std; int main() { int a,m; ]={}; scanf("%d%d",&a,&m); while(true) { ){ printf("Yes\n"…
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数>b,且减去1<<i后仍>=a,就减1<<i 当当前数在[a,b]之间时,输出 因为从高位开始减,所以保证当前数是最小的 #include<cstdio> #include<iostream> using namespace std; typedef l…
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护最长连续子区间 把数从大到小插入主席树 对于每个询问,二分x 在第x棵线段树中查,若最长连续子区间>=w,到代表更大的线段树中查 没有建第n+1棵线段树,导致前面节点的siz不对,WA了一次 #include<cstdio> #include<iostream> #include…