# A - City of Lights

Sign-in question.

``````#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, k;
int a[N];
int main() {

cin >> n >> k;
int cnt = 0;
int maxx = 0;
memset(a, 0, sizeof a);
for (int i = 0; i < k; i++) {

int x;
cin >> x;
for (int j = 1; j <= n / x; j++) {

if (a[j * x] == 0) {

a[j * x] = 1;
cnt++;
} else {

a[j * x] = 0;
cnt--;
}
}
maxx = max(maxx, cnt);
}
cout << maxx << endl;
return 0;
}
``````

# B - Blurred Pictures

## Title:

Find the largest square that can be cut, traverse the side length from 1 and traverse from top to bottom, and then judge.

## Code:

``````#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int x[N], y[N];
int n;

int judge(int upside, int l) {

if (x[upside] + l > y[upside]) return 0;
if (upside + l > n) return 0;
int downside = upside + l;
int left = max(x[upside], x[downside]);
if (left + l <= y[upside] && left + l <= y[downside]) return 1;
return 0;
}

int main() {

int maxx = 1;
cin >> n;
for (int i = 1; i <= n; i++) {

cin >> x[i] >> y[i];
}
for (int i = 1; i <= n; i++) {

while (judge(i, maxx)) maxx++;
}
cout << maxx << endl;
}
``````

# D - Monument Tower

``````#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int X, Y;
struct node {

int x, y;
} p[N];
int maxx[N], minn[N], lie[N];
bool cmp(node a, node b) {

return a.y < b.y; }

int main()
{

cin >> X >> Y;
memset(p, 0, sizeof p);
memset(maxx, -1, sizeof maxx);
memset(minn, 0x3f, sizeof minn);
memset(lie, 0, sizeof lie);
int n;
cin >> n;
long long pos = 0;
for (int i = 0; i < n; i++) {

cin >> p[i].x >> p[i].y;
maxx[p[i].x] = max(maxx[p[i].x], p[i].y);
minn[p[i].x] = min(minn[p[i].x], p[i].y);
}
long long cnt = 0;
for (int i = 0; i < 100005; i++) {

if (maxx[i] != -1 && minn[i] != 0x3f3f3f3f) {

lie[cnt++] = maxx[i];
lie[cnt++] = minn[i];
}
}
sort(lie, lie + cnt);
long long mid = lie[(cnt - 1) / 2];
long long ans = X - 1;
for (int i = 0; i < 100005; i++) {

if (maxx[i] != -1 && minn[i] != 0x3f3f3f3f) {

ans += maxx[i] - minn[i] + abs(mid - maxx[i]) + abs(mid - minn[i]);
}
}
cout << ans << endl;
}
``````

# E - Rounding

to the title Find the approximate value, because you need to judge the two decimal places, you have to multiply it by 100 at the beginning, and then convert it back.
Because of rounding, the first number you want at the beginning is all minus 50, and the second number is all plus 49. Then add on the basis of the first number. If the last number is greater than the second number, then it cannot be adjusted and the IMPOSSIBLE is output.

``````#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;

int n, sum, k = 10000;
int a[N], num[N][2];
char name[N][50];
int main()
{

cin >> n;
for(int i = 0; i < n; i ++)
{

cin >> name[i] >> a[i];
a[i] *= 100;
sum += a[i];
num[i][0] = a[i] - 50;
num[i][1] = a[i] + 49;
if(a[i] == 0) num[i][0] = a[i];
if(a[i] == k) num[i][1] = a[i];
}
for(int i = 0; i < n; i ++)
{

num[i][0] = max(num[i][0], a[i] + k - sum - (n - 1) * 49 );
num[i][1] = min(num[i][1], a[i] + k - sum + (n - 1) * 50 );
if(num[i][0] > num[i][1])
{

cout << "IMPOSSIBLE" << endl;
return 0;
}
}
for(int i = 0; i < n; i ++)
printf("%s %.2f %.2f\n", name[i], num[i][0] * 1.0 / 100, num[i][1] * 1.0 / 100);

}
``````

### Guess you like

Origin blog.csdn.net/qq_47783181/article/details/112759873
Recommended
Ranking
Daily