80pts,TLE on #4,使用vector+pair
查看原帖
80pts,TLE on #4,使用vector+pair
443675
紊莫turtle楼主2022/6/9 10:45

RT,应该和效率无关,因为n=7的点过了。
源码如下:

#include <bits/stdc++.h>
using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(int x){write(x);putchar('\n');}
inline void writesp(int x){write(x);putchar(' ');}
inline string sread(){string str="";char ch=getchar();while(ch==' ' || ch=='\n' || ch=='\r')ch=getchar(); while(ch!=' ' && ch!='\n' && ch!='\r'){str+=ch;ch=getchar();} return str;}
typedef pair<int,int> Pair;
int main()
{
	int n=pow(2,read());
	vector<Pair> v;
	for(int i=1;i<=n;i++)
	{
		int x=read();
		v.push_back(make_pair(x,i));
	}
	while(v.size()!=2)
	{
		int l=v.size();
		for(int i=0;i<l;i+=2)
			if(v[i].first>v[i+1].first) v[i+1].second=-1;
			else v[i].second=-1;
		for(int i=0;i<v.size();i++)
			if(v[i].second==-1) v.erase(v.begin()+i);
	}
	if(v[0].first>v[1].first) write(v[1].second);
	else write(v[0].second);
	return 0;
}


2022/6/9 10:45
加载中...