码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-2.1-sort3-pass

时间:2014-09-02 22:52:15      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

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

/*
ID: qq104801
LANG: 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: sort3
LANG: C++

Compiling...
Compile: OK

Executing...
   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 ----
3
2
1
3
------- test 2 ----
2
1
1
------- test 3 ----
6
1
2
3
2
3
1
------- test 4 ----
9
2
2
1
3
3
3
2
3
1
------- test 5 ----
20
1
1
3
2
1
1
1
3
2
1
3
3
2
1
3
1
1
2
3
1
------- test 6 ----
50
1
1
1
3
1
3
2
1
2
3
3
1
3
2
1
1
2
3
2
2
3
3
2
3
2
2
3
1
1
1
1
1
1
1
3
1
1
2
2
3
1
1
3
3
2
1
1
1
3
2
------- test 7 ----
100
3
2
2
3
1
.........

 

usaco-2.1-sort3-pass

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/dpblue/p/3952410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!