首页 > 代码库 > usaco-2.1-sort3-pass

usaco-2.1-sort3-pass

这个题是水题?呵呵,不一定呵。

/*ID: qq104801LANG: C++TASK: sort3*/#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <vector>#include <map>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>using namespace std;int n;void test(){        freopen("sort3.in","r",stdin);    freopen("sort3.out","w",stdout);    cin>>n;    //cout<<n<<endl;    int i,x;    vector<int> v;    vector<int>::iterator it1;    multiset<int> s;    multiset<int>::iterator it2;    for(i=0;i<n;i++)    {        cin>>x;        v.push_back(x);        s.insert(x);    }    int c12=0,c13=0,c21=0,c23=0,c31=0,c32=0;    for(it1=v.begin(),it2=s.begin();it1!=v.end(),it2!=s.end();++it1,++it2)    {        if(*it1!=*it2)        {            if(*it2==1)            {                if(*it1==2)c12++;                if(*it1==3)c13++;            }            if(*it2==2)            {                if(*it1==1)c21++;                if(*it1==3)c23++;            }            if(*it2==3)            {                if(*it1==1)c31++;                if(*it1==2)c32++;            }        }    }    int ans=c21+c31+(c21>c12?c23+c21-c12:c32+c12-c21);    cout<<ans<<endl;}int main () {            test();            return 0;}

test data:

USER: cn tom [qq104801]TASK: sort3LANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.008 secs, 3508 KB]   Test 2: TEST OK [0.008 secs, 3508 KB]   Test 3: TEST OK [0.003 secs, 3508 KB]   Test 4: TEST OK [0.005 secs, 3508 KB]   Test 5: TEST OK [0.005 secs, 3508 KB]   Test 6: TEST OK [0.005 secs, 3508 KB]   Test 7: TEST OK [0.008 secs, 3508 KB]   Test 8: TEST OK [0.008 secs, 3508 KB]All tests OK.YOUR PROGRAM (sort3) WORKED FIRST TIME! Thats fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----3213------- test 2 ----211------- test 3 ----6123231------- test 4 ----9221333231------- test 5 ----2011321113213321311231------- test 6 ----5011131321233132112322332322311111113112231133211132------- test 7 ----10032231.........

 

usaco-2.1-sort3-pass