soj4236 && soj2750
来源:互联网 发布:淘宝上的上海大药房 编辑:程序博客网 时间:2024/05/01 23:14
只所以把两个题目放在一块,是觉得这两个题目有异曲同工之妙吧。算是排序和贪心吧。
题目链接:http://cstest.scu.edu.cn/soj/problem.action?id=4263
http://cstest.scu.edu.cn/soj/problem.action?id=2750
4263:
#include <stdio.h>#include <algorithm>using namespace std;const int MAX = 1000+10;struct node{ int a; int b;}cloth[MAX];bool operator<(const node&p1, const node&p2){ return p1.b-p1.a>p2.b-p2.a;}int main(){ int v, m; while (scanf("%d%d", &v, &m) == 2) { int i; for (i=1; i<=m; i++) { scanf("%d%d", &cloth[i].a, &cloth[i].b); } sort(cloth+1, cloth+m+1); for (i=1; i<=m; i++) { if (v<=0||v<cloth[i].b) { puts("NO"); break; } else { v -= cloth[i].a; } } if (i==m+1) { puts("YES"); } }}
2750:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAX = 10005;struct node{ string str;}no[MAX];int n;bool operator<(const node& a, const node& b){ return a.str + b.str < b.str + a.str;}int main(){ while (cin >> n) { for (int i=0; i<n; i++) { cin >> no[i].str; } sort(no, no+n); for (int i=0; i<n; i++) { cout << no[i].str; } cout << endl; }}
- soj4236 && soj2750
- javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
- zk event thread model
- linux find命令详解
- Android
- 使用Vitamio打造自己的Android万能播放器(12)—— 播放网络视频缓冲处理
- soj4236 && soj2750
- 黑马程序员--面向对象(一)
- Linux切换键命令及常用指令
- Android设备的识别
- android SDK 安装目录结构详解及各工具
- 关于二叉查找树的一些题目
- ffmpeg 应用(1)
- 64位ubuntu下android开发环境的配置
- android中ListView拖动时背景黑色的问题