A 子序列的权值最小值
思路:我们通过&可以知道a1&a2<=min(a1,a2)所以当我们全部&后答案最小
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define int long long
const int N=2e5+7;
int a[N],s[N];
int n,mn;
signed main(){
int n,ans;
cin >>n;
for(int i=1;i<=n;i++){
int x;
cin >>x;
if(i==1) ans=x;
else ans&=x;
}
cout <<ans<<endl;
}
B 魔导师晨拥
思路:跟着题意模拟一遍即可
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define int long long
const int N=2e5+7;
int a[N],s[N];
int n,mn,m;
signed main(){
cin >>n>>m;
int ans = 0;
int atc = 2;
for(int i=1;i<=n;i++){
cin >>a[i];
}
while(m--){
for(int i=1;i<=n;i++){
if(a[i]>0){
a[i]-=atc;
if(a[i]==0) atc++;
}
}
ans+=atc;
}
cout <<ans<<endl;
}
C GCPC总决赛
思路:很容易看出,固定一个数组对于另一个数组进行全排列即可
next_permutation() yyds
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define int long long
const int N=2e5+7;
int a[N],b[N],sa[N],sb[N],p[N];
int n,mn;
signed main(){
cin>>n;
rep(i,1,n){
cin>>a[i];
p[i]=i;
sa[a[i]]++;
}
rep(i,1,n){
cin>>b[i];
sb[b[i]]++;
}
int _1=0,_2=0,_3=0;
do
{
int y=0,x=0;
rep(i,1,n){
//cout<<a[i]<<" "<<b[i]<<endl;
if(a[p[i]]>b[i])x++;
else if(a[p[i]]<b[i])y++;
}
//cout<<endl;
if(x>y)_1++;
if(x==y)_3++;
if(x<y)_2++;
}while(next_permutation(p+1,p+1+n));
cout<<_1<<" "<<_2<<" "<<_3;
}
D Ginger的大花环
思路:贪心+思路
想让答案最小并且满足三个不能同一色,很明显112为最优,但是这里有结束位置特判:
(1)如果n是三的倍数直接计算112即可
(2)如果n取模后为一,按之前应该排1这样形成环后就会出现111这种情况,所以将最后一位加2
(3)如果n取模后为二,按之前应该是12没有影响,特加12即可
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define int long long
const int N=2e5+7;
int a[N],b[N],sa[N],sb[N];
int n,mn,k;
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= k; i++) cin >> a[i];
sort(a + 1, a + 1 + k);
if(k == 1)
{
cout << "Ginger666" << endl;
return 0;
}
int ad[3];
ad[0] = 0;
ad[1] = a[2];
ad[2] = a[2] + a[1];
cout << n / 3 * (a[1] + a[1] + a[2]) + ad[n % 3] << endl;
return 0;
}
E 最值区间计数
思路:
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
const int mod = 998244353;
signed main()
{
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n == 1)
{
puts("1");
return 0;
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
ans = (ans + (n - i) * (i * n + i) - i * (i + 1 + n) * (n - i) / 2) % mod;
}
for (int i = 1; i <= n - 2; i++)
{
ans = ans * i % mod;
}
cout << ans * 2 % mod << endl;
return 0;
}