zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 188 C

    • 题意:有(2^n)个人站成一排比赛,刚开始每个人都和自己右边的人进行比赛,赢得人晋级下一轮(下标的小的在前面),不断重复这个过程,问最后拿到第二名的人的编号.
    • 题解:根据题意,可以用vector直接模拟这个过程.
    • 代码:
    #include <bits/stdc++.h>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    #define rep(a,b,c) for(int a=b;a<=c;++a)
    #define per(a,b,c) for(int a=b;a>=c;--a)
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL;
    ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
    
    
    int main() {
        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    	
    	int n;
    	cin>>n;
    	n=pow(2,n);
    	vector<int> a(n);
    	vector<int> v;
    
    	for(auto &w:a) cin>>w;
    
    	if(n==2){
    		if(a[0]>a[1]) cout<<2<<'
    ';
    		else cout<<1<<'
    ';
    		return 0;
    	}
    
    	rep(i,0,n-1){
    		if(i&1){
    			if(a[i]>=a[i-1]) v.pb(i);
    			else v.pb(i-1);
    		}
    	}
    
    	while(v.size()>2){
    		vector<int> tmp=v;
    		v.clear();
    		for(int i=0;i<(int)tmp.size();++i){
    			if(i&1){
    			if(a[tmp[i]]>a[tmp[i-1]]) v.pb(tmp[i]);
    			else v.pb(tmp[i-1]);
    		}
    
    		}
    	}
    
    	if(a[v[0]]>a[v[1]]) cout<<v[1]+1<<'
    ';
    	else cout<<v[0]+1<<'
    ';
    
        return 0;
    }
    
    
  • 相关阅读:
    golang 中 sync包的 WaitGroup
    Go_20: Golang 中 time 包的使用
    mysql 同步数据到 ElasticSearch 的方案
    mysql 对应 binlog 查看
    python3.6爬虫总结-01
    Golang 之协程详解
    golang私服搭建
    Ubuntu vim设置
    密码校验规则
    golang密码校验
  • 原文地址:https://www.cnblogs.com/lr599909928/p/14285801.html
Copyright © 2011-2022 走看看