Nyoj 364 田忌赛马
2014-04-21 20:25
274 查看
题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=364
分下面三种情况:
(1)如果田忌最快的马比齐王最快的马快,那么让田忌最快的马与之比试
(2)如果田忌最慢的马比齐王最慢的马快,那么让田忌最慢的与之比试
(3)田忌最慢的马与齐王最快的马比试,如果田忌最慢的马比齐王最快的马慢,kcount--;
分下面三种情况:
(1)如果田忌最快的马比齐王最快的马快,那么让田忌最快的马与之比试
(2)如果田忌最慢的马比齐王最慢的马快,那么让田忌最慢的与之比试
(3)田忌最慢的马与齐王最快的马比试,如果田忌最慢的马比齐王最快的马慢,kcount--;
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; const int MAXN = 1010; int main() { int iTian[MAXN], iKing[MAXN];//分别储存田忌和齐王的马 int n, kcount, i; while(~scanf("%d", &n)) { memset(iTian, 0, sizeof(iTian)); memset(iKing, 0, sizeof(iKing)); for(i = 0; i < n; ++i) scanf("%d", &iTian[i]); for(i = 0; i < n; ++i) scanf("%d", &iKing[i]); sort(iTian, iTian+n); sort(iKing, iKing+n); int iLowTian = 0, iFastTian = n-1, iLowKing = 0, iFastKing = n-1; kcount = 0; while(1) { if(iLowTian > iFastTian) break; if(iTian[iFastTian] > iKing[iFastKing])//如果田忌的快马比齐王的快马快,那么让田忌的快马与齐王的快马比 { iFastTian--; iFastKing--; kcount++; } else if(iTian[iLowTian] > iKing[iLowKing])//如果田忌的慢马比齐王的慢马快,那么让田忌的慢马与齐王的慢马比 { iLowKing++; iLowTian++; kcount++; } else { if(iTian[iLowTian] < iKing[iFastKing])//再否则让田忌的慢马与齐王的快马比 kcount--; iLowTian++; iFastKing--; } } printf("%d\n", kcount*200); } return 0; }
相关文章推荐
- NYOJ 364 HDU 1052 田忌赛马
- NYOJ 364 田忌赛马(贪心)
- NYOJ 364 田忌赛马 (贪心)
- NYOJ 364 田忌赛马
- NYOJ 364 田忌赛马
- NYOJ 364 田忌赛马
- NYOJ364 田忌赛马
- NYOJ 364 田忌赛马
- NYOJ--364--田忌赛马
- NYOJ 364 田忌赛马
- NYOJ 364 & HDU 1052 田忌赛马(贪心)
- nyoj 364 田忌赛马(贪心)
- NYOJ 364 田忌赛马
- 田忌赛马 364nyoj
- nyoj--364--田忌赛马(贪心)
- nyoj--364--田忌赛马(贪心)
- nyoj 364 田忌赛马
- nyoj364(田忌赛马)
- NYOJ 364 田忌赛马
- NYOJ 364 田忌赛马