A
输出
−
1
∗
s
u
m
-1 * sum
−1∗sum
void solve()
{
int n;
cin >> n;
int sum = 0;
for (int i = 1;i < n;i++)
{
int x;
cin >> x;
sum += x;
}
cout << -1 * sum << "\n";
}
B
统计一下每个花费能传播多少个人,排个序,贪心的考虑,优先选花费 < p的,剩下的用花费p传播,注意要保证至少花费一次p
void solve()
{
mp.clear();
ll n,p;
cin >> n >> p;
for (int i = 1;i <= n;i++)
cin >> arr[i];
for (int i = 1;i <= n;i++)
{
int x;
cin >> x;
mp[x] += arr[i];
}
ll ans = 0;
ll sum = 0;
ll la = 0;
for(auto it : mp)
{
if(it.fi > p)
break;
ll tmp = min(n - sum,it.se);
sum += tmp;
ans += it.fi * tmp;
la = it.fi;
if(sum >= n)
break;
}
ll tmp = n - sum;
ans += tmp * p;
if(sum == n)
ans = ans - la + p;
cout << ans << '\n';
}
C
假设在
n
+
1
n + 1
n+1 的位置填的数为
x
x
x ,$x $ %
n
n
n
=
=
=
a
a
a ,
a
a
a一定小于
n
n
n,
a
a
a 模上一个比
a
a
a 大的数结果还是
a
a
a ,直到
a
a
a 模上
a
a
a 变成0,之后结果一直是0,所以只有当
1
≤
k
≤
3
1 \le k \le 3
1≤k≤3 的时候才有答案
k
=
1
k = 1
k=1时 只有一种情况,
a
n
+
1
=
0
a_{n+1} = 0
an+1=0;
k
=
2
k = 2
k=2时 保证
a
n
+
1
a_{n+1}
an+1 的位置是
n
n
n的倍数,或者
1
≤
a
n
+
1
<
n
1 \le a_{n+1} < n
1≤an+1<n
k
=
3
k = 3
k=3时 用k - 前两种情况即可
void solve()
{
ll n,m,k;
cin >> n >> m >> k;
if(k == 1)
cout << 1 << '\n';
else if(k == 2)
{
ll ans = 0;
ans += m / n;
ans = ans + min(n,m);
if(m / n >=1)
ans--;
cout << ans << "\n";
}
else if(k == 3)
{
ll ans = 0;
ans += m / n;
ans = ans + min(n,m);
if(m / n >=1)
ans--;
ans = m - ans;
cout << ans << "\n";
}
else
cout << 0 << "\n";
}
D
先预处理一遍,令 每一个
a
i
a_i
ai 等于
a
i
a_i
ai和他所有倍数的最大值,再对 a 排序,计算
∑
i
=
1
n
a
i
∗
2
i
−
1
\sum_{i = 1}^{n} a_i * 2^{i-1}
∑i=1nai∗2i−1
ll ksm(ll a,ll b)
{
a %= mod;
ll ans=1;
while(b)
{
if(b & 1)
ans=ans*a%mod;
a=a*a%mod;
b = b >> 1;
}
return ans;
}
ll arr[MAXN];
void solve()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> arr[i];
for (ll i = n/2;i >= 1;i--)
{
for (ll j = 2;j <= 100000;j++)
{
ll x = i * j;
if(x > n)
break;
arr[i] = max(arr[i],arr[x]);
}
}
sort(arr+1,arr+1+n);
ll ans = 0;
for (int i = n;i >= 1;i--)
ans = (ans + (arr[i] * ksm(2,i-1) % mod)) % mod;
cout << ans << "\n";
}