Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

WA了N次,跪求大牛指点迷津

Posted by stupidjohn at 2011-05-18 22:15:02 on Problem 2828
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxN 263000
int st[maxN * 2];
int ans[maxN];
int n, M;
int find(int i, int l, int r, int id){
	int child, blank, mid;
	for(; id<M; id=child){
		st[id]++;
		mid=(l+r)>>1;
		child=id<<1;
		blank=mid-l+1-st[id<<1];
		if(i<blank) r=mid;
		else{
			i-=blank; child++; l=mid+1;
		}
	}
	st[id]++;
	return id-M;
}
void getm(){
	for(int i=1; i<0xfffffff; i++)
	if(i>n) {M=i; break;}
}
struct node{
	int p, v;
}line[maxN];
int main(){
	int pos;
	while(scanf("%d", &n)==1){
		getm();	
		for(int i=n-1; i>=0; i--){
			scanf("%d %d", &line[i].p, &line[i].v);
		}
		memset(st, 0, sizeof(st));
		for(int i=0; i<n; i++){
			pos=find(line[i].p, 0, M-1, 1);
			ans[pos]=line[i].v;
		}
		for(int i=0; i<n-1; i++)
			printf("%d ", ans[i]);
		printf("%d\n", ans[n-1]);
	}
	return 0;
}




Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator