hdu 1052 田忌赛马

贪心,排序从大到小。。

先比大的。跑只是就拿最小的来送死。。

假设是平局就比后面的。。。

若后面也是平局就拿去跟前面的去跑。

。。

#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

using namespace std;

int s[1005],w[1005];

int main()

{

int n,i;

while(scanf("%d",&n))

{

if(n==0)

break;

for(i=0;i<n;i++)

scanf("%d",&w[i]);

for(i=0;i<n;i++)

scanf("%d",&s[i]);

sort(w,w+n);

sort(s,s+n);

int z=0,sum=0,c=n-1,v=n-1;

int i1=0,i2=0;

while(z++<n)

{

if(w[c]>s[v])

{

sum+=200;

c--;

v--;

}

else if(w[c]<s[v])

{

sum-=200;

i1++;

v--;

}

else

{

if(w[i1]>s[i2])

{

sum+=200;

i1++;

i2++;

}

else

{

if(w[i1]<s[v])

sum-=200;

i1++;

v--;

}

}

}

printf("%d\n",sum);

}

return 0;

}

时间: 2024-10-24 11:56:21

hdu 1052 田忌赛马的相关文章

hdu 1052(田忌赛马 贪心算法,sort排序)

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

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

C语言贪心(2)___田忌赛马(Hdu 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 others." "Both of Tian and the king have t

HDU 1052 Tian Ji -- The Horse Racing (田忌赛马)

田忌和齐王各有N匹马,判断怎样比赛,使田忌净胜场数最多. 之前无意看到强哥写的题解(很早就做了~~囧)感觉很有意思,但是当时忘了去A 了,现在回想起来此题很是经典了,意犹未尽的感觉,直接复制题解了,思路写的很清楚了, 基本就是看着思路敲的 [解题思路]不管怎么比赛 http://www.midifan.com/moduleuser-index-400171.htmhttp://www.midifan.com/moduleuser-index.htmhttp://www.midifan.com/m

【贪心专题】HDU 1052 Tian Ji -- The Horse Racing (田忌赛马)

链接:click here~~ 题意: 田忌和齐王各有N匹马,判断怎样比赛,使田忌净胜场数最多. 之前无意看到强哥写的题解(很早就做了~~囧)感觉很有意思,但是当时忘了去A 了,现在回想起来此题很是经典了,意犹未尽的感觉,直接复制题解了,思路写的很清楚了, 基本就是看着思路敲的 [解题思路]不管怎么比赛,都要让田忌的马发挥最大价值.当然,马的第一要务是用来赢得比赛,而且要最大效益的赢,也就是要赢对方仅次于自己的马. 当他不能完成这个任务的时候就要去输,并拉对方最快的马下水,给自己后面的队友创造更

HDU 1052 贪心+dp

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): 31270    Accepted Submission(s): 9523 Problem Description Here is a fam

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

题意:田忌赛马,问你田忌最多能赢多少银子. 析:贪心,绝对贪心的题,贪心策略是: 1.如果田忌当前的最快的马能追上齐王的,那么就直接赢一局 2.如果田忌当前的最慢的马能追上齐王的,那么就直接赢一局 3.如果田忌当前的最慢的马不能超过齐王的,那么就输一局,并把齐王最快的干掉 通过以上策略,就是田忌赢的最多. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #incl

HDU 1052

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 of Tian and the king have three hor

hdu 1052 贪心

// 判断出(田忌)的必胜局面和必败局面,则可以容易的得到决策方案 // 若没有明显的必胜局面和必败局面,则使用田忌赛马的策略 1 #include "bits/stdc++.h" 2 using namespace std; 3 int N; 4 int v1[1010], v2[1010]; 5 6 int main() 7 { 8 while(scanf("%d", &N) && N) { 9 int i, j; 10 for(i =