偷个懒,先发下前6题代码,第七题还可以优化(困了,醒得来就明早写,醒不来就咕咕咕)
A
#include<bits/stdc++.h>
using namespace std;
int x[3], y[3], t;
int main()
{
cin >> t;
while(t --)
{
for(int i = 0; i < 3; i ++) cin >> x[i] >> y[i];
int res = abs(x[0] - x[1]) + abs(y[0] - y[1]);
if(x[0] == x[1] && x[0] == x[2] && min(y[0], y[1]) < y[2] && y[2] < max(y[0], y[1])) res += 2;
if(y[0] == y[1] && y[0] == y[2] && min(x[0], x[1]) < x[2] && x[2] < max(x[0], x[1])) res += 2;
cout << res << endl;
}
}
B
#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin >> t;
while(t --)
{
string s;
cin >> s;
int i = 0, j = s.size() - 1;
while(i < j)
{
if(s[i] == 'a' + j - i) i ++;
else if(s[j] == 'a' + j - i) j --;
else break;
}
if(i == j && s[i] == 'a') cout << "YES\n";
else cout << "NO\n";
}
}
C
#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin >> t;
while(t --)
{
int k, n, m;
cin >> k >> n >> m;
vector<int> a(n), b(m), res(n + m);
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 0; i < m; i ++) cin >> b[i];
int i = 0, j = 0, u = 0;
while(u < n + m)
{
if(i < n && a[i] == 0) res[u ++] = a[i ++], k ++;
else if(j < m && b[j] == 0) res[u ++] = b[j ++], k ++;
else
{
if(i < n && a[i] <= k) res[u ++] = a[i ++];
else if(j < m && b[j] <= k) res[u ++] = b[j ++];
else break;
}
}
if(u < n + m)
{
cout << -1 << endl;
continue;
}
for(auto x : res) cout << x << ' ';
cout << endl;
}
}
D
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
int main()
{
cin >> t;
while(t --)
{
ll n, u;
cin >> n;
vector<ll> a(n), res(n, 0);
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 1; i < n; i ++)
{
res[i] = (res[i - 1] | a[i - 1] | a[i]) - a[i];
}
for(auto x : res) cout << x << ' ';
cout << endl;
}
}
E
#include <bits/stdc++.h>
using namespace std;
int t, k, n;
int main()
{
cin >> t;
while(t --)
{
cin >> n >> k;
vector<int> a(n, 2e9 + 10), p(k), d(k);
for(int i = 0; i < k; i ++) cin >> p[i], p[i] --;
for(int i = 0; i < k; i ++) cin >> d[i], a[p[i]] = d[i];
for(int i = 1; i < n; i ++) a[i] = min(a[i], a[i - 1] + 1);
for(int i = n - 2; i >= 0; i --) a[i] = min(a[i], a[i + 1] + 1);
for(int x : a) cout << x << ' ';
cout << endl;
}
return 0;
}
F
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t, n;
const int N = 2e5 + 10;
int a[N];
struct Node{
int l, r, gcd;
} tr[4 * N];
void build(int u, int l, int r)
{
if(l == r) tr[u] = {l, r, a[l]};
else
{
tr[u] = {l, r};
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
tr[u].gcd = __gcd(tr[u << 1].gcd, tr[u << 1 | 1].gcd);
}
}
int query(int u, int l, int r)
{
if(l <= tr[u].l && tr[u].r <= r) return tr[u].gcd;
int mid = tr[u].l + tr[u].r >> 1;
if(l > mid) return query(u << 1 | 1, l, r);
else if(r <= mid) return query(u << 1, l, r);
else return __gcd(query(u << 1, l, r) , query(u << 1 | 1, l, r));
}
int query(int l , int r)
{
if(l <= r) return query(1, l, r);
return __gcd(query(1, l, n), query(1, 1, r));
}
int main()
{
cin >> t;
while(t --)
{
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
bool eq = true;
for(int i = 2; i <= n; i ++)
if(a[i] != a[1]) eq = false;
if(eq)
{
cout << 0 << endl;
continue;
}
int g = a[1];
for(int i = 2; i <= n; i ++) g = __gcd(a[i], g);
for(int i = 1; i <= n; i ++) a[i] /= g;
build(1, 1, n);
int cnt = 1;
for(int i = 1; i <= n; i ++)
while(query(i, (i + cnt > n) ? (i + cnt - n) : (i + cnt)) > 1) cnt ++;
cout << cnt << endl;
}
}
码风和思路 真的很赞~
hhhhhh码风有点y总有没有,但是比赛的时候一塌糊涂哈哈哈哈都不敢发,每次都是重新写
谢谢你!
确实啊!! 我正想说呢hhh