USACO Section 2.1: Prob Sorting A Three-Valued Sequence
2013-07-05 05:18
519 查看
贪心,先是交换俩俩交换后就可以的,接着交换3个轮回的,每个3个轮回的要交换2次
/* ID: yingzho1 LANG: C++ TASK: sort3 */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> using namespace std; ifstream fin("sort3.in"); ofstream fout("sort3.out"); int N; int main() { fin >> N; vector<int> f(N), g(N); for (int i = 0; i < N; i++) fin >> f[i]; g = f; sort(g.begin(), g.end()); int acount = 0; for (int i = 0; i < N-1; i++) { for (int j = i+1; j < N; j++) { if (f[j] != g[j] && f[i] == g[j] && f[j] == g[i]) { swap(f[i], f[j]); acount++; } } } int count2 = 0; for (int i = 0; i < N; i++) { if (f[i] != g[i]) count2++; } fout << acount + count2/3*2 << endl; return 0; }
相关文章推荐
- USACO - Chapter2 Section 2.1 - Sorting a Three-Valued Sequence
- USACO-Section2.1 Sorting a Three-Valued Sequence [其他][排序][交换]
- USACO Section2.1 Sorting a Three-Valued Sequence 解题报告
- USACO-Section2.1 Sorting a Three-Valued Sequence(排序)
- USACO-Section 2.1 Sorting a Three-Valued Sequence (贪心)
- USACO-Section2.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 2.1 Sorting a Three-Valued Sequence (乱搞)
- USACO2.1 三值的排序 Sorting a Three-Valued Sequence
- USACO 2.1 Sorting a Three-Valued Sequence
- USACO [2.1] Sorting a Three-Valued Sequence
- USACO 2.1 Sorting a Three-Valued Sequence
- USACO 2.1 Sorting A Three-Valued Sequence
- 【USACO 2.1】Sorting A Three-Valued Sequence
- USACO 2.1 Sorting a Three-Valued Sequence
- [2016/7/11][usaco 2.1]Sorting a Three-Valued Sequence
- USACO 2.1 Sorting A Three-Valued Sequence
- USACO 2.1 Sorting a Three-Valued Sequence (贪心)