zoukankan      html  css  js  c++  java
  • [HDOJ1052]Tian Ji -- The Horse Racing

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052

    贪心,田忌的策略比较复杂,仔细想一下可过。

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 int main()  {
     7     int n;
     8     int th[1000], qh[1000];
     9     int win = 0;
    10     while(scanf("%d", &n), n) {
    11         int tmax, tmin, qmax, qmin;
    12         win = 0;
    13         for(int i = 0; i < n; i++) {
    14             scanf("%d", &th[i]);
    15         }
    16         for(int i = 0; i < n; i++) {
    17             scanf("%d", &qh[i]);
    18         }
    19         sort(th, th+n);
    20         sort(qh, qh+n);
    21         tmax = n - 1;
    22         qmax = n - 1;
    23         tmin = 0;
    24         qmin = 0;
    25         while(tmax >= tmin) {
    26             if(th[tmax] > qh[qmax]) {
    27                 tmax--;
    28                 qmax--;
    29                 win++;
    30             }
    31             else {
    32                 if(th[tmin] > qh[qmin]) {
    33                     tmin++;
    34                     qmin++;
    35                     win++;
    36                 }
    37                 else {
    38                     if(th[tmin] < qh[qmax]) {
    39                         tmin++;
    40                         qmax--;
    41                         win--;
    42                     }
    43                     else {
    44                         tmin++;
    45                         qmax--;
    46                     }
    47                 }
    48             }
    49         }
    50         printf("%d
    ", win*200);
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    手把手教你学Git
    服务器上Mysql的安装与配置
    python 5
    python 4
    python 3
    python 2
    区分命令行模式和Python交互模式
    CUDA编程模型之内存管理
    多目标优化算法-NSGA2
    C# ListView 如何添加列标头
  • 原文地址:https://www.cnblogs.com/kirai/p/4770119.html
Copyright © 2011-2022 走看看