讨论 / 高精度+快排
zyfworks 2012-06-01 23:14:00
点我顶贴 收藏 删除
C++ STL的string類和sort函數無壓力,一次AC。

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <string>

#include <iostream>

#include <algorithm>

#define Len P[i].len

using namespace std;

const int MAXN=1011;

class hugeint

{

public:

int len,num[MAXN*2];

string pork,name;

}P[MAXN],sum;

string temp;

int N;

inline int max(int a,int b) {return a>b?a:b;}

inline void hugeplus(hugeint &a,hugeint &b)

{

int len=max(a.len,b.len);

for(int i=1;i<=len;i++)

{

if(i==500) break;

a.num[i]+=b.num[i];

if(a.num[i]>9) a.num[i]-=10,a.num[i+1]++;

}

a.num[len+1]==0?a.len=len:a.len=len+1;

if(a.len>500) a.len=500;

}

inline void hugeout(hugeint &a)

{

for(int i=490;i>=1;i--) printf("%d",a.num[i]);

}

bool cmp(const hugeint&a,const hugeint&b)

{

if(a.len!=b.len) return a.len>b.len;

if(a.pork!=b.pork) return a.pork>b.pork;

return a.name<b.name;

}

int main()

{

freopen("in","r",stdin);

// freopen("out","w",stdout);

std::ios::sync_with_stdio(0);

cin>>N;

for(int i=1;i<=N;i++)

{

cin>>P[i].name;

temp.clear();

cin>>temp;

P[i].pork=temp;

Len=temp.length();

for(int j=0;j<Len;j++) P[i].num[Len-j]=temp[j]-'0';

hugeplus(sum,P[i]);

}

sort(P+1,P+N+1,cmp);

for(int i=1;i<=N;i++) printf("%s\n",P[i].name.c_str());

hugeout(sum);

return 0;

}

#1 zyfworks@2012-05-20 08:47:00
回复 删除
靠靠靠,怎麼回事?? 三連了!!! 請求管理員刪貼2個!

靠靠靠,怎麼回事?? 三連了!!! 請求管理員刪貼2個!

#2 995541152@2012-06-01 23:14:00
回复 删除
高鸡度+牛排@##¥¥%……&&**((……%¥##¥##

三连杀了,管理删帖= =

查看更多回复
提交回复