C - 2D Plane 2N Points
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
Constraints
- All input values are integers.
- 1≤N≤100
- 0≤ai,bi,ci,di<2N
- a1,a2,…,aN,c1,c2,…,cN are all different.
- b1,b2,…,bN,d1,d2,…,dN are all different.
Input
Input is given from Standard Input in the following format:
Na1 b1a2 b2:aN bNc1 d1c2 d2:cN dN
Output
Print the maximum number of friendly pairs.
Sample Input 1
32 03 11 34 20 45 5
Sample Output 1
2
For example, you can pair (2,0) and (4,2), then (3,1) and (5,5).
Sample Input 2
30 01 15 22 33 44 5
Sample Output 2
2
For example, you can pair (0,0) and (2,3), then (1,1) and (3,4).
Sample Input 3
22 23 30 01 1
Sample Output 3
0
It is possible that no pair can be formed.
Sample Input 4
50 07 32 24 81 68 56 95 49 13 7
Sample Output 4
5
Sample Input 5
50 01 15 56 67 72 23 34 48 89 9
Sample Output 5
4
这个题目的描述很简单,就是有A,B两个集合,你要找到两个集合最多匹配的个数,匹配的是B中的元素横纵坐标都是比A的大,这里采用二分,查询另一个分组是不是存在这样的元素,每次都选择与其最相近的元素
(相当于排序之后不够考虑一个坐标轴)
#includeusing namespace std;#define Fi first#define Se secondpair ,int>p[1005];int n;int main(){ cin>>n; for(int i=0; i >p[i].Fi.Fi>>p[i].Fi.Se,p[i].Se=i>=n; sort(p,p+n+n); set s; int ans=0; for(int i=0; i p[i].Fi.Se))s.erase(--s.lower_bound(p[i].Fi.Se)),ans++; else if(!p[i].Se)s.insert(p[i].Fi.Se); cout<
D - Two Sequences
Time limit : 3sec / Memory limit : 256MB
Score : 500 points
Problem Statement
You are given two integer sequences, each of length N: a1,…,aN and b1,…,bN.
There are N2 ways to choose two integers i and j such that 1≤i,j≤N. For each of these N2 pairs, we will compute ai+bj and write it on a sheet of paper. That is, we will write N2 integers in total.
Compute the XOR of these N2 integers.
Definition of XOR
Constraints
- All input values are integers.
- 1≤N≤200,000
- 0≤ai,bi<228
Input
Input is given from Standard Input in the following format:
Na1 a2 … aNb1 b2 … bN
Output
Print the result of the computation.
Sample Input 1
21 23 4
Sample Output 1
2
On the sheet, the following four integers will be written: 4(1+3),5(1+4),5(2+3) and 6(2+4).
Sample Input 2
64 6 0 0 3 30 5 6 5 0 3
Sample Output 2
8
Sample Input 3
51 2 3 4 51 2 3 4 5
Sample Output 3
2
Sample Input 4
100
Sample Output 4
0
这个题目也是有点意思,题目还是很好懂的
int Add(int a,int b){ return b?Add(a^b,(a&b)<<1):a;}
位运算实现两数相减
int MINUS(int a,int b){ return b?MINUS(a^b,((a^b)&b)<<1):a;}
#includeusing namespace std;const int N=2e5+5;int a[N],b[N];int main(){ int n,r=0; cin>>n; for(int i=0; i >a[i]; for(int i=0; i >b[i]; if(n&1) { for(int i=0; i >=1) { for(int j=0; j