hdu acm steps 1.3.6
来源:互联网 发布:农村淘宝服务站 昆山 编辑:程序博客网 时间:2024/04/29 23:25
题目:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=3&problemid=13
贪心+排序。
下面是AC代码:
#include<stdio.h>#include<stdlib.h>struct In{ int m; int n;}s[110];int cmp(const void *a,const void *b){ return (*(struct In*)a).m>(*(struct In*)b).m?-1:1;}int main(void){ int i,j; int w,v,sum; while(scanf("%d",&w)!=EOF) { if(w==0) break; scanf("%d",&v); for(i=0;i<v;i++) scanf("%d %d",&s[i].m,&s[i].n); qsort(s,v,sizeof(s[0]),cmp); sum=0; for(i=0;i<v&&w>0;i++){ if(w>=s[i].n){ sum+=s[i].n*s[i].m; w=w-s[i].n; } else{ sum+=w*s[i].m; w=0; } } printf("%d\n",sum); } return 0;}
- hdu acm steps 1.3.6
- hdu ACM Steps 1.3
- hdu acm steps 1.3.1
- hdu acm steps 1.3.2
- hdu acm steps 1.3.3
- hdu acm steps 1.3.4
- hdu acm steps 1.3.5
- hdu acm steps 1.3.7
- hdu acm steps 1.3.8
- hdu acm steps 2.1.6
- hdu acm steps 2.2.6
- HDU 1.2.6 (ACM steps)
- hdu ACM steps 1.3.4 hdu 2561
- hdu ACM Steps 1.3.5 排序
- hdu ACM steps 1.2.6 hdu3361
- hdu ACM Steps 1.1
- hdu ACM Steps 1.2
- hdu ACM Steps 2.1
- 步骤二:买空间或者用自己电脑做服务器
- hdu acm steps 1.3.5
- Wireshark检测不到网卡解决方案
- Android 软件管理器的开发1
- Delphi 使用HLP文件制作系统的帮助文档
- hdu acm steps 1.3.6
- 步骤三:域名解析,收尾
- 哈希结构---访问大文件(查看单个文件中出现最多的单词)
- IAR安装与破解WIN7版本
- struts原理与实践(二)
- Merge into 详细介绍
- 我的学习家园
- shell脚本实现ftp自动备份
- 关于cache line