A - wwwvvvvvv
直接模拟
#include<cstdio>
#include<cstring>
const int N = 105;
int n, ans;
char s[N];
int main() {
scanf("%s", s + 1);
for(int i = 1; i <= strlen(s +1); i ++) {
if(s[i] == 'v') ans ++;
else ans += 2;
}
printf("%d", ans);
return 0;
}
B - LOOKUP
枚举模拟。
#include<cstdio>
#include<cstring>
const int N = 105;
int n, m, ans;
char s[N], t[N];
int main() {
scanf("%s %s", s + 1, t + 1);
n = strlen(s + 1), m = strlen(t + 1);
for(int i = 1, j; i + m - 1 <= n; i ++) {
for(j = 1; j <= m; j ++) {
if(s[i + j - 1] != t[j]) break;
}
//printf("%d %d\n", i, j);
if(j == m + 1) {
puts("Yes");
return 0;
}
}
puts("No");
return 0;
}
C - RANDOM
只要将字符数组每列都存储一下,再通过枚举其中一个字符数组的列,寻找在另一个字符数组中是否有与其相同的列即可。
#include<bits/stdc++.h>
using namespace std;
int main() {
int h,w;
cin >> h >> w;
vector <string> s(w);
vector <string> t(w);
for(int i = 0; i < h; i ++) {
for(int j = 0; j < w; j ++) {
s[j].resize(h), cin >> s[j][i];
}
}
for(int i = 0; i < h; i ++) {
for(int j = 0; j < w; j ++) {
t[j].resize(h), cin >> t[j][i];
}
}
sort(s.begin(), s.end()), sort(t.begin(), t.end());
for(int i = 0; i < w; i ++) {
if(s[i] != t[i]){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
D - Freefall
三分。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define int long long
long double a, b, c, d;
long double num(int x) {
return b * x + a / sqrt(x + 1);
}
signed main() {
scanf("%llf %llf", &a, &b), c = a;
int l, r, mid;
if(a < b) {
mid = 1;
while(1) {
d = num(mid);
if(d > c) {
printf("%.10llf", c);
return 0;
}
c = d, mid ++;
}
}
else {
l = 0, r = 1e18;
while(l <= r) {
mid = (r - l) / 2 + l;
if(num(mid) < num(mid - 1) && num(mid) < num(mid + 1)) {
printf("%.10llf", num(mid));
return 0;
}
if(num(mid) < num(mid - 1)) l = mid + 1;
else r = mid - 1;
}
}
return 0;
}
E - Cheating Amidakuji
。。。
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 2e5 + 5;
int n, m, a[N], b[N], c[N], ans[N];
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= m; i ++) scanf("%d", &a[i]), c[i] = i;
b[1] = 1;
for(int i = 1, j; i < m; i ++) {
j = b[i];
if(j == a[i]) b[i + 1] = j + 1;
else if(j == a[i] + 1) b[i + 1] = j - 1;
else b[i + 1] = j;
}
for(int i = m; i; i --) {
ans[i] = c[b[i]];
swap(c[a[i]], c[a[i] + 1]);
}
for(int i = 1; i <= m; i ++) printf("%d\n", ans[i]);
return 0;
}
标签:AtCoder,main,int,题解,scanf,mid,++,279,include
From: https://www.cnblogs.com/Spring-Araki/p/17161767.html