#include <bits/stdc++.h>
using namespace std;
int n, x, y, m;
int k[20], p[20];
int main()
{
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) cin >> k[i];
cin >> m;
for (int i = 1; i <= m; i++) cin >> p[i];
bool f1 = 1, f2 = 1;
for (int i = x + 1; i <= x + m; i++)
if (k[i] != p[i - x]) f2 = 0;
for (int i = x - 1; i >= x - m; i--)
if (k[i] != p[x - i]) f1 = 0;
if (f1 == 1 && f2 == 1) cout << "Unsure";
else if (f1 == 1 && y < x) cout << "Right";
else if (f2 == 1 && x < y) cout << "Right";
else cout << "Wrong";
return 0;
}
View Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int n, a[N];
ll ans;
int main()
{
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++)
ans += max(a[i], a[i + 1]);
cout << ans;
return 0;
}
View Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0, x, y; i < n; i++) cin >> x >> y;
double ans = 1.0 / n;
printf("%.12f", ans);
return 0;
}
View Code
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, m, q, x, y;
string s;
bool vis[N][N];
int path[8][2] = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
bool check(int d)
{
if (d == 1 || d == 3 || d == 5 || d == 7)
{
if ((vis[x + path[(d + 7) % 8][0]][y + path[(d + 7) % 8][1]]) && (vis[x + path[(d + 1) % 8][0]][y + path[(d + 1) % 8][1]]))
return true;
}
return false;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> s;
for (int j = 0; j < m; j++)
if (s[j] == '.') vis[i][j + 1] = 0;
else if (s[j] == '#') vis[i][j + 1] = 1;
else vis[i][j + 1] = 0, x = i, y = j + 1;
}
cin >> q >> s;
int v = 0, d = 0;
for (int i = 0; i < q; i++)
{
bool f = 1;
if (s[i] == 'L') d = (d + 7) % 8;
else if (s[i] == 'R') d = (d + 1) % 8;
else if (s[i] == 'U') v++;
else v = max(v - 1, 0);
int tx, ty;
for (int j = 0; j < v; j++)
{
tx = x + (path[d][0]), ty = y + (path[d][1]);
if (vis[tx][ty] == 1 || tx <= 0 || ty <= 0 || tx > n || ty > m || check(d))
{
printf("Crash! %d %d\n", x, y);
v = f = 0;
break;
}
x = tx, y = ty;
}
if (f) printf("%d %d\n", x, y);
}
return 0;
}
View Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n, cnt = 0;
cin >> n;
char ch;
while (cin >> ch) if (ch == '-') cnt++;
cout << cnt;
return 0;
}
View Code