您的位置:首页 > 产品设计 > UI/UE

USACO 2.1 Sorting A Three-Valued Sequence

2011-05-03 13:12 323 查看
TASK: sort3
LANG: C++

Compiling...
Compile: OK

Executing...
Test 1: TEST OK [0.000 secs, 3028 KB]
Test 2: TEST OK [0.000 secs, 3028 KB]
Test 3: TEST OK [0.000 secs, 3028 KB]
Test 4: TEST OK [0.000 secs, 3028 KB]
Test 5: TEST OK [0.000 secs, 3028 KB]
Test 6: TEST OK [0.000 secs, 3028 KB]
Test 7: TEST OK [0.000 secs, 3028 KB]
Test 8: TEST OK [0.000 secs, 3028 KB]

All tests OK.
Your program ('sort3') produced all correct answers!  This is your
submission #3 for this problem.  Congratulations!

[code] /*
ID: jiafeim1
PROG: sort3
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define maxN(x,y) ((x)>(y)?(x):(y))

int num[1003];
int sorted[1003];
int countX[4][4]={0};
int main()
{
ofstream fout ("sort3.out");
ifstream fin ("sort3.in");

int n;
fin>>n;

for(int i=0;i!=n;++i)
{
fin>>num[i];
sorted[i] = num[i];
}

sort(sorted,sorted+n);

int total = 0;
for(int i = 0;i!=n;++i)
{
if(sorted[i]!=num[i])
++countX[sorted[i]][num[i]];
}
total =countX[2][1]+countX[3][1]+countX[2][3]+max(0,countX[1][3]-countX[3][1]);

fout<<total<<endl;
fin.close();
fout.close();
return 0;
}




[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: