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 |
Re:帮忙看看,C++ AC g++WA 用的STL priorityqueueIn Reply To:Re:帮忙看看,C++ AC g++WA 用的STL priorityqueue Posted by:weakY at 2009-08-23 10:15:23 囧,贴成以前的代码了 现在知道了,g++ 输出double一定要用printf("%f")下面这个应该g++c++都能AC了 #include<stdio.h> #include<string.h> #include<queue> using namespace std; char s[1000]; int a[300]; struct node { int v,w; } b[10000]; struct poi { int p; }; bool operator<(const poi &A,const poi&B) { return b[A.p].v>b[B.p].v; } int main() { while (scanf("%s",s)==1&&strcmp(s,"END")!=0) { int l,i,j; l=strlen(s); memset(a,0,sizeof a); for (i=0;i<l;i++) a[s[i]]++; priority_queue<poi> Q; for (j=i=0;i<300;i++) { if (a[i]>0) { b[j].v=a[i]; b[j].w=0; poi t; t.p=j++; Q.push(t); } } if (j==1) { printf("%d %d 8.0\n",b[0].v*8,b[0].v); continue; } while (1) { poi t1=Q.top(); Q.pop(); if (Q.empty()) break; poi t2=Q.top(); Q.pop(); b[j].v=b[t1.p].v+b[t2.p].v; b[j].w=b[t1.p].w+b[t2.p].w+b[j].v; poi t; t.p=j++; Q.push(t); } printf("%d %d %.1f\n",l*8,b[j-1].w,double(l*8/b[j-1].w)); } } > printf("%d %d %.1lf\n",l*8,b[j-1].w,(double)(l*8/b[j-1].w)); > > 你C++能AC?(double)(l*8/b[j-1].w)应该是(double)l*8/b[j-1].w,你的double强制类型转换没有将它们转换成double的除法 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator