HDU 2019 Fighting for HDU(贪心水题)
2015-07-21 16:42
811 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2109
题 意:给你两组数据,按从下到大排序后,标胶对应位置的大小。
思 路:sort排序+贪心
代码如下:
题 意:给你两组数据,按从下到大排序后,标胶对应位置的大小。
思 路: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; }
相关文章推荐
- Javascript SHA-1:Secure Hash Algorithm
- [转]可视化的数据结构和算法
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- 统计文件中不小于某一长度的单词的个数(泛型算法实现)
- 使用他人的MD5编码类,修改形成密码串
- Extracting Structured Data from Web Pages
- (译)Cocos2d_for_iPhone_1_Game_Development_Cookbook:1.13使用CCTexture2DMutable调换调色盘
- Java中3DES加密
- Refactoring Notes-Refactoring Methods(3)
- 图书馆管理程序~~不过貌似功能!!有空再修修
- trainging contest#2(2011成都现场赛)I BY Hyoga
- C/C++头文件包含内容概览
- 堆栈的应用(1) 平衡符号 C++实现
- 程序员编程艺术第一章、左旋转字符串
- 程序员编程艺术:第三章续、Top K算法问题的实现
- 程序员编程艺术:第四章、现场编写类似strstr/strcpy/strpbrk的函数
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 程序员编程艺术:第七章、求连续子数组的最大和