P2920 [USACO08NOV]时间管理Time Management

news/2024/10/23 8:37:07/

https://www.luogu.org/problemnew/show/P2920

#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>//头文件准备
using namespace std;
struct Work{//定义结构体,方便排序int v;int f;
}work[1005];
int n,ans;
bool cmp(Work x,Work y){return x.f>y.f;
}
int main(){scanf ("%d",&n);for (int i=1;i<=n;i++){scanf ("%d %d",&work[i].v,&work[i].f);}sort (work+1,work+1+n,cmp);//按照结束时间排序ans=work[1].f;//一开始答案是最后一件事的结束时间,然后从最后一件事一直模拟到第一件事for (int i=1;i<=n;i++){if (ans<=work[i].f)ans-=work[i].v;//如果你完成这件事的结束时间是在那件事应该完成时间之前,那么那件事的开始时间就是这件事的结束时间减去这件事的完成所需时间else ans=work[i].f-work[i].v;//如果不在应该完成时间之前,那么这件事的开始时间就是这件事应该完成时间减去这件事的完成所需时间}if (ans<0)printf ("-1\n");//如果FJ无论如何都完不成,就输“-1”(输出格式里有)else printf ("%d\n",ans);//否则输出他能睡多久懒觉(。。。真懒)while (1);//反抄袭return 0;
}

http://www.ppmy.cn/news/505742.html

相关文章

eclipse导入tomcat 8.0x源码

1、安装Ant Ant下载地址&#xff1a;http://ant.apache.org/bindownload.cgi 下载完成以后&#xff0c;解压到相应目录&#xff0c;例如我解压到了D:\open-soft\apache-ant-1.9.6文件夹 然后配置Ant的环境变量&#xff0c;增加 ANT_HOME 为D:\open-soft\apache-ant-1.9.6\ 然后…

poj 2920 Mine Map【BFS】

&#xfeff;&#xfeff; Mine Map Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 1023 Accepted: 493 题目大意&#xff1a; 给一个n*n的金库&#xff0c;金库中有地雷‘*’和空格?&#xff0c;现在你从金库中间出发&#xff0c;刚刚开始时&#xff0c;【遍历…

LUOGU P2920 [USACO08NOV]时间管理Time Management

题目描述 Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 < N < 1,000) to accomplish (like milking the cows, cleaning the barn, mending the fences, and so on). …

题解 P2920 【[USACO08NOV]时间管理Time Management】

好了&#xff0c;废话不多说&#xff0c;我们切入正题&#xff0c;首先&#xff0c;不懂得分治的可以去看这位大佬的文章&#xff0c; 这道题是让我们求最晚可以在什么时间起床&#xff0c;这里我们需要加入一个小小的贪心&#xff0c;就是结束时间短的放前面处理&#xff0c;至…

BZOJ1620洛谷P2920 [USACO08NOV]时间管理Time Management

emm贪心题&#xff0c;但不知道怎么让我搞成了并查集 先将数组按结束时间排序&#xff0c;因为肯定先安排靠后的工作&#xff0c;后面处理时冲突会减小很多 然后如何并查集乱搞呢&#xff1f; 假如下图是一个没有加入任务的时间线{{20,5},{15,4},{12,3},{10,1},{5,2}}这是排…

CenOS 7.x的高级管理工具systemd介绍

文章目录 一、系统启动流程回顾二、CentOS 5.x,6.x,7.x的init程序区别三、systemd工具介绍3.1、systemd工具概述3.2、systemctl工具概述3.3、service以及chkconfig工具使用回顾3.4、systemd中的unit介绍3.5、systemctl工具实现service和chkconfig的功能3.6、systemctl实现运行级…

P2920题解【[USACO08NOV]时间管理Time Management】

这个题不难&#xff0c;但我是蒟蒻。。。 先看题目 题目&#xff1a; Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 < N < 1,000) to accomplish (like milking the co…

[vue3.x]实战问题--vue2.x升级vue3.x遇到的问题

主要是记录一在使用vue&#xff0c;并且从vue2.x升级版本过程中遇到的问题&#xff0c;方便以后的查找 环境 升级vuenext 脚手架&#xff1a;vue-cli vue:2.6.11更新脚手架 脚手架如果存在全局安装 npm i vue/cli -g然后在项目中更新vue/cli-service npm i vue/cli-servi…