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]
相关文章推荐
- USACO-Section2.1 Sorting a Three-Valued Sequence【数学公式】
- USACO 2.1 Sorting a Three-Valued Sequence (贪心)
- USACO - Chapter2 Section 2.1 - Sorting a Three-Valued Sequence
- USACO Section2.1 Sorting a Three-Valued Sequence 解题报告
- USACO 2.1 Sorting a Three-Valued Sequence
- USACO-Section2.1 Sorting a Three-Valued Sequence[排序]
- USACO [2.1] Sorting a Three-Valued Sequence
- [USACO2.1]三值的排序 Sorting a Three-Valued Sequence
- USACO-Section2.1 Sorting a Three-Valued Sequence [其他][排序][交换]
- USACO 2.1 Sorting A Three-Valued Sequence
- USACO 2.1 Sorting a Three-Valued Sequence
- USACO Section 2.1: Prob Sorting A Three-Valued Sequence
- USACO-Section2.1 Sorting a Three-Valued Sequence(排序)
- USACO 2.1 Sorting A Three-Valued Sequence
- USACO-Section 2.1 Sorting a Three-Valued Sequence (贪心)
- USACO 2.1-Sorting a Three-Valued Sequence
- USACO 2.1 Sorting A Three-Valued Sequence (sort3)
- USACO 2.1 Sorting a Three-Valued Sequence (乱搞)
- 【USACO 2.1】Sorting A Three-Valued Sequence
- USACO2.1 三值的排序 Sorting a Three-Valued Sequence