You are given a set of nn segments on the axis OxOx, each segment has integer endpoints between 11 and mm inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — coordinates of the left and of the right endpoints.
Consider all integer points between 11 and mm inclusive. Your task is to print all such points that don't belong to any segment. The point xxbelongs to the segment [l;r][l;r] if and only if l≤x≤rl≤x≤r.
The first line of the input contains two integers nn and mm (1≤n,m≤1001≤n,m≤100) — the number of segments and the upper bound for coordinates.
The next nn lines contain two integers each lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — the endpoints of the ii-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that li=rili=ri, i.e. a segment can degenerate to a point.
In the first line print one integer kk — the number of points that don't belong to any segment.
In the second line print exactly kk integers in any order — the points that don't belong to any segment. All points you print should be distinct.
If there are no such points at all, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.
3 5
2 2
1 2
5 5
2
3 4
1 7
1 7
0
In the first example the point 11 belongs to the second segment, the point 22 belongs to the first and the second segments and the point 55belongs to the third segment. The points 33 and 44 do not belong to any segment.
In the second example all the points from 11 to 77 belong to the first segment.
区间中有多少个没有被遮住的数
1 #include <iostream> 2 3 using namespace std; 4 int a[1000]; 5 int b[1000]; 6 int n,m; 7 int main(){ 8 cin>>n>>m; 9 for(int i=0;i<n;i++){ 10 int x,y; 11 cin>>x>>y; 12 for(int i=x;i<=y;i++) 13 a[i]=1; 14 } 15 int ans = 0; 16 int cnt = 0; 17 for(int i=1;i<=m;i++){ 18 if(a[i]==0){ 19 b[ans++] = i; 20 cnt++; 21 } 22 } 23 cout<<cnt<<endl; 24 for(int i=0;i<ans;i++){ 25 cout<<b[i]<<" "; 26 } 27 cout<<endl; 28 return 0; 29 }
You are given two strings ss and tt. Both strings have length nn and consist of lowercase Latin letters. The characters in the strings are numbered from 11 to nn.
You can successively perform the following move any number of times (possibly, zero):
- swap any two adjacent (neighboring) characters of ss (i.e. for any i={1,2,…,n−1}i={1,2,…,n−1} you can swap sisi and si+1)si+1).
You can't apply a move to the string tt. The moves are applied to the string ss one after another.
Your task is to obtain the string tt from the string ss. Find any way to do it with at most 104104 such moves.
You do not have to minimize the number of moves, just find any sequence of moves of length 104104 or less to transform ss into tt.
The first line of the input contains one integer nn (1≤n≤501≤n≤50) — the length of strings ss and tt.
The second line of the input contains the string ss consisting of nn lowercase Latin letters.
The third line of the input contains the string tt consisting of nn lowercase Latin letters.
If it is impossible to obtain the string tt using moves, print "-1".
Otherwise in the first line print one integer kk — the number of moves to transform ss to tt. Note that kk must be an integer number between 00and 104104 inclusive.
In the second line print kk integers cjcj (1≤cj<n1≤cj<n), where cjcj means that on the jj-th move you swap characters scjscj and scj+1scj+1.
If you do not need to apply any moves, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.
6
abcdef
abdfec
4
3 5 4 5
4
abcd
accd
-1
In the first example the string ss changes as follows: "abcdef" →→ "abdcef" →→ "abdcfe" →→ "abdfce" →→ "abdfec".
In the second example there is no way to transform the string ss into the string tt through any allowed moves.
暴力交换就行了.不会超时.
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 int a[10000]; 5 int main(){ 6 int n; 7 string s,ss; 8 cin>>n; 9 cin>>s>>ss; 10 if(s==ss){ 11 cout<<"0"<<endl; 12 return 0; 13 } 14 string st = s; 15 sort(st.begin(),st.end()); 16 string stt = ss; 17 sort(stt.begin(),stt.end()); 18 if(st != stt){ 19 cout<<"-1"<<endl; 20 return 0; 21 } 22 int ans = 0; 23 for(int i=0;i<n;i++){ 24 if(s[i]!=ss[i]){ 25 for(int j = i;j<n;j++){ 26 if(s[j] == ss[i]){ 27 a[ans++] = j; 28 char c = s[j]; 29 s[j] = s[j-1]; 30 s[j-1] = c; 31 i--; 32 break; 33 } 34 } 35 } 36 } 37 cout<<ans<<endl; 38 for(int i=0;i<ans;i++) 39 cout<<a[i]<<" "; 40 cout<<endl; 41 42 return 0; 43 }