HDOJ 1789 Doing Homework again (贪心)
来源:互联网 发布:武汉禾田软件 编辑:程序博客网 时间:2024/06/05 02:11
题目链接:~( ̄▽ ̄~)(~ ̄▽ ̄)~
code:
#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct{int dl, re;}node;node num[1005];int used[1005], n = 0, sum = 0;int cmp(const void *a, const void *b){return -((*(node *)a).re-(*(node *)b).re);}void greedy(){int i = 0, j = 0;for(i = 0; i<n; i++){if(!used[num[i].dl])used[num[i].dl] = 1;else{for(j = num[i].dl; j>0; j--)if(!used[j])break;if(j != 0)used[j] = 1;elsesum += num[i].re;}}}int main(){int i = 0, t = 0;scanf("%d",&t);while(t--){scanf("%d",&n);for(i = 0; i<n; i++)scanf("%d",&num[i].dl);for(i = 0; i<n; i++)scanf("%d",&num[i].re);qsort(num, n, sizeof(num[1]), cmp);memset(used, 0, sizeof(used[0])*(n+1));sum = 0;greedy();printf("%d\n",sum);}return 0;}
- HDOJ 1789 Doing Homework again (贪心)
- HDOJ 1789 Doing Homework again贪心
- hdoj 1789 Doing Homework again 【贪心】
- hdoj--1789--Doing Homework again(贪心模拟)
- HDOJ 1789-Doing Homework again【贪心】
- HDOJ.1789 Doing Homework again (贪心)
- hdu 1789 Doing Homework again (贪心)
- hdu 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again(贪心~!)
- hdu 1789 Doing Homework again (贪心)
- HDU 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again(贪心)
- HDU 1789 Doing Homework again(贪心)
- hdu 1789 Doing Homework again(贪心)
- HDU-1789-Doing Homework again(贪心)
- HDU 1789 Doing Homework again(贪心)
- Windows7与Window2008 64位IIS7上面配置操作Excel
- Firebug进阶——控制台详解
- C语言宏定义##连接符和#符的使用
- Oracle数据字典
- HDU 1789 Doing Homework again!
- HDOJ 1789 Doing Homework again (贪心)
- thinkphp输出重复2次 解决办法
- python面向对象编程
- 2. 最好使用C++转型操作符
- 进程间通信 - 剪贴板实现
- ORACLE ORA-01157: 无法标识/锁定数据文件
- 使用宏灵活的控制代码
- How to use epoll? A complete example in C
- 两个比较好的linux服务器监控软件SoU.6.0.0.444与SpotlightonMySQL_300