# Codeforces Round #653 (Div. 3)(A 二分 B 水 C 水 D 水 E1 思维 F 模拟 得到有序数组 )

### A. Required Remainder

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=1e2+10;
char s[N];
int len;
int main()
{
{

ll l=0,r=1e9+10,ans=0;
while(l<=r)
{
ll mid=l+r>>1;
if(mid*x+y<=n) l=mid+1,ans=mid*x+y;
else r=mid-1;
}
printf("%lld\n",ans);

}
}


### B. Multiply by 2, divide by 6

2的次幂大于3的次幂 -1

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=1e2+10;
char s[N];
int len;
int main()
{
{
if(n==1){
puts("0");continue;
}
int num2=0,num3=0;
while(n%2==0) num2++,n=n/2;
while(n%3==0) num3++,n=n/3;
if(n!=1||num2>num3){
puts("-1");continue;
}

int ans=num3-num2+num3;
printf("%d\n",ans);

}
}


### C. Move Brackets

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=1e2+10;
char s[N];
int len;
int main()
{
{
scanf("%s",s+1);
stack<char>sta;
int l=0,r=0;
for(int i=1;i<=len;++i){
if(s[i]=='(') sta.push('(');
else{
if(sta.size()) sta.pop();
else r++;
}
}
l=sta.size();
int ans=min(l,r);
printf("%d\n",ans);
}
}


### D. Zero Remainder Array

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=2e5+10;
int n,k;
int a[N];
int main()
{
{
map<int,int>mp;
int mx=0,num=0;
rep(i,1,n) {
int d=k-a[i]%k;
if(d==k) continue;
mp[d]++;
if(mp[d]>num) mx=d,num=mp[d];
else if(mp[d]==num) mx=max(mx,d);
}
if(num==0){
puts("0");continue;
}
//printf("num:%d mx:%d\n",num,mx);
ll ans=(1ll*num-1)*k+mx+1;
printf("%lld\n",ans);
}
}


### E1. Reading Books (easy version)

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=2e5+10;
int vis[N],n,k,l1,l2,l3,val[N];
struct node
{
int v,id;
}a[N],b[N],c[N];
bool cmp(node a,node b)
{
return a.v<b.v;
}
deque<node>ans1,ans2;
int main()
{
rep(i,1,n)
{
if(t1==1&&t2==1) c[++l3]={x,i};
else if(t1==1) a[++l1]={x,i};
else if(t2==1) b[++l2]={x,i};
val[i]=x;
}

if(l1+l3<k||l2+l3<k){puts("-1");return 0;}

sort(a+1,a+1+l1,cmp);
sort(b+1,b+1+l2,cmp);
sort(c+1,c+1+l3,cmp);

//printf("l3:%d\n",l3);

for(int i=1;i<=k&&i<=l1;++i) ans1.push_back(a[i]);
for(int i=1;i<=k&&i<=l2;++i) ans2.push_back(b[i]);

int now=1;
while(now<=l3&&(ans1.size()<k||ans2.size()<k)){

//printf("now:%d\n",now);
if(ans1.size()<k&&ans2.size()<k){
ans1.push_front(c[now]);
ans2.push_front(c[now]);
}
else if(ans1.size()<k){

ans1.push_front(c[now]);
ans2.push_front(c[now]);
ans2.pop_back();
}
else{
ans1.push_front(c[now]);
ans2.push_front(c[now]);
ans1.pop_back();
}
now++;
}

while(now<=l3){
if(c[now].v<=ans1.back().v+ans2.back().v){
ans1.push_front(c[now]);
ans2.push_front(c[now]);
ans1.pop_back();
ans2.pop_back();
}
++now;
}

for(auto it:ans1) vis[it.id]=1;
for(auto it:ans2) vis[it.id]=1;

ll ans=0;
rep(i,1,n) if(vis[i]) ans+=val[i];
printf("%lld\n",ans);

}


### F. Cyclic Shifts Sorting

1 2 4 3 5

1 3 2 4 5

1 2 3 3 5 4 => 1 2 3 4 3 5 => 1 2 3 3 4 5

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
return w==1?x:-x;
}
const int N=5e2+10;

int n;
int a[N],vis[N];
int main()
{
{
int base=1;
vector<int>ans;
for(int k=1;k<n-1;++k){
int mi=INT_MAX,id=0;
for(int i=base;i<=n;++i){
if(a[i]<mi) mi=a[i],id=i;
}
//printf("mi:%d id:%d\n",mi,id);
while(id>=base+2){
ans.push_back(id-2);
int tmp=a[id];
a[id]=a[id-1];
a[id-1]=a[id-2];
a[id-2]=tmp;
id=id-2;
}
if(id==base+1){
ans.push_back(base);
ans.push_back(base);
int tmp=a[id];
a[id]=a[id+1];
a[id+1]=a[base];
a[base]=tmp;
}
base++;
}
//rep(i,1,n) printf("%d ",a[i]);
//puts("");
int flag=1;
for(int i=1;i+1<=n;++i) if(a[i+1]<a[i]) flag=0;

if(flag){
printf("%d\n",ans.size());
for(int v:ans) printf("%d ",v);
puts("");
}
else{
int f=0,mx=0;

rep(i,1,n) mx=max(mx,a[i]);
rep(i,0,mx) vis[i]=0;
rep(i,1,n) vis[a[i]]++;
rep(i,1,n) if(vis[a[i]]>=2) f=1;

if(f){
//puts("***");
int id=n;
while(id-1>=1&&a[id]<a[id-1]){
ans.push_back(id-2);
int tmp=a[id];
a[id]=a[id-1];
a[id-1]=a[id-2];
a[id-2]=tmp;
id--;
}
printf("%d\n",ans.size());
for(int v:ans) printf("%d ",v);
puts("");

}
else puts("-1");

}

}
}
/*
5
8
1 2 3 3 4 5 7 6
*/


06-29 257

06-29 131

06-29 270

06-29 70

06-29 328

07-04 47

06-29 59

06-29 152

06-29 127

#### Codeforces Round #653 (Div. 3) D. Zero Remainder Array(思维)

©️2020 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。