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;
    }
    
    
  • 相关阅读:
    window 7/8/10 安装nginx
    全面了解 Nginx 到底能做什么
    MySQL优化
    office 2013 破解工具 及 软件下载
    centos6+如何对外开放80,3306端口号或者其他端口号
    CentOS 中查看软件的版本号
    CentOS 中安装 mysql 5.7+
    STL入门大全(待编辑)
    Feign
    微信公众号
  • 原文地址:https://www.cnblogs.com/lr599909928/p/14285801.html
Copyright © 2011-2022 走看看