hdu acm-step 1.3.2 Tian Ji -- The Horse Racing

  本题的题意是:给出n匹马,每匹马都有一个固定的速度,结果有胜平负三种。

  代码如下:

  

#include <cstdio>
#include <algorithm>
using namespace std;
int tian[1000];
int king[1000];
int win,lose;
int n,i;
int lt,lk,rt,rk;
namespace IO
{
    char ch;
    const int M = 0xcf;
    const int N = 0x30;
    int scan()
    {
        bool f = true;
        int sum=0;
        ch=getchar();
        while(ch!=‘\n‘||f==true)
        {
            if(ch<=‘9‘&&ch>=‘0‘){sum=sum*10+(ch&M);f=false;}
            else if((ch==‘ ‘||ch==‘\n‘)&&!f)return sum;
            ch=getchar();
        }
        return sum;
    }
    void print(int a)
    {
        char s[20];
        int i=0;
        if(a<0){putchar(‘-‘);a=-a;}
        if(a==0)putchar(‘0‘);
        while(a){s[i]=a%10|N;a/=10;i++;};
        while(i--){putchar(s[i]);}
    }
}
int main()
{
    while(n=IO::scan())
    {
        for(i=0;i<n;i++)tian[i]=IO::scan();
        for(i=0;i<n;i++)king[i]=IO::scan();
        sort(tian,tian+n);
        sort(king,king+n);
                win=lose=0;
                rk=rt=n-1;
                lt=lk=0;
                while(lt<=rt)
                {
                        if(tian[rt] > king[rk])
                        {
                                win++;rt--;rk--;
                        }
                        else if(tian[lt] > king[lk])
                        {
                                win++;lt++;lk++;
                        }
                        else{
                                if(tian[lt] < king[rk])
                                {
                                        lose++;
                                }
                                lt++;rk--;
                        }
                }
        IO::print(200*(win-lose));
        putchar(‘\n‘);
    }
    return 0;
}

这道题错了很多次,后来发现原来结果有负的情况,改了之后就好了。

时间: 2024-10-12 19:56:11

hdu acm-step 1.3.2 Tian Ji -- The Horse Racing的相关文章

(hdu step 1.3.3)Tian Ji -- The Horse Racing(田忌赛马)

题目: Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4411 Accepted Submission(s): 1069   Problem Description Here is a famous story in Chinese history. "That was about 2

HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and

HDU 1052 Tian Ji -- The Horse Racing【贪心在动态规划中的运用】

算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输,则连一条权为-200的边. 然而我们知道,二分图的最佳匹配算法的复杂度很高,无法满足N=2000的要求. 我们不妨用贪心思想来分析一下问题.因为田忌掌握有比赛的“主动权”,他总是根据齐王所出的马来分配自己的马,所以这里不妨认为齐王的出马顺序是按马的速度从高到低出的.由这样的假设,我们归纳出如下贪心

HDU Tian Ji -- The Horse Racing (贪心)

Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 56   Accepted Submission(s) : 25 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Here is a

hdu 1052 Tian Ji -- The Horse Racing 可恶的贪心-------也算是经典贪心题吧,对于一般人来说,不看题解,应该很难做出来吧

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20051    Accepted Submission(s): 5869 Problem Description Here is a famous story in Chinese history. "That was about

HDU 1052.Tian Ji -- The Horse Racing【很好的贪心】【8月27】

Tian Ji -- The Horse Racing Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others." "Both

hdu1052 Tian Ji -- The Horse Racing

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17346    Accepted Submiss

杭州电 1052 Tian Ji -- The Horse Racing(贪婪)

http://acm.hdu.edu.cn/showproblem.php? pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18058    Accepted Submission(s): 5239 Problem Description Here is a f

HDU1052 Tian Ji -- The Horse Racing 贪心

Tian Ji -- The Horse Racing Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1052 Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a

杭电 1052 Tian Ji -- The Horse Racing(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18058    Accepted Submission(s): 5239 Problem Description Here is a fa