(:我一开始以为我要爆0了,跌,磕磕绊绊,还好写出了这两题,后面的太难了题目都没看hh
https://codeforces.com/contest/1763
A. Absolute Maximization
题目大意:
给定一个数组a,我们可以任意移动不同数字上的同位置上的二进制数0或1
问我们数组中最大值-最小值是多少?
inputCopy
4
3
1 0 1
4
5 5 5 5
5
1 2 3 4 5
7
20 85 100 41 76 49 36
outputCopy
1
0
7
125
昨晚赛场上写的hh,纯纯黛比了,脑子忘在学校了
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
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;
string s[n+10];
for(int i=1;i<=n;i++)
{
cin>>a[i];
LL x=a[i];
while(x)
{
s[i]+=to_string(x%2);
x/=2;
}
}
//for(int i=1;i<=n;i++) cout<<s[i]<<" "; cout<<endl;
map<LL,LL> mp;
for(int i=1;i<=n;i++)
{
string flag=s[i];
reverse(flag.begin(),flag.end());
for(int j=0;j<flag.size();j++)
{
if(s[i][j]=='1') mp[j]++;
}
}
string maxn,minn;
for(int i=10;i>=0;i--)
{
if(mp[i]>0)
{
maxn+='1';
if(n==mp[i]) minn+='1';
else minn+='0';
}
else
{
maxn+='0';
minn+='0';
}
}
//cout<<maxn<<" "<<minn<<endl;
LL ans1=0,ans2=0;
reverse(maxn.begin(),maxn.end());
for(int i=0;i<maxn.size();i++)
{
ans1+=(maxn[i]-'0')*pow(2,i);
}
reverse(minn.begin(),minn.end());
for(int i=0;i<minn.size();i++)
{
ans2+=(minn[i]-'0')*pow(2,i);
}
//cout<<ans1<<" "<<ans2<<endl;
cout<<ans1-ans2<<endl;
mp.clear();
}
return 0;
}
正解:
int maxn=a[1],minn=a[1];
for(int i=2;i<=n;i++)
{
maxn|=a[i];
minn&=a[i];
}
B. Incinerate
题目大意:
n个怪兽,给定一个序列h表示初始血量,给定一个序列p表示力量。
我们的初始战斗力为k,每次可以对所有怪兽-k的血量,但是在每次-完之后剩余活着的战斗力最弱的那个怪兽都会反过来攻击我们的战斗力,
问我们能不能在我们的战斗力>=0的时候把所有怪兽消灭掉?
inputCopy
3
6 7
18 5 13 9 10 1
2 7 2 1 2 6
3 4
5 5 5
4 4 4
3 2
2 1 3
1 1 1
outputCopy
YES
NO
YES
理清思路就好了,AB都不难(注意细节问题)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
struct node
{
LL h;
LL p;
LL minn;
}a[N];
bool cmp(node l,node r)
{
if(l.h!=r.h) return l.h<r.h;
else return l.p>r.p;
}
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<=n;i++)
{
cin>>a[i].h;
}
for(int i=1;i<=n;i++)
{
cin>>a[i].p;
}
sort(a+1,a+1+n,cmp);
for(int i=n;i>=1;i--)
{
if(i==n) a[i].minn=a[i].p;
else a[i].minn=min(a[i+1].minn,a[i].p);
//cout<<a[i].minn<<" ";
}
//cout<<endl;
LL last=1;
LL sum=k;
while(k>0)
{
while(a[last].h<=sum)
{
last++;
if(last>n) break;
}
//cout<<last<<endl;
if(last>n) break;
k-=a[last].minn;
sum+=k;
}
if(last>n) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
标签:typedef,AB,cout,minn,840,int,LL,Codeforces,cin
From: https://www.cnblogs.com/Vivian-0918/p/16993667.html