给一个区间,求区间里的数转化为二进制后拥有'1'个数最多的那个数,要是拥有'1'的数量相同,取最小的那个数 输出。
直接从左端点对1进行或运算,构造出'1'最多且最小的数,直到值大于右端点
#include #define ll long longint main(){ int t; scanf("%d", &t); while(t--) { ll l, r, tmp, p = 1; scanf("%I64d %I64d", &l, &r); for(ll i = 0; i r) break; l = tmp; p
D. Maximum Value
time limit per test
1 second
memory limit per test
256 megabytes
You are given a sequence a consisting ofn integers. Find the maximum possible value of (integer remainder ofai divided byaj), where1?≤?i,?j?≤?n and ai?≥?aj.
Input
The first line contains integer n ? the length of the sequence (1?≤?n?≤?2·105).
The second line contains n space-separated integersai (1?≤?ai?≤?106).
Output
Print the answer to the problem.
Sample test(s)
Input
33 4 5
Output
找a[i]
#include int const MAX = 2000000 + 10; int a[MAX]; int main() { int n, x, ans = 0; scanf("%d",&n); for(int i = 0; i ans && a[j] > i) ans = a[j] % i; printf("%d\n",ans); }
Div.1 : D. Kindergarten
time limit per test
2 seconds
memory limit per test
256 megabytes
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).
The teacher wants to divide the children into some number of groups in such way that the totalsociability of the groups is maximum. Help him find this value.
Input
The first line contains integer n ? the number of children in the line (1?≤?n?≤?106).
The second line contains n integersai ? the charisma of thei-th child (?-?109?≤?ai?≤?109).
Output
Print the maximum possible total sociability of all groups.
Sample test(s)
Input
51 2 3 1 2
Output
Input
33 3 3
Output
Note
In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.
In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.
把一串数列分成若干组,每组的权值为该组中最大值与最小值的差,求所有组的权值和的最大值
#include #define ll long longint main(){ int n, t; scanf ("%d", &n); ll ans = 0, t1 = 0, t2 = 0; for(int i = 0; i t1) t1 = ans + t; if (!i || ans - t > t2) t2 = ans - t; ans = t1 - t > t2 + t ? t1 - t : t2 + t; } printf("%I64d\n", ans);}
查看更多关于CodeforcesRound#276(Div.2)_html/css_WEB-ITnose的详细内容...