POJ 2287 - Tian Ji -- The Horse Racing(贪心)

题意:田忌和齐王都有 n(n <= 1000)匹马,二者进行 n 轮赛马,赢一局+200,平一局得 0,输一局 -200,求田忌最多能赢多少钱。

贪心,先将田忌和齐王的马分别排序,然后最上等与最上等比,最下等与最下等比,如果有能赢的则+200,如果无法满足条件,则用田忌的最下等与齐王的最上等比(故意输或者平局)。

代码如下:

 1 #pragma comment(linker, "/STACK:102400000, 102400000")
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cctype>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<iostream>
 8 #include<sstream>
 9 #include<iterator>
10 #include<algorithm>
11 #include<string>
12 #include<vector>
13 #include<set>
14 #include<map>
15 #include<deque>
16 #include<queue>
17 #include<stack>
18 #include<list>
19 #define fin freopen("in.txt", "r", stdin)
20 #define fout freopen("out.txt", "w", stdout)
21 #define pr(x) cout << #x << " : " << x << "   "
22 #define prln(x) cout << #x << " : " << x << endl
23 #define Min(a, b) a < b ? a : b
24 #define Max(a, b) a < b ? b : a
25 typedef long long ll;
26 typedef unsigned long long llu;
27 const int INT_INF = 0x3f3f3f3f;
28 const int INT_M_INF = 0x7f7f7f7f;
29 const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
30 const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
31 const double pi = acos(-1.0);
32 const double EPS = 1e-8;
33 const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
34 const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
35 const ll MOD = 1e9 + 7;
36 using namespace std;
37 
38 #define NDEBUG
39 #include<cassert>
40 const int MAXN = 1000 + 10;
41 const int MAXT = 10000 + 10;
42 
43 int n;
44 deque<int> t, k;
45 
46 int main(){
47     while(scanf("%d", &n) == 1 && n){
48         int tmp;
49         t.clear();
50         k.clear();
51         for(int i = 0; i < n; ++i)  {scanf("%d", &tmp);  t.push_back(tmp);}
52         for(int i = 0; i < n; ++i)  {scanf("%d", &tmp);  k.push_back(tmp);}
53         sort(t.begin(), t.end());
54         sort(k.begin(), k.end());
55         int ans = 0;
56         while(n--){
57             if(t.front() > k.front()){
58                 t.pop_front();
59                 k.pop_front();
60                 ans += 200;
61             }
62             else if(t.back() > k.back()){
63                 t.pop_back();
64                 k.pop_back();
65                 ans += 200;
66             }
67             else{
68                 if(t.front() != k.back())  ans -= 200;
69                 t.pop_front();
70                 k.pop_back();
71             }
72         }
73         printf("%d\n", ans);
74     }
75     return 0;
76 }

 

转载于:https://www.cnblogs.com/tyty-TianTengtt/p/6089550.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值