求助POJ1002..(TLE)...

bigfish9 2010-07-31 11:52:25
已经用快排了 还是超了 是不是数据处理上有问题 可是数据处理都是O(n)的级别的吧...实在不明白了 弄了半天....
有没有哪位大大帮我看下程序的 刚接触C++ 虽然以前也写过程序 不过对C++很多用法也不太了解= =
#include <iostream>
#include <string.h>
using namespace std;
int num[100005];
int v[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
char st[20];
void quicksort(int l,int r)
{
int i,j,mid,t;
i=l;j=r;mid=num[(l+r)/2];
while (i<=j)
{
while ((num[i]<mid)&&(i<r)) ++i;
while ((num[j]>mid)&&(j>l)) --j;
if (i<=j)
{
t=num[i];num[i]=num[j];num[j]=t;
++i;
--j;
}
}
if (l<j) quicksort(l,j);
if (r>i) quicksort(i,r);
}
int main()
{
int t,now,nown,tmp,n,len,i,j;
cin>>n;
for (i=1;i<=n;++i)
{
cin>>st;
len=strlen(st);
tmp=0;
for (j=0;j<=len-1;++j)
if (('0'<=st[j])&&(st[j]<='9'))
tmp=tmp*10+int(st[j])-48;
else if (('A'<=st[j])&&(st[j]<='Z'))
tmp=tmp*10+v[int(st[j])-65];
num[i]=tmp;
}
quicksort(1,n);
num[n+1]=-10;
now=0;nown=0;
int anss=0;
for (i=1;i<=n+1;++i)
{
if (num[i]!=now)
{
if (nown>=2)
{
t=now/10000;
if (t>=100)
cout<<t;
else if (t>=10)
cout<<"0"<<t;
else cout<<"00"<<t;
cout<<'-';
t=now%10000;
if (t>=1000)
cout<<t;
else if (t>=100)
cout<<'0'<<t;
else if (t>=10)
cout<<"00"<<t;
else cout<<"000"<<t;
cout<<' '<<nown<<endl;
++anss;
}
now=num[i];
nown=1;
}
else ++nown;
}
if (anss==0)
cout<<"No duplicates.";
}
...全文
92 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
FancyMouse 2010-08-01
  • 打赏
  • 举报
回复
大规模数据别用iostream用stdio
bigfish9 2010-08-01
  • 打赏
  • 举报
回复
第一次发帖 = = 不好意思
bigfish9 2010-08-01
  • 打赏
  • 举报
回复
谢谢 改成stdio确实可以了......
输入输出只有O(N)级别....那用IOSTREAM不就效率比STDIO差了几十倍???
那平时做ACM时这两种方法如何取舍?? 都直接用STDIO么??
genlic 2010-07-31
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20100731/21/24992eea-a643-4b90-800d-d5e778d7bd74.html?46792
看下。。

64,439

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧