A题是一道模拟题按照题目的意思模拟就行,B题是一道思维题,C题是一道数论的题,D题是一道思维题,E题是一道树上差分的问题,E题关于树上差分看了好多博客其实还是不太理解。
#include<iostream>
using namespace std;
const int N = 1010;
int h[N];
int a, b, k, n, m;
int main()
{
int T;cin >> T;
while(T --)
{
scanf("%d", &n);
for(int i = 0; i < n; ++ i) scanf("%d", &h[i]);
scanf("%d%d%d%d", &a, &k, &b, &m);
for(int i = 1; i <= m - 1; i ++)
{
for(int j = 0; j < n; ++ j)
{
h[j] += a;
if(h[j] > k) h[j] = b;
}
}
for(int i = 0; i < n; ++ i) printf("%d ", h[i]);
cout << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int T;cin >> T;
while(T --)
{
long long l, r;cin >> l >> r;
long long sum = (l + r) * (r - l + 1) / 2;
long long m;cin >> m;
while(m --)
{
long long x;cin >> x;
if(sum % x) cout << 1 << endl;
else cout << 0 << endl;
}
}
return 0;
}
c题是对a中的所有数分解质因数,然后枚举b中的数,看b中数的质因数是否在a的质因子里面出现过。
#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 1e5 + 110;
int a[N], b[N];
int n;
int main()
{
unordered_map<int, int>mp;
cin >> n;
for(int i = 0; i < n; ++ i) scanf("%d", &a[i]);
for(int i = 0; i < n; ++ i) scanf("%d", &b[i]);
for(int i = 0; i < n; ++ i)
{
int k = a[i];
for(int j = 2; j <= k / j; ++ j)
{
if(k % j == 0)
{
while(k % j == 0) k /= j;
mp[j] ++;
}
}
if(k > 1) mp[k] ++;
}
for(int i = 0; i < n; ++ i)
{
int k = b[i];
for(int j = 2; j <= k / j; ++ j)
{
if(k % j == 0)
{
while(k % j == 0) k /= j;
if(mp[j])
{
cout << "No" << endl;
return 0;
}
}
}
if(k > 1 && mp[k])
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
#include <iostream>
using namespace std;
typedef long long ll;
void solve()
{
ll n;
int k, m;
cin >> n >> k >> m;
while(m --)
{
ll q;
ll ans = 0;
scanf("%lld", &q);
if(k == 1) cout << n - q << endl;
else
{
ll l = q, r = q;
while(l <= n)
{
ans += r - l + 1;
r = min(k * r + k, n - 1);
l = k * l + 1;
}
cout << ans << endl;
}
}
}
int main()
{
int T;cin >> T;
while(T --) solve();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 10000009, M = 500009;
int n;
int rt[N][2];
int cnt[M];
int dfs(int x, int sum) {
if(x > n) return 0;
sum += rt[x][0];
int ans = sum, add = rt[x][1];
add += dfs(2 * x, sum);
add += dfs(2 * x + 1, sum);
cnt[ans + add] ++;
return add;
}
int main() {
int m; cin >> n >> m;
int op, x;
for(int i = 0; i < m; i ++) {
cin >> op >> x;
if(op == 1) {
rt[x][0] ++;
} else if(op == 2) {
rt[x][0] --;
rt[1][0] ++;
} else if(op == 3) {
rt[x][1] ++;
} else {
rt[x][1] --;
rt[1][0] ++;
}
}
dfs(1, 0);
for(int i = 0; i <= m; i ++) cout << cnt[i] << ' ';
return 0;
}
这种做法好像不是差分的做法了
#include <iostream>
using namespace std;
const int N = 1e8 + 10;
int n, m;
int cf[N], ans[N], tag[N];
void dfs(int u, int f)
{
if(u > n) return;
int w = 0;
w += cf[u];
w += tag[u];
ans[w] ++;
cf[u * 2] += cf[u];
cf[u * 2 + 1] += cf[u];
dfs(u * 2, u);
dfs(u * 2 + 1, u);
}
int main()
{
cin >> n >> m;
for(int i = 0; i < m; ++ i)
{
int op, x; scanf("%d%d", &op, &x);
if(op == 1) cf[x] ++;
else if(op == 2)
{
cf[x] --;
cf[1] ++;
}
else if(op == 3)
{
while(x)
{
tag[x] ++;
x /= 2;
}
}
else if(op == 4)
{
while(x)
{
tag[x] --;
x /= 2;
}
cf[1] ++;
}
}
dfs(1, 0);
for(int i = 0; i <= m; ++ i) printf("%d ", ans[i]);
return 0;
}
F题没做
标签:cin,int,++,long,cf,牛客,62,小白月赛,op From: https://www.cnblogs.com/cxy8/p/16970015.html