比赛链接

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 4e5+10;




void sol(){
int x; cin >> x;
int p = sqrt(x);
if (p * (p + 1) == x)
cout << "YES" <<endl;
else
cout << "NO" << endl;
}


int main(){
IO
sol();
}

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 2e5 + 10;

int t;
int n, a[N];

void sol(){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++)
for (int j = i +1; j <= n; j++)
if (__gcd(a[i], a[j]) > 1){
cout << a[i] << ' ' << a[j] << endl;
return;
}
cout << -1 <<endl;
}


int main(){
IO
cin >> t;
while (t--){
sol();
}
}

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

// patternStart=0 表示模板 P = 0101...
// patternStart=1 表示模板 P = 1010...
// 我们抽出所有 s[i] == P[i] 的位置,形成 mid,求 mid 的最大绝对子段和
int calc(const string &s, int patternStart) {
int mx = 0, mn = 0; // 最大/最小子段和
int curMax = 0, curMin = 0;

int n = (int)s.size();
for (int i = 0; i < n; i++) {
char expected = ((i & 1) == 0 ? (patternStart ? '1' : '0')
: (patternStart ? '0' : '1'));
if (s[i] == expected) {
int val = (s[i] == '1') ? 1 : -1; // '1'->+1, '0'->-1

// Kadane 最大子段和
curMax = max(0, curMax + val);
mx = max(mx, curMax);

// Kadane 最小子段和
curMin = min(0, curMin + val);
mn = min(mn, curMin);
}
}
return max(mx, -mn);
}

int main() {
IO
int T;
cin >> T;
while (T--) {
int n;
string s;
cin >> n >> s;

// 变成 1010...:抽 P=0101... 的匹配位
// 变成 0101...:抽 P=1010... 的匹配位
int ans = min(calc(s, 0), calc(s, 1));
cout << ans << endl;
}
return 0;
}

F

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 510;

//int atx[13] = {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2};
//int aty[13] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};

void sol(){
int n; cin >> n;
cout << n - 1 + n / 5 << endl;
}


int main(){
IO
int t;
cin >> t;
while (t--){
sol();
}
}

G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 1e5 + 10;

int t;


void sol(){
int n, m; cin >> n >> m;
int a[N], b[N];
ls sum1 = 0; ls sum2 = 0;
for (int i = 1 ; i<= n; i++){
cin >> a[i];
sum1 += a[i];
}
for (int i = 1; i <= m; i++){
cin >> b[i];
sum2 += b[i];
}
if (sum1 == sum2){
cout << 1 << endl;
return;
}
else if (sum1 < sum2){
sort(b + 1, b + m + 1);
int k = 0;
for (int i = m; i >= 1; i--)
{
sum2 -= b[i];
k++;
if (sum2 <= sum1)
break;
}
cout << k << endl;
}
else{
sort(a + 1, a + n + 1);
int k = 0;
for (int i = n; i >= 1; i--)
{
sum1 -= a[i];
k++;
if (sum2 >= sum1)
break;
}
cout << k << endl;
}
}


int main(){
IO
cin >> t;
while (t--)
sol();
}

H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 2e5 + 10;

void sol(){
double xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb;
if (xa == xb){
printf("%.8lf", 4.0 / fabs(ya-yb)+fabs(xa));
return;
}
if (ya == yb){
if (fabs(xa-xb)*fabs(ya)==4)
printf("0");
else
printf("no answer");
return;
}
double lenab = (double)sqrt((double)(xa-xb)*(xa-xb)+(double)(ya-yb)*(ya-yb));
double h = 4.0 / lenab;
double k = (double)(yb-ya)/(xb-xa);
double b = ya - k * xa;
printf("%.8lf", (h*sqrt(1+k*k)-b)/k);
}


int main(){
IO
// cin >> t;
// while (t--){
sol();
// }
}

J

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;

#define IO ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ls;
const int N = 1e5 + 10;

int t;

ls qs(ls a, ls p){
ls ans = 1;
while (p){
if (p % 2 == 1){
ans *= a;
}
p >>= 1;
a *= a;
}
return ans;
}


void sol(){
ls n; cin >> n;
int q; cin >> q;
while (q--){
ls x; cin >> x;
ls l = 1, r = 68;
while (l < r){
ls mid = l + (r - l) / 2;
if (qs(2, mid) > x)
r = mid;
else
l = mid + 1;
}
if (qs(2, l) - 1 <= n)
cout << qs(2, l - 1) << endl;
else{
cout << n - qs(2, l - 1) + 1 << endl;
}
}
}


int main(){
IO
cin >> t;
while (t--)
sol();
}