A Jellyfish and Undertale
这个直接顺着选就好了,能过
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=105;
int x[maxn];
int t;
int a,b,n;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
memset(x,0,sizeof(x));
cin>>a>>b>>n;
for(int i=1;i<=n;i++) cin>>x[i];
int tim=b;
for(int i=1;i<=n;i++){
if(1+x[i]<=a) tim+=x[i];
else tim+=(a-1);
}
cout<<tim;
cout.put('\n');
}
return 0;
}
B Jellyfish and Game
U1S1我打的时候是div2B啊,咋变A了,不懂,不管给他当1875B了(1874B题解都看不懂...)
分类讨论一下最大值最小值就可以显然的得出二者的选择策略,然后就应该很好处理了
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n,m;
const int maxn=55;
int a[maxn];
int b[maxn];
int minn=INT_MAX,minna=INT_MAX,minnb=INT_MAX,maxx,maxxa,maxxb;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
int n,m,k;
cin>>n>>m>>k;
minn=INT_MAX,minna=INT_MAX,minnb=INT_MAX,maxx=0,maxxa=0,maxxb=0;
int sum1=0,sum2=0;
int maxid=0,minid=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum1+=a[i];
if(a[i]>maxx){
maxid=1;
maxx=a[i];
}
maxxa=max(a[i],maxxa);
minna=min(a[i],minna);
if(a[i]<minn){
minid=1;
minn=a[i];
}
}
for(int i=1;i<=m;i++){
cin>>b[i];
if(b[i]>maxx){
maxid=2;
maxx=b[i];
}
maxxb=max(b[i],maxxb);
minnb=min(b[i],minnb);
if(b[i]<minn){
minid=2;
minn=b[i];
}
}
if(maxxb<minna){
if(k%2==1) cout<<sum1<<'\n';
else cout<<sum1+minnb-maxxa<<'\n';
}
else if(maxid==1&&minid==1){
if(k%2==1) cout<<maxxb-minn+sum1<<'\n';
else cout<<maxxb-maxx+sum1<<'\n';
}
else if(maxid==1&&minid==2){
if(k%2==1) cout<<sum1+maxxb-minna<<'\n';
else cout<<sum1+maxxb-minna-maxx+minn<<'\n';
}
else if(maxid==2&&minid==1){
if(k%2==1) cout<<sum1+maxx-minn<<'\n';
else cout<<sum1<<'\n';
}
else{
if(k%2==1) cout<<sum1+maxx-minna<<'\n';
else cout<<sum1+minn-minna<<'\n';
}
}
return 0;
}
C Jellyfish and Green Apple
很显然可以想到,每个人分到的苹果要么是整数要么是 \(\frac{x}{1<<y}\) 的模式所以无解应该很好判断,然后我们在考虑如何计算答案,由于已经知道有多少个苹果了所以只要苹果能分的话我们就分给每个人,否则的话我们就给所有苹果切一刀,然后再分,证明一下,这其实就相当于给分数形式分子分母都放大了,如果每个人都收到了等量的 \(\frac{1}{(1<<y)}\) 这样就保证了正确性,最优的话因为每个人都收到一样的份数,所以当你要切时必然不可能只切一部分否则就证明上回切少了对吧
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int>mp;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i=0;i<=30;i++) mp[1<<i]=1;
int t;
cin >>t;
while(t--){
int n,m;
cin>>n>>m;
int nn=n,mm=m;
int now=__gcd(n,m);
if(!mp[m/now]){
cout<<"-1"<<'\n';
continue;
}
int ans=0;
nn%=m;
while(nn){
ans+=nn;
nn*=2;
if(nn>=m) nn%=m;
}
cout<<ans<<'\n';
}
return 0;
}
标签:maxx,int,MAX,CF1875,cin,long,INT
From: https://www.cnblogs.com/jt0007/p/17787964.html