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大学生程序设计竞赛训练》暑期课面向全球招生!

这编译器......

Posted by y20070316 at 2015-05-21 13:43:49 on Problem 1338
为什么G++ Wrong Answer,C++就Accepted了?

附个代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

typedef long long LL;
const int N=1501;

int n; LL p[N];	//Query
LL two[N]; int hw,tw;
LL three[N]; int hth,tth;
LL five[N]; int hf,tf;	//Queue

inline int get(void)
{
	int id=(two[hw]<three[hth]?2:3);
	if (id==2) 
		id=(two[hw]<five[hf]?2:5);
	else id=(three[hth]<five[hf]?3:5);
	return id;
}

void add(void)
{
	int minid=get(); LL data;
	p[++p[0]]=(data=(minid==2?two[hw++]:minid==3?three[hth++]:five[hf++]));
	if (minid<=5) five[++tf]=data*5;
	if (minid<=3) three[++tth]=data*3;
	if (minid<=2) two[++tw]=data*2;
}

int main(void)
{	
	p[0]=p[1]=1;
	two[1]=2,three[1]=3,five[1]=5;
	hw=tw=hth=tth=hf=tf=1;
	for (int i=1;i<N;i++) add();
	
	for (int i;i;)
	{
		scanf("%d",&n);
		if (!n) break;
		printf("%lld\n",p[n]);
	}
	
	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