目录
A - Meeting of Old Friends
题目链接https://codeforces.com/problemset/problem/714/A
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int main()
{
ll a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
if (a > c) swap(a, c);
if (b > d) swap(b, d);
ll ans = 0;
if (b - c < 0) cout << "0" << '\n';
else {
ans = b - c + 1;
if (k >= c && k <= b) ans--;
cout << ans << endl;;
}
return 0;
}
B - Filya and Homework
题目链接https://codeforces.com/problemset/problem/714/B
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int a[mac];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
if (a[1] == a[n]) {
printf("YES\n");
return 0;
}
else {
int p = -1, nb = 0, a1 = -1, a2 = -1, a3 = -1;
for (int i = 1; i <= n; i++) {
if (a[i] != p) {
nb++, p = a[i];
if (a1 < 0) a1 = a[i];
else if (a2 < 0) a2 = a[i];
else a3 = a[i];
}
}
if (nb > 3) printf("NO\n");
else {
if(nb < 3 ||(nb == 3 && a3 - a2 == a2 - a1))
cout << "YES" ;
else {
cout << "NO";
}
}
}
return 0;
}
C - Sonya and Queries
题目链接https://codeforces.com/problemset/problem/714/C
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
char s[50], ss[10];
int vis[1 << 20];
int main()
{
int n;
scanf("%d", &n);
while (n--) {
scanf("%s%s", ss, s);
if (ss[0] == '+') {
int len = strlen(s);
int sum = 0;
for (int i = 0; i < len; i++) {
if (s[i] & 1) sum = sum << 1 | 1;
else sum = sum << 1;
}
vis[sum]++;
}
else if (ss[0] == '-') {
int len = strlen(s);
int sum = 0;
for (int i = 0; i < len; i++) {
if (s[i] & 1) sum = sum << 1 | 1;
else sum = sum << 1;
}
vis[sum]--;
}
else {
int len = strlen(s);
int sum = 0;
for (int i = 0; i < len; i++) {
if (s[i] & 1) sum = sum << 1 | 1;
else sum = sum << 1;
}
printf("%d\n", vis[sum]);
}
}
return 0;
}
D - Crazy Computer
题目链接https://codeforces.com/problemset/problem/716/A
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int a[mac];
int main()
{
int n,m;
scanf("%d%d", &n,&m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
if (n==1) {
printf ("1\n");
return 0;
}
int ans=1;
int x=1;
for (int i=2; i<=n; i++){
if (a[i]-a[i-1]>m) x=i;
}
ans=n-x+1;
printf ("%d\n",ans);
return 0;
}
E - Complete the Word
题目链接https://codeforces.com/problemset/problem/716/B
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
char s[mac];
int vis[mac];
int main()
{
scanf("%s", s);
int len = strlen(s);
if (len < 26) printf("-1\n");
else {
int mark = -1, tail = 0;
for (int i = 0; i < len; i++) {
if (mark!=-1) break;
if (s[i] != '?') {
vis[s[i] - 'A']++;
while (vis[s[i] - 'A'] > 1) {
vis[s[tail] - 'A']--;
tail++;
}
}
if (i - tail + 1 == 26 ) mark = tail;
}
if (mark == -1) {
printf("-1\n"); return 0;
}
for (int i = 0; i < len; i++) {
if (i == mark) {
for (int j = i; j < i + 26; j++) {
if (s[j] == '?') {
for (int k = 0; k < 26; k++) {
if (!vis[k]) {
printf("%c", 'A' + k);
vis[k] ++; break;
}
}
}
else printf("%c", s[j]);
}
i += 26;
}
if (i >= len) {
printf("\n"); return 0;
}
if (s[i] == '?') printf("A");
else printf("%c", s[i]);
}
printf("\n");
}
return 0;
}
F - Plus and Square Root
题目链接https://codeforces.com/problemset/problem/716/C
#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
char s[mac];
int vis[mac];
int main()
{
int n;
ll ans = 0, stp = 0, now = 2, lev = 1;
scanf("%d", &n);
for (ll i = 1; i < n + 1; i++) {
if (i == 1) printf("2\n");
else {
ans = i * (i + 1) * (i + 1) - (i - 1);
printf("%lld\n", ans);
}
}
return 0;
}