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

这叫用ansistring超时的pascal党情何以堪啊……

Posted by xuhaoran510 at 2010-11-28 11:30:32 on Problem 1635
In Reply To:大家速度来围观,cin+stl string=960MS。。。。。贴代码,这个效率我不说了 Posted by:yzhw at 2010-08-22 14:00:32
> Source Code
> 
> Problem: 1635  User: yzhw 
> Memory: 824K  Time: 969MS 
> Language: G++  Result: Accepted 
> 
> Source Code 
> # include <iostream>
> using namespace std;
> # include <string>
> # include <vector>
> # include <algorithm>
> void deal(string &pos,int s,int e)
> {
>    if(s>e) return;
>    else
>    {
> 	   int c1=0,ts=s;
> 	   vector<string> tmp;
>        for(int i=s;i<=e;i++)
>        {
>           if(pos[i]=='1')
>              c1--;
>           else
>              c1++;
>           if(!c1)
>           {
>              deal(pos,ts+1,i-1);
> 			 tmp.push_back(pos.substr(ts,i-ts+1));
> 			 ts=i+1;
>           }
>        }
> 	   sort(tmp.begin(),tmp.end());
> 	   string ans=pos.substr(0,s);
> 	   for(int i=0;i<tmp.size();i++)
> 		   ans+=tmp[i];
> 	   ans+=pos.substr(e+1,pos.length()-e-1);
> 	   pos=ans;
>    }
> }
> int main()
> {
> //	freopen("e.in","r",stdin);
> //	freopen("ans.txt","w",stdout);
>     int testcase;
>     cin>>testcase;
>     while(testcase--)
>     {
>        string a,b;
>        cin>>a>>b;
>        if(a.length()!=b.length())
>        {
>             cout<<"different"<<endl;
>             continue;
>        }
>        deal(a,0,a.length()-1);
>        deal(b,0,b.length()-1);
>        if(a==b)
>           cout<<"same"<<endl;
>        else
>           cout<<"different"<<endl;
>     }
> 	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