Sicily-1134

一.      题意

按照孩子们需要的积木块数排序(从小到大),先处理需要积木块数少的孩子。

二.      代码

 1 //
 2 //  main.cpp
 3 //  sicily-1134
 4 //
 5 //  Created by ashley on 14-10-25.
 6 //  Copyright (c) 2014年 ashley. All rights reserved.
 7 //
 8
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12
13 typedef struct
14 {
15     long ownCake;
16     long wantCake;
17 }child;
18
19 child childs[10000];
20
21 bool compare(child left, child right)
22 {
23     return left.wantCake < right.wantCake;
24 }
25
26 int main(int argc, const char * argv[])
27 {
28     int childrenNum;
29     long currentNum, cakeNum;
30     bool success;
31     while (cin >> childrenNum >> cakeNum) {
32         if (childrenNum == 0) {
33             break;
34         }
35         success = true;
36         currentNum = cakeNum;
37         for (int i = 0; i < childrenNum; i++) {
38             cin >> childs[i].ownCake >> childs[i].wantCake;
39         }
40         sort(childs, childs + childrenNum, compare);
41         for (int i = 0; i < childrenNum; i++) {
42             if (childs[i].wantCake > currentNum) {
43                 success = false;
44                 cout << "NO" << endl;
45                 break;
46             } else {
47                 currentNum = currentNum + childs[i].ownCake;
48             }
49         }
50         if (success) {
51             cout << "YES" << endl;
52         }
53     }
54     return 0;
55 }
时间: 2024-12-18 18:57:39

Sicily-1134的相关文章

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252

zzuli oj 1134 字符串转换

题目链接: https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1134 Description 输入一个以回车结束的字符串,它由数字和字母组成,请过滤掉所有非数字字符,然后将数字字符串转换成十进制整数后乘以2输出. Input 输入一个以回车结束的字符串,长度不超过100,由数字和字母组成. Output 将转换后的整数乘以2输出,测试数据保证结果在int范围内. Sample Input sg987aa65t498 Sample Output 1

Sicily 1146:Lenny&#39;s Lucky Lotto(dp)

题意:给出N,M,问有多少个长度为N的整数序列,满足所有数都在[1,M]内,并且每一个数至少是前一个数的两倍.例如给出N=4, M=10, 则有4个长度为4的整数序列满足条件: [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 10] 分析:可用动态规划解题,假设dp[i][j],代表满足以整数i为尾数,长度为j的序列的个数(其中每一个数至少是前一个数的两倍).那么对于整数i,dp[i][j] 等于所有dp[k][j-1]的和,其中k满足:

1134: 零起点学算法41——多组测试数据(a+b)III

1134: 零起点学算法41--多组测试数据(a+b)III Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 1585  Accepted: 1174[Submit][Status][Web Board] Description 对于多组测试数据,还有一些是没有明确告诉你多少组,但会告诉你输入什么样的数据就结束,如每组输入2个整数,但如果输入的是0 0就结束,这类题目的处理方法是 int main(

sicily 1345 能量项链

先模拟一下确定理解题意,然后再找状态转移方程,注意方向~ 1 //sicily 1345 能量项链 2 #include <bits/stdc++.h> 3 4 using namespace std; 5 6 int a[205]; 7 int dp[205][205]; 8 9 int main() 10 { 11 int n; 12 while(cin >> n) 13 { 14 memset(dp, 0, sizeof(dp)); 15 for(int i=0; i<

sicily 1063. Who&#39;s the Boss

Time Limit: 1sec    Memory Limit:32MB Description Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is alway

Sicily 1735 Encryption (模拟)

链接:http://soj.me/show_problem.php?pid=1735&cid= Description Let me introduce an easy method of encryption to you. Suppose there're N bytes (1 byte = 8 bits) data that are to be encrypted and we want to encrypt them in groups of M bytes, while for the

51nod 1134 最长递增子序列 (O(nlogn)算法)

1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9) Output 输

sicily 1219(记忆化搜索)

题目链接:sicily 1214 解题思路: 博弈题,用搜索来做.但是,如果用普通的搜索来做的话,是会超时的--复杂度大约是O( n^n ),所以需要采用记忆化搜索的方法(其实差不多就是动态规划了,但是这里是树形DP). 状态: 用集合S表示现在树的状态,i 表示现在轮到谁进行砍边,dp[ S ][ i ]表示最优值.集合S可以用二进制来表示,即001表示现在还剩下第0条边. 状态转移: 1)A的目标是取最大值,B的目标是取最小值,我们在推导当前状态的最优解时,需要分两种情况考虑!即A得维护较大