您的位置:首页 > 编程语言 > Go语言

HDU 2019 Fighting for HDU(贪心水题)

2015-07-21 16:42 811 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2109

题       意:给你两组数据,按从下到大排序后,标胶对应位置的大小。

思       路:sort排序+贪心

代码如下:

#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
#define m 300040
typedef long long LL;
int main()
{
int n;
while( scanf ( "%d", &n ) != EOF )
{
if( n == 0 ) break;
int hdu[120],d[120];
for( int i = 0 ; i < n ; i ++ )
scanf ( "%d", &hdu[i] );
for( int i = 0 ; i < n ; i ++ )
scanf ( "%d", &d[i] );
sort( hdu, hdu+n );
sort( d, d+n );
int h = 0, dx = 0;
for( int i = 0; i < n; i ++ )
{
if( hdu[i] > d[i] ) h+=2;
else if( hdu[i] < d[i] ) dx+=2;
else {
dx++;h++;
}
}
printf("%d vs %d\n",h,dx);
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  algorithm 贪心