这题是给一个范围(L是左边界,R是有边界)问你在这个范围内哪个数载二进制下1的数量是最多的(有多个解请 输出最小数)。
也就是,要二进制的1尽量多,还要求尽量小,那就从低位开始把0变成1呗
那么我们就从左边界开始,从低位向高位按位或(0变成1,1也还是1)1,直到比R大停止, 输出前一个(即比R小的最后一个数)。
Code:
#include #include #include #include #include #include #include #include using namespace std;typedef long long ll;#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a) >l>>r; for(ll i=0;i r)break; l=t,p
D. Maximum Value
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 (1?≤?n?≤?2·105).
The second line contains n space-separated integers ai (1?≤?ai?≤?106).
Output
Print the answer to the problem.
Sample test(s)
input
33 4 5
output
int n=0; cin>>n; for(int i=0;i modmax; i++) for(int j=i+1;num[j]>modmax && j这样的东西……TLE的飞起……
想了想就不能暴力啊,暴力的话剪枝也没用
Code:
#include #include #include #include #include #include #include #include using namespace std;int n,a[200048]={0},ans=0;#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a) 0) update(a[p-1] % a[i]); j+=a[i]; } update(a[n-1] % a[i]); } printf("%d\n",ans); return 0;}
E. Strange Sorting
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
How many specific orders do you know? Ascending order, descending order, order of ascending length, order of ascending polar angle... Let's have a look at another specific order: d-sorting. This sorting is applied to the strings of length at least d, where d is some positive integer. The characters of the string are sorted in following manner: first come all the 0-th characters of the initial string, then the 1-st ones, then the 2-nd ones and so on, in the end go all the (d?-?1)-th characters of the initial string. By the i-th characters we mean all the character whose positions are exactly i modulo d. If two characters stand on the positions with the same remainder of integer division byd, their relative order after the sorting shouldn't be changed. The string is zero-indexed. For example, for string 'qwerty':
Its 1-sorting is the string 'qwerty' (all characters stand on 0 positions),
Its 2-sorting is the string 'qetwry' (characters 'q', 'e' and 't' stand on 0 positions and characters 'w', 'r' and 'y' are on 1 positions),
Its 3-sorting is the string 'qrwtey' (characters 'q' and 'r' stand on 0 positions, characters 'w' and 't' stand on 1 positions and characters 'e' and 'y' stand on 2 positions),
Its 4-sorting is the string 'qtwyer',
Its 5-sorting is the string 'qywert'.
You are given string S of length n and m shuffling operations of this string. Each shuffling operation accepts two integer arguments kand d and transforms string S as follows. For each i from 0 to n?-?k in the increasing order we apply the operation of d-sorting to the substring S[i..i?+?k?-?1]. Here S[a..b] represents a substring that consists of characters on positions from a to b inclusive.
After each shuffling operation you need to print string S.
Input
The first line of the input contains a non-empty string S of length n, consisting of lowercase and uppercase English letters and digits from 0 to 9.
The second line of the input contains integer m ? the number of shuffling operations (1?≤?m·n?≤?106).
Following m lines contain the descriptions of the operations consisting of two integers k and d (1?≤?d?≤?k?≤?n).
Output
After each operation print the current state of string S.
Sample test(s)
input
qwerty34 26 35 2
output
qertwyqtewryqetyrw
Note
Here is detailed explanation of the sample. The first modification is executed with arguments k?=?4, d?=?2. That means that you need to apply 2-sorting for each substring of length 4 one by one moving from the left to the right. The string will transform in the following manner:
qwerty ?→? qewrty ?→? qerwty ?→? qertwy
Thus, string S equals 'qertwy' at the end of first query.
The second modification is executed with arguments k?=?6, d?=?3. As a result of this operation the whole string S is replaced by its 3-sorting:
qertwy ?→? qtewry
The third modification is executed with arguments k?=?5, d?=?2.
qtewry ?→? qertwy ?→? qetyrw
DIV2全场只有一个人(joker99)出了E,看了下代码暂时囫囵吞了下,贴一下代码等日后学习下。
Code:
#include #include #include #include #include #include #include #include using namespace std;#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a) = 0; h--) if (vl >= (1 = sh) ps = pwr[h][ps - sh] + sh; vl -= (1
查看更多关于第二十次codeforces竞技结束#276Div2_html/css_WEB-ITnose的详细内容...