当前位置: 首页 > 工具软件 > 天梯 > 使用案例 >

天梯赛------

戴高远
2023-12-01
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
const int N=1e6+10;
string s[N];
map<pii,int>m;
int a[N];
void dfs(int l,int r,int win){
	cout<<l<<' '<<r<<' '<<win<<endl;
    if(l+1==r){a[l]=m[{l,r}],a[r]=win;return;}
    int mid=(l+r)/2;
    cout<<"mid="<<mid<<endl;
    if(m[{l,r}]>=m[{l,mid}]&&m[{l,r}]>m[{mid+1,r}]){
        dfs(l,mid,win);
        dfs(mid+1,r,m[{l,r}]);
        return;
    }
    if(m[{l,r}]<m[{l,mid}]){
        dfs(l,mid,win);
        dfs(mid+1,r,m[{l,r}]);
    }else{
        dfs(l,mid,m[{l,r}]);
        dfs(mid+1,r,win);
    }
}
signed main(){
    int k;scanf("%d",&k);
     int x;
    for(int i=1;i<=k;++i){
        for(int j=1;j<=pow(2,k);j+=pow(2,k-1)){
        	//cout<<"f"<<j<<endl;
            scanf("%d",&x);
        m[mp(j,j+i)]=x;
        }
        
    }
   scanf("%d",&x);
   exit(0);
    dfs(1,k,x);
    for(int i=1;i<=k;++i)cout<<a[i]<<" \n"[i==k];
	return 0;
}
 
 /*
 l1-8
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int N=1e5+10;
string s,x,y;
signed main(){
    ll t;cin>>t;
    while(t--){
        ll a,b;cin>>a>>b;
        ll suma=0,sumb=0;
        ll aa=a,bb=b;
        while(aa>0){
		suma+=aa%10;aa/=10;
        }
		while(bb>0){
		sumb+=bb%10;bb/=10;
        }//if(sum==0){puts(a>b?"A":"B");break;}
        //cout<<suma<<' '<<sumb<<endl;
       
        if(a%sumb==0&&b%suma==0){puts(a>b?"A":"B");continue;}
        if(a%sumb==0)puts("A");
        else if(b%suma==0)puts("B");
        else{puts(a>b?"A":"B");
		}
    }
	return 0;
} 
 l2-1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int N=1e5+10;
deque<int>a,b;
signed main(){
    ll n,sum=0,maxx=0;scanf("%lld",&n);
    while(n--){
        ll x;scanf("%lld",&x);
       if(a.empty()){a.push_back(x);continue;}
         
        if(x<a.back()){a.push_back(x);continue;}
		if(b.empty())b.push_back(x);
        else if(x>b.back())b.push_back(x);
        else{sum+=1;
        	ll cnt=0;
        	
        	while(!a.empty())a.pop_front(),cnt++;
       
			maxx=max(maxx,cnt);
             int kk=1;
			for(auto p=b.begin();p<b.end()-1;++p){
				auto t=p;
				if(*t>x)a.push_back(*t),b.erase(t),--p;
			}
        	if(!b.empty()&&*(b.end()-1)>x)a.push_back(*(b.end()-1)),b.erase(b.end()-1);
			a.push_back(x);
		
	
		}
        
    }
    if(!a.empty()){sum++;	
    ll cnt=0;
        	
        	while(!a.empty())a.pop_front(),cnt++;
       
			maxx=max(maxx,cnt);}
    if(!b.empty()){sum++;
    ll cnt=0;
        	
        	while(!b.empty())b.pop_front(),cnt++;
       
			maxx=max(maxx,cnt);}
    cout<<sum<<' '<<maxx;
	return 0;
} 
*/
/*
l2-2
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int N=1e4+10;
int a[N];char s[30];
signed main(){
    int n,c;scanf("%d%d",&n,&c);
	int sum=0;
    for(int i=1;i<=n;++i){
        
        int x;scanf("%s%d",s,&x);
       a[i]=x%c;
       sum+=x/c;
        printf("%s %d\n",s,(x%c==0?0:1)+x/c);
    }
    int l=1,r=n;
    sort(a+1,a+1+n);
   // for(int i=1;i<=n;++i)cout<<a[i]<<' ';cout<<endl;
    while(l<=n&&a[l]==0)l++;
    while(l<r){//cout<<l<<"   "<<r<<" "<<sum<<endl;
    int k=a[l];
        while(l<r&&k+a[r]<=c)l++,k+=a[l];
        if(a[l]!=k){sum+=1,r--;continue;}
        if(a[r]+a[l]>c){
            sum+=1,r--;
          
        }
    }
    if(l==r)sum+=1;
    printf("%d",sum);
	return 0;
} 
*/
/*l2-4
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int N=1e5+10;
string s[N];
int n,m;
int b[5][4]={{0,1},{0,-1},{-1,0},{1,0}};
bool check(int x,int y){
    if(x<1||x>n||y<1||y>m)return false;
    if(s[x][y]=='0')return false;
    return true;
}
void dfs(int x,int y,int& f){
    if(s[x][y]=='0')return ;
    if(s[x][y]>='2'&&s[x][y]<='9')f=1;
    s[x][y]='0';
    for(int i=0;i<4;++i){
        int xx=x+b[i][0],yy=y+b[i][1];
        if(check(xx,yy))dfs(xx,yy,f);
    }
}
signed main(){
    cin>>n>>m;
    int sum=0,cnt=0;
    for(int i=1;i<=n;++i){
        cin>>s[i];
        s[i]= " "+s[i];
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(s[i][j]!='0'){
                int f=0;cnt++;
                dfs(i,j,f);sum+=f;
            }
        }
    }
    cout<<cnt<<' '<<sum<<endl;
	return 0;
} 

*/

 类似资料: