• 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;
    }
    
    
  • 相关阅读:
    [Windows Powershell]-学习笔记(1)
    MyBatis For .NET学习-问题总结
    Zynq学习笔记(1)
    规范的位操作方法
    浮点数转换成字符串函数
    测试卡尔曼滤波器(Kalman Filter)
    关于按键扫描程序的终极讨论
    关于STM8的用户数据空间读写问题
    IPv4分析
    关于STM8空间不足的解决方法
  • 原文地址:https://www.cnblogs.com/lr599909928/p/14285801.html
Copyright © 2020-2023  润新知