亂搞題





 stl亂搞n(logn)^3,莫名其妙的過了

#include <cstdio>  
#include <cmath>  
#include <ctime>  
#include <string>  
#include <cstring>  
#include <cstdlib>  
#include <iostream>  
#include <algorithm>  
  #include<set> 
#include <vector>  
#include<queue>
#include<map>
#define pb push_back 

#define forup(i,a,b) for(int i=(a);i<=(b);i++)  
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)  
  
#define maxn 100005 
#define maxm 100005 
#define INF 1070000000  
#pragma GCC optimize(2) 
using namespace std;  
typedef long long ll;  
typedef unsigned long long ull;  
  map<int,int>  p[maxn];
template<class T> inline  
void read(T& num){   num = 0; bool f = true;char ch = getchar();   while(ch < '0' || ch > '9') { if(ch == '-') f = false;ch = getchar();}  while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}   num = f ? num: -num; } 
int out[100]; 
template<class T> inline 
void write(T x,char ch){  if (x==0) {putchar('0'); putchar(ch); return;} if (x<0) {putchar('-'); x=-x;}int num=0; while (x){ out[num++]=(x%10); x=x/10;} fordown(i,num-1,0) putchar(out[i]+'0'); putchar(ch); } 
/*==================split line==================*/
int n;
int a[maxn];
vector<int> g[maxn];
set<int> s;
bool cmp(int x,int y)  {return x>y;}
void fen(int x)
{     while(a[x]>0)
    { g[x].pb(a[x]); a[x]=a[x]>>1;}
}

bool  pd(int mid)
{  s.clear();
forup(i,1,n)
   {  bool flag=0;
       for(int j=0;j<g[i].size();j++)
       {  if(g[i][j]<=mid&&(s.find(g[i][j])==s.end()))
          {s.insert(g[i][j]);flag=1;break;}
	   }
	    if(!flag) return false;
   }
   return true;
}

int main()
{  cin>>n;
int cmax=0;
  forup(i,1,n){read(a[i]);cmax=max(cmax,a[i]);}  sort(a+1,a+1+n,cmp); 
	forup(i,1,n)
	{   fen(i);}
	  int l=1,r=cmax;
	  while(r-1>l)
	  {  int mid=(l+r)>>1;
	     if(pd(mid))   r=mid;
	      else l=mid;
	  }
	  if(pd(l)){for(set<int>::iterator i=s.begin();i!=s.end();i++){write(*i,' ');}}
	 else{pd(r);for(set<int>::iterator i=s.begin();i!=s.end();i++){write(*i,' ');}}	
	return 0;
 } 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章