1.
[Programming Questions] programming questions 1
Time limit: 1 seconds
Space limit: 32768K
P is a given two-dimensional set of planar integer points. Defines a point x in P, which is called "maximum" if x satisfies any point in P that is not in the upper-right area of x (the horizontal ordinate is greater than X). Find out the collection of all "maximum" points. (The horizontal and vertical axes of all points are not duplicated, the axis range is within [0, 1E9)]
The following illustration: A solid point is a collection of points that meet the criteria. Please implement the code to find the collection of all "maximum" points in the collection P and output.
Input Description:
The first line enters the number of points set N, the next n rows, and two numbers per row represent the X-and Y-axes of the point.
for 50% data, 1 <= N <= 10000;
For 100% data, 1 <= N <= 500000;
Output Description:
Outputs the "largest" point collection, which is output from small to large on the x-axis, representing the x-axis and y-axis of the point, respectively, for each line of two digits.
Input Example 1:
5
1 2
5 3
4 6
7 5
9 0
Output Example 1:
4 6
7 5
9 0
AC Code:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 5e5+5;
struct node{
int x, y;
node (int x,int y): x (x), Y (y) {}
node () {}
bool operator< (const node& N) Const {
return this->x < n.x;
}
};
struct node ND[MAXN];
int FLAG[MAXN];
int main () {
int n;
while (scanf ("%d", &n) = = 1) {
for (int i = 0; i < n; i++)
scanf ("%d%d", &nd[i].x,&nd[i].y);
Sort (nd,nd+n);
memset (flag,0,sizeof (flag));
Flag[n-1] = 1;
int Max1 = ND[N-1].Y;
for (int i = n-2; I >= 0; i--) {
if (Nd[i].y < MAX1) continue;
Max1 = nd[i].y;
Flag[i] = 1;
}
for (int i = 0; i < n; i++) {
if (Flag[i]) printf ("%d%d\n", nd[i].x,nd[i].y);
}
}
return 0;
}
2.
[Programming questions] programming questions 2
Time limit: 3 seconds
Space limit: 131072K
Given an array sequence, a range is required to be selected so that the interval is the largest of the values calculated in all the intervals as follows:
The minimum number in the interval * interval all the number and the final program output after the calculated maximum value, do not need to output a specific interval. If the given sequence [6 2 1] is based on the above formula, you can get all the calculated values that can be selected for each interval:
[6] = 6 * 6 = 36;
[2] = 2 * 2 = 4;
[1] = 1 * 1 = 1;
[6,2] = 2 * 8 = 16;
[2,1] = 1 * 3 = 3;
[6, 2, 1] = 1 * 9 = 9;
The selected interval is visible from the above calculation [6] and the value is 36, then the program output is 36.
All the numbers within the interval are within the range of [0, 100];
Input Description:
The first line enters the array sequence length n, and the second line enters the array sequence.
for 50% data, 1 <= n <= 10000;
For 100% data, 1 <= n <= 500000;
Output Description:
The maximum value after which the output array has been computed.
Input Example 1:
3
6 2 1
Output Example 1:
36
AC Code:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 5E5+10;
int A[MAXN];
int n;
int main () {while
(scanf ("%d", &n) = = 1) {for
(int i = 1; I <= n; i++)
{
scanf ("%d", &a[i]); c14/>}
int Max1 = 0;
for (int i = 1; I <= n; i++) {
int Min1 = a[i];
int sum = a[i];
for (int j = i-1; J >=1; j--) {
if (A[j] >= Min1) sum + = a[j];
else break;
}
for (int j = i+1; J <=n; J + +) {
if (A[j] >= Min1) sum + = a[j];
else break;
}
MAX1 = Max (Max1,sum * Min1);
}
printf ("%d\n", Max1);
}
return 0;
}