| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这编译器......为什么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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator