A.
找到规律发现,只转移到2次幂上
// Problem: A. Shuffle Party
// Contest: Codeforces - Codeforces Round 930 (Div. 2)
// URL: https://codeforces.com/contest/1937/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// /l、
// (゚、 。 7
// l、 ~ヽ
// じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
ll lowbit(ll x){
return x&(-x);
}
// 1->2->4->8->16->32
void Lan(){
ll n;
cin>>n;
if(n==lowbit(n)){
cout<<n<<'\n';
}else{
ll res=1;
while(res<n){
res<<=1;
}
res>>=1;
cout<<res<<'\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
B.
找到最小向下操作以及最大向下操作的位置
这个过程中都可以向下操作
// Problem: B. Binary Path
// Contest: Codeforces - Codeforces Round 930 (Div. 2)
// URL: https://codeforces.com/contest/1937/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// /l、
// (゚、 。 7
// l、 ~ヽ
// じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e5 + 9;
char a[3][N];
void Lan(){
int n;
cin>>n;
for(int i=1;i<=2;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
//初始化,向下操作的位置,最大最小
int mx=n;//到最大位置必须向下
int mn=1;//到最小位置必须向右,(之前不能向下)
for(int i=n;i>=2;i--){
if(a[1][i]=='1' && a[2][i-1]=='0'){//i-1的位置就向下操作
mx=i-1;
}
}
for(int i=1;i<mx;i++){
if(a[2][i]=='1' && a[1][i+1]=='0'){//向右操作
mn=i+1;
}
}
//先一直向右边操作
for(int i=1;i<=mx;i++){
cout<<a[1][i];
}
//向下操作再一直向右边
for(int i=mx;i<=n;i++){
cout<<a[2][i];
}
cout<<'\n';
cout<<mx-mn+1<<'\n';//在这区间内都可以操作向下
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
C.
利用a[i]|a[i]==a[i],n-1次循环找到n-1;
因为是排列所以存在最优的那个
找到最小且和n-1|best越大越好
1xxxxx
0????? x~=?
// Problem: C. Bitwise Operation Wizard
// Contest: Codeforces - Codeforces Round 930 (Div. 2)
// URL: https://codeforces.com/contest/1937/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// /l、
// (゚、 。 7
// l、 ~ヽ
// じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
// 大xor大
// a[i]|a[i]==a[i] 利用这个找到最大值 3
// 0 3 1 2
// 3,0
//找到最大的,再找到|运算得到最大的数,中最小的数
//输出即可
int a,b,c,d;
int mx,mn;//pos
char ask(int a,int b,int c,int d){
cout<<"?"<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
char res;
cin>>res;
return res;
}
void Lan(){
int n;
cin>>n;
mx=0;
for(int i=1;i<n;i++){
if(ask(i,i,mx,mx)=='>'){//找到最大
mx=i;
}
}
mn=0;
for(int i=1;i<n;i++){
char t=ask(i,mx,mn,mx);//找到最合适的
if(t=='>'){
mn=i;
}else if(t=='=' && ask(i,i,mn,mn)=='<'){
mn=i;
}
}
cout<<"!"<<" "<<mx<<" "<<mn<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q=1;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
文章介绍了三道Codeforces竞赛题目,涉及数组操作(如将数字移到2的幂位置)、寻找最小和最大向下操作路径、以及利用bitwise操作找到最优解。
1725

被折叠的 条评论
为什么被折叠?



