牛客小白月赛63 ABCD
https://ac.nowcoder.com/acm/contest/49030
这套题目质量挺好的,E过了200+,状态不佳,改天补补
A-子序列的权值最小值
输入
6
1 1 4 5 1 4
输出
0
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=1e9+7;
const double PI=3.1415926535;
#define endl '\n'
LL a[N],b[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
LL sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i==1) sum=a[i];
else sum&=a[i];
}
cout<<sum<<endl;
}
return 0;
}
B-魔导师晨拥
输入
5 6
1 2 3 4 5
输出
36
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=1e9+7;
const double PI=3.1415926535;
#define endl '\n'
LL a[N],b[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
LL beg=2;
LL ans=0;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
a[j]-=beg;
if(a[j]==0) beg++;
}
ans+=beg;
}
cout<<ans<<endl;
}
return 0;
}
C-GCPC总决赛
输入
2
0 2
1 3
输出
0 1 1
数据范围小,直接暴力即可
方法一
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=5005;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[N],b[N];
LL num[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
num[i]=i;
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
LL sum1=0,sum2=0,sum3=0;
do
{
LL x=0,y=0,z=0;
for(int i=1;i<=n;i++)
{
int aa=a[num[i]],bb=b[i];
if(aa>bb) x++;
else if(aa<bb) y++;
else z++;
}
if(x>y) sum1++;
else if(x<y) sum2++;
else sum3++;
}
while(next_permutation(num+1,num+1+n));
cout<<sum1<<" "<<sum2<<" "<<sum3<<endl;
}
return 0;
}
方法二
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=5005;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n,sum1=0,sum2=0,sum3=0;
LL a[N],b[N];
bool st[N];
vector<LL> v;
void dfs(int idx)
{
if(idx>n)
{
LL x=0,y=0,z=0;
for(int i=0;i<v.size();i++)
{
if(v[i]>b[i+1]) x++;
else if(v[i]<b[i+1]) y++;
else z++;
}
if(x>y) sum1++;
else if(x<y) sum2++;
else sum3++;
return ;
}
for(int i=1;i<=n;i++)
{
if(st[i]==0)
{
st[i]=1;
v.push_back(a[i]);
dfs(idx+1);
v.pop_back();
st[i]=0;
}
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
dfs(1);
cout<<sum1<<" "<<sum2<<" "<<sum3<<endl;
}
return 0;
}
D-Ginger的大花环
输入
5 4
1 2 3 4
输出
7
输入
3 1
1
输出
Ginger666
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=5005;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n,k;
cin>>n>>k;
for(int i=1;i<=k;i++)
{
cin>>a[i];
}
if(k<=1) cout<<"Ginger666"<<endl;
else
{
sort(a+1,a+1+k);
if(n%3==0) cout<<(n/3)*(2*a[1]+a[2]);
else if(n%3==1) cout<<(n/3)*(2*a[1]+a[2])+a[2];
else if(n%3==2) cout<<(n/3)*(2*a[1]+a[2])+a[1]+a[2];
}
}
return 0;
}