codeforces-230A-Dragons(贪心+排序)

codeforces 1574 C. Slay the Dragon 本场比赛其他题目题解 A. Regular Bracket Sequences B. Combinatorics Homework C. Slay the Dragon D. The Strongest Build C. Slay the Dragon 开启传送门 题目描述 Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with 阅读详情

题目链接:codeforces.com/problemset/problem/230/A

A. Dragons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.

If Kirito starts duelling with the i-th (1 ≤ i ≤ n) dragon and Kirito's strength is not greater than the dragon's strength xi, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by yi.

Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.

Input

The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.

Output

On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.

Sample test(s)
input
2 2
1 99
100 0
output
YES
input
10 1
100 100
output
NO
Note

In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.

In the second sample Kirito's strength is too small to defeat the only dragon and win.



解析:

一只龙有 S 的血量。

其他 n 只龙,第 i 只龙有 Xi 的血量,其被打死之后,胜利者有 Yi 的血量奖励。

若要该龙胜利到最后,则在每一场战斗后,该龙的最优选择就是选择一只血量最小的龙战斗。

因此只要按照每只龙的血量排序即可。


参考代码:

#include<stdio.h>
#include<stdlib.h>
struct node
{
    int x;
    int y;       
}ans[1010];
int cmp(const void *a, const void *b)
{
    struct node *aa = (node *)a;
    struct node *bb = (node *)b;
    return (((aa->x)>(bb->x))?1:-1);    
}
int main()
{
    int s, n;
    while(scanf("%d %d", &s, &n) != EOF)
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d %d", &ans[i].x, &ans[i].y);        
        }                
        qsort(ans, n, sizeof(ans[0]), cmp);
        int i=0;
        while(ans[i].x<s && i<n)
            s += ans[i++].y;
        if(i==n)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;    
}




难度指数1000 Codeforces 230A Dragons 阅读详情

相关推荐

codeforces——230A——Dragons

A. Dragons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kirito is stuck on a level of the MMORPG he is playing now

lose__way的博客 607

CodeForces 230A. Dragons

http://codeforces.com/problemset/problem/230/A 简单题 只需注意下对于结构体种某个元素的排序,自己写cmp函数的写法 #include&lt;iostream&gt; #include&lt;algorithm&gt; using namespace std; struct dragon{ int x; int y; }; dra...

肖火柴的火柴盒 347

Nacos 2.3.2实战:5分钟搞定达梦数据库插件配置(含避坑指南)

本文详细介绍了在Nacos 2.3.2中配置达梦数据库数据源插件的完整实战流程。通过解析SPI插件机制,提供从环境准备、插件编译部署到核心配置的逐步指南,并重点分享了驱动加载、SQL兼容性等高频问题的避坑解决方案,助力开发者高效完成国产化数据库适配。

weixin_29200485的博客 499

codeforces 230 A (简单贪心) B(质数扩展)

A. Dragons(简单贪心) 题目链接:codeforces 230A 题意: 一个人初始力量为 s ,有n条龙, 如果力量大于龙的力量x[i],那么可以打过这条龙并获得这条龙的额外给定的力量y[i],如果可以打过所有龙(可以按任意顺序),输出YES , 否则输出 NO 题解: 肯定是先打力量小的龙,如果力量相同,先打给额外力量多的龙 #include <bit...

error311的博客 531

Arduino应用——PWM控制直流电机风扇

Arduino应用——PWM控制直流电机风扇PWM原理实验器件功能描述如何改变文本的样式插入链接与图片实现代码生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 最近在使用arduino UNO开发板完成课程小作业。其中一个要求设计一个电风扇控制系统,要求能够通过PWM调节风扇的转速。期间搜索了许多例程和方法,但受限于器件,效果不

hypecycle的博客 2万+

Keil MDK打开别人工程总报错?手把手教你修复‘找不到main.o’和‘未定义’的路径问题

本文详细解析Keil MDK工程移植时常见的'找不到main.o'和'未定义'编译错误,提供从路径修复到宏定义配置的完整解决方案。通过系统化的检查清单和预防措施,帮助开发者快速解决MDK工程迁移问题,提升嵌入式开发效率。

weixin_28724661的博客 399

Codeforces 3B.Lorry(贪心,排序)

明明是一道水题好么。。。 题意是有两种货物,一种占用1单位面积,另一种占用2单位面积 每个货物有对应的价值 现在有n个货物,总面积为v,问如何能够使所载货物价值最大 很明显的背包问题 但是因为要打印路径,感觉直接排序写起来比较方便 我的思路是按不同面积排序,每次比较两种情况的价值,取较大者 我的思路是对的,可能是题目时间太久的原因,莫名其妙地RE 把RE代码贴在这里,希望发现问题的

小华在努力~ 1020

从零构建AI Agent集群:Docker Compose与Nginx部署实战

在AI应用开发领域,微服务架构和容器化部署已成为提升开发效率和系统可维护性的关键技术。Docker Compose作为容器编排工具,能够将多个独立服务(如Node.js、Python应用)及其依赖(数据库、缓存)封装在隔离环境中,并通过统一配置文件定义服务间的网络与依赖关系,实现一键启停。Nginx作为反向代理,则提供了统一的网络入口、请求路由和负载均衡能力,是构建高可用Web应用的基石。这种组合技术方案的价值在于,它能将复杂的AI系统(如工作流引擎、对话Agent、技能库)的部署运维复杂度大幅降低,使得开

weixin_27028523的博客 638

codeforces976C(排序+贪心)

题目链接:http://codeforces.com/contest/976/problem/C题意:给出一些区间,让你找出使得li&gt;=lj&amp;&amp;ri&lt;=rj的i j,有多组解输出任意一组即可,没有输出-1,-1思路:按照l小到大排个序,相等r大到小排个序,挨着找就可以了。代码:#include&lt;bits/stdc++.h&gt; using namespace s...

时光、疏离了记忆づ童话的博客 914

IAR for ARM 搭建STM32F103C8T6工程模板(实战指南)

本文详细介绍了如何在IAR for ARM开发环境中为STM32F103C8T6微控制器搭建完整的工程模板。从环境准备、固件库获取、目录结构设计到工程配置与编译调试,提供了实战指南和常见问题解决方案,帮助开发者快速建立稳定的STM32开发环境。

fun88的博客 988

全覆盖路径规划开源项目Clean-robot-turtlebot3关键函数解析(上)

本系列文章主要介绍全覆盖路径规划开源项目Clean-robot-turtlebot3的相关内容,包含如下四篇文章,分别介绍了开源项目Clean-robot-turtlebot3流程的概括总结、ROS坐标系常用坐标及其变换、Clean-robot-turtlebot3关键函数解析等内容。

慕羽★的博客 2778

Dragons(CodeForces 230A)(贪心和排序)

这题是CSU-ACM暑假集训基础组训练赛(1)

旧时相识的专栏 1425

提高RFID检测距离以及检测速度的方法总结

摘要:提高RFID检测距离需优化阅读器功率、标签灵敏度、天线设计及频段选择,同时减少环境干扰;提升检测速度则需改进防碰撞算法、增强并行处理能力、精简数据传输。实际应用需平衡两者关系,如物流仓储采用UHF频段、高增益天线和动态Q算法实现远距离高速读取,ETC系统则通过微波频段和高速调制实现超远距离快速识别。不同场景需针对性优化硬件配置和系统参数。

start_up_go的博客 292

CodeForces 230A Dragons(贪心)

Dragons time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Kirito is stuck on a level of the MMORPG he is playing now. To move on in the gam

Hot_Summer_Days的专栏 1075

【图像拼接】论文精读:Content-Preserving Warps for 3D Video Stabilization(CPW)

论文题目:Content-Preserving Warps for 3D Video Stabilization——用于3D视频稳定的内容保持扭曲GSP、SPW、LPC等warp时多个项最小化问题的思想都是来自于这篇论文——CPW视频防抖。我们描述了一种从手持摄像机转换视频的技术,以便它看起来像是用定向相机运动拍摄的。我们的方法调整视频以出现,就好像它是从附近的视点拍摄的,允许模拟 3D 相机运动。通过仅针对感知合理性,而不是准确的重建,我们能够开发能够有效从单个源视频中重建动态场景的算法。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 2万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

CodeForces 230A Dragons

原题传送门:http://codeforces.com/problemset/problem/230/A     A. Dragons time limit per test 2 seconds     memory limit per test256 megabytes input standard input output standard o...

u014663203的专栏 169

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

A. Dragons 【1000 / 贪心】

https://codeforces.com/problemset/problem/230/A #include<bits/stdc++.h> using namespace std; bool flag=true; vector<pair<int,int>>ve; int main(void) { int s,t; cin>>s>>t; for(int i=0;i<t;i++) { int a,b; cin>>a&.

bettle_king的博客 180

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Dragons

http://codeforces.com/problemset/problem/230/A Dragons time limit per test 2 seconds memory limit per test ...

weixin_34205826的博客 126

【CodeForces 651B】Beautiful Paintings 排序+贪心

题目大意: 给定集合AA,对于任意一个AA的排列(a1,a2,...,an)(a_1,a_2,...,a_n),记S(a)=cnt(ai<ai+1)S(a)=cnt(a_i<a_{i+1}),求max(S(a))\max(S(a))。很明显每次搞出一个长度为cntcnt的最长上升序列,然后把元素给删掉,答案增加cnt−1cnt-1。 直接暴力需要O(n2)O(n^2)。但是可以进行优化。 设有

Sdchr 402

codeforces822C(排序+贪心)

题目链接:http://codeforces.com/problemset/problem/822/C 题意:n各区间,每个区间都有一个值cost,可能有相交,给出一个总时间x,选取每个区间[L,R]花费时间为R-L+1;问是否能选取某些不相交区间使得花费总时间为x。 如果能,要求值cost总和最小。 思路:对于l从小到大排序,将r放进优先队列从小到大排序。 代码: #includebi

时光、疏离了记忆づ童话的博客 616

A. Dragons

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kirito is stuck on a level of the MMORPG he is playing now. To m

无知的我 2155

CodeForces 230A 贪心+排序

记得当时做的时候第一次还很蠢的累加了== 其实就是排个序啦,如果前面的龙

一段旅途 1084
上一篇: hdu -1237- 简单计算器(栈实现)
下一篇: codeforces-230B-T-primes
monkey7777
博客等级 码龄15年 55粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值