Question is intended to find a 1 ~ N B are arranged, such that the absolute value of the difference between each number and arrangement of the arrangement A B is greater than or equal to N
Had in mind was the original arrangement in reverse output should meet the requirements
WA then in the sixth spot. 132 then think of this reverse arrangement 231, dif only 2 <3
Then the second idea is the larger number and smaller numbers in order to exchange, over the last
#include<iostream> #include<string.h> #include<stdio.h> using namespace std; const int maxn=1e5+7; int a[maxn],n,m,b[maxn]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&m); a[m]=i; } for(int i=1;i<=n;i++) b[a[n+1-i]]=i; for(int i=1;i<n;i++) printf("%d ",b[i]); printf("%d\n",b[n]); return 0; }
Meaning of the title is given R, C two arrays, consisting of two-dimensional array of NxN get asked from the beginning to the end there is an even number of points for each path
First through R, C array to obtain a two-dimensional array, and each region is determined even-staining around the starting point will be determined at the end of this region is not, so that the solution can be
But the N largest 1e5, on a two-dimensional array of super memory, and the results did not expect good way, only to see the problem solution
Let the point (i, j) is labeled 0 or 1, representing at this point is even or odd. Similarly R, C array
When we look at from a point (i, j) to (i, j + 1), R (i) values unchanged, indicating C (j) and C (j + 1) with the same 0 or 1
Similarly, the (i, j) to the (i + 1, j) Description R (i) and R (i + 1) with the same 0 or 1
And if the path is not straight, for example, the left - down - left, we can judge
C (j) and C (j + 1) with one or with 0, C (j + 1) and C (j + 2) with one or with 0, C (j) and C (j + 2) with 1 or with 0
Therefore, if the (a, b) to (A, B), R (a, A) and C (b, B) are two sections with the same 0 or 1
Of course, this path is a necessary condition
As the starting point must be even, with only two intervals with the 1 or 0, or that the starting point is odd
Therefore, only the start and end points are determined even number, and two sections with a certificate or to have the same path ,, 0
Here whether with 0 or 1 with the same prefix and determining section
#include<iostream> #include<string.h> #include<stdio.h> using namespace std; const int maxn=1e5+7; int n,q,c[maxn],r[maxn],csum[maxn],rsum[maxn]; int ra,ca,rb,cb; int main(){ scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) scanf("%d",&r[i]); for(int i=1;i<=n;i++) scanf("%d",&c[i]); for(int i=1;i<=n;i++) if(r[i]%2==r[i-1]%2)rsum[i]=rsum[i-1]; else rsum[i]=rsum[i-1]+1; for(int i=1;i<=n;i++) if(c[i]%2==c[i-1]%2)csum[i]=csum[i-1]; else csum[i]=csum[i-1]+1; while(q--){ scanf("%d%d%d%d",&ra,&ca,&rb,&cb); if((r[ra]+c[ca])%2||(r[rb]+c[cb])%2){ printf("NO\n"); continue; } if(ra<rb)swap(ra,rb); if(ca<cb)swap(ca,cb); if(rsum[ra]-rsum[rb]==0&&csum[ca]-csum[cb]==0){ printf("YES\n"); } else printf("NO\n"); } return 0; }
Meaning of the title is given N rectangles, find the maximum area
A genius for finding method is half the area of a rectangle
Find one kind of method is to find two rectangular, satisfy a length L greater than or equal, greater than a width equal to d, the maximum area of max l * max d
See this question, my first reaction is two points after a determined area, looking for this area can not be, of course, can also float half
But this still can not think of how to find a method to complete the second, finally. . . Look problem solution
The first method is simple to find, you can find someone to come out at the time of input
Then find the second method by sorting and selecting the maximum value, respectively, satisfy the l, d conditions
Is well known, a traverse complexity is O (n) (one-dimensional)
If you can deal with in advance, then once traversal get an answer, I think this program is written very beautiful
We want these matrices by the width d descending order, there must be wider than the matrix before he hit the back of the matrix
When a maximum value and then to record the i-th matrix, the maximum length of the matrices before him, if he is larger than the length maxl, he matrix and have a length corresponding to greater than or equal maxl maxl, and vice versa he maxl length greater than the corresponding matrix equal to the length of his
This will only satisfy the condition of d and l
When in fact I have here a question, the answer is to look at the code and found that before ordering the longer side of the matrix as the width of the sort, but do not know why
One idea is to input each of two matrices, length and width of two reversed as read into the matrix, but this may appear to meet the conditions are the same, it is not
Later, looked under the case does not deal with, then it is equivalent to two matrix cross piled up, finally certain overlapping area is small, so we should deal with
There is a precision problem? ? Said double save any content longlong
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int maxn=1e5+7; typedef long long LL; struct Node{ LL l,d; bool operator<(const Node &a){ return d>a.d; } }node[maxn]; int n; LL ans,l,d; int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld%lld",&l,&d); if(d<l)swap(d,l); node[i].d=d,node[i].l=l; ans=max(ans,l*d); } sort(node,node+n); LL maxl=node[0].l; for(int i=1;i<n;i++){ ans=max(ans,node[i].d*min(maxl,node[i].l)*2); maxl=max(maxl,node[i].l); } if(ans%2)printf("%lld.5\n",ans/2); else printf("%lld.0\n",ans/2); return 0; }
This question is a good thought, given that Italy is a string of characters, and a bunch of operations
1 is a reverse operation to the character r l, the function value f 2 is obtained by a string
As long as you follow the topic that is done, it is easy to write, and then TLE
Then I consider the operation 1 writing prefix and then still TLE
Only problem may be in the f function, but. . Have no idea
If you are thinking that sensitive, you will find that A = A + B and B = A + B operation may be implemented in two matrices are respectively
After all, we can not but have several 'A' on the matrix by several A = A + B, after all strings are ordered, 'AB' and 'BA' end result is not the same
Therefore, a turn style, the operation interval cumulative values ordered using modified segment tree to satisfy interval and to give
Specific point is that you can get through the tree line interval of l to r's tired of all the new matrices multiply
123
Do more, I slowly began to understand, when you have no idea that they are mostly related with the number of number theory.
This question text is too long, the beginning did not understand the meaning of problems
The main talking point is the infinite set, as long as two-point difference between the value of i, B i have a set of values, it is connected to two points
B which asks you to delete the set point, the connection graph is a bipartite graph
This question is to ensure the bipartite graph is to ensure that no odd ring
We look at two relatively prime number, such as 3, 4
From the starting point 0 Start, plus 3, become 0,3,6,9,12
4 plus turn into 0,4,8,12. 0-12 in the ring in a total of seven the number is odd ring
The half-rings has four lines, there are three half ring, because the prime 3,4, 3 should be multiplied by 4 becomes 12,4 3 becomes 12
So the first conclusion, if the prime number, the sum is odd odd ring
If parity relatively prime, it must be a strange ring. So the only possible solution is relatively prime Kiki, such as 3,5
The second conclusion, with two numbers multiplied by the same factor, the number of loop invariant
8 such wire loops can be composed of 3,5, 12 and 20 can be composed of wire loops 8, except that a line of increased value increases
Finally a conclusion, so we put two numbers in addition to co-prime, the last two odd judge is not on the list
But in fact, except the odd odd or odd, so look at two numbers divided by the same factor of 2, the last two odd to see whether they will do
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxn=2e5+7; typedef long long LL; LL n,a[maxn],cnt[maxn],num[maxn]; int main(){ scanf("%lld",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); for(int i=1;i<=n;i++){ LL t=a[i]; while(t%2==0){ cnt[i]++; t/=2; } num[cnt[i]]++; } int ans=0,maxcnt; for(int i=0;i<63;i++) if(num[i]>ans){ ans=num[i]; maxcnt=i; } printf("%lld\n",n-ans); for(int i=1;i<=n;i++) if(cnt[i]!=maxcnt)printf("%lld ",a[i]); cout<<endl; return 0; }
CodeForces 1225D??