【UVA - 10020 】Minimal coverage (贪心,区间覆盖问题)

题干:(Uva题不给题干了)

     t组样例,每组首先给出一个M,然后给出一些线段(0 0结束),然后问怎么取能使得最少的线段覆盖区间[0, M]。

Sample Input
2
1
-1 0
-5 -3
2 5
0 0
1
-1 0
0 1
0 0
Sample Output
0
1
0 1    

解题报告:

   就是个贪心啊

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
struct Node {int st,ed;Node(){}Node(int st,int ed):st(st),ed(ed){}bool operator<(const Node & b) const{if(st != b.st) return st < b.st;return ed > b.ed;}
} node[MAX];
int tot,n,m,cnt,nb;
int ans[MAX];
int main()
{int t;int a,b,maxx,minn;cin>>t;while(t--) {tot=cnt=0;maxx = 0,minn = 0x3f3f3f3f;scanf("%d",&m);while(scanf("%d%d",&a,&b)) {if(a==0 && b==0) break;if(b<=0) continue;if(a>=m) continue;node[++tot] = Node(a,b);maxx = max(maxx,b);minn = min(minn,a);}sort(node+1,node+tot+1);int cure,curs;curs=cure=0;
//		if(minn >= m || maxx <= 0) {
//			puts("0");
//			if(t) puts("");
//			continue;
//		}int flag = 0;for(int i = 1; i<=tot; ) {if(node[i].st > curs) {break;	}while(i<=tot && node[i].st<=curs) {if(node[i].ed > cure) {cure = node[i].ed;nb = i;}i++;}//if(i!=tot) i--;ans[++cnt] = nb;curs = cure;if(curs >= m) {flag=1;break;}}if(flag == 0) puts("0");else {printf("%d\n",cnt);for(int i = 1; i<=cnt; i++) printf("%d %d\n",node[ans[i]].st,node[ans[i]].ed);}if(t) puts("");}return 0 ;} 

总结: 那两句读数据的时候的if去掉好像也可以AC,,反正注释掉的那一部分加上也可以AC。。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441112.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java邮箱地址正则表达式_Java 中用正则表达式修改 Email 地址

需求系统中有一列会用来存储 email 地址&#xff0c;现在需要对输入的字符串进行过滤&#xff0c;要求是&#xff0c;把无效的地址过滤掉。有一些需要说明的是这些地址是通过图像识别得到的&#xff0c;有些是用户自己输入的已有历史记录已经存在了脏数据&#xff0c;需要替换这…

【CodeForces - 305C】Ivan and Powers of Two(思维,STL,set,优先队列)

题干&#xff1a; Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number …

【CodeForces - 1082B】Vova and Trophies (贪心模拟,暴力)

题干&#xff1a; Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wan…

java mac 转换 整形_JAVA的整型与字符串相互转换

1如何将字串 String 转换成整数 int?A. 有两个方法:1). int i Integer.parseInt([String]); 或i Integer.parseInt([String],[int radix]);2). int i Integer.valueOf(my_str).intValue();注: 字串转成 Double, Float, Long 的方法大同小异.2 如何将整数 int 转换成字串 St…

【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

题干&#xff1a; Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for e…

java迷宫生成算法_DFS算法迷宫生成器

我正在尝试使用DFS算法在ASCII中创建迷宫(&#xff03;表示墙和自由空间)&#xff0c;其左上角开始&#xff0c;右下角出口 . 问题是迷宫开始创建&#xff0c;然后它被阻止&#xff0c;因为它的所有邻居都已被访问过 .我从左上角开始&#xff0c;将单元格标记为已访问并放置一个…

【牛客 - 272A】Phrase String(构造,水题)

题干&#xff1a; 给出v, k&#xff0c;请你找到最小的正整数n&#xff0c;满足&#xff1a; n的二进制表示下存在一个长度为v的回文串&#xff0c;该回文串首尾都是1且n的二进制表示中至少有k个1。保证v,k均为偶数&#xff01; 由于n可能很大&#xff0c;你只需要输出对取模的…

eclipse 跑maven命令_maven编写命令行执行mvn package没问题,eclipse执行报错

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼报错是这样的“[ERROR] Unknown lifecycle phase "Systemout3". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sou…

【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)

题干&#xff1a; Mike has always been thinking about the harshness of social inequality. Hes so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A  [a1, a2, ..., an…

erlang odbc mysql参数_Erlang在Redhat 5.3下使用unixODBC连接Oracle数据库的配置

个人在安装配置时遇到一些麻烦&#xff0c;特此记录如下&#xff1a; 环境 数据库服务器操作系统&#xff1a;Windows 2003 数据库&#xff1a;Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统&#xff1a;Redhat 5.3 erlang:Erlang R1…

【POJ - 2533】Longest Ordered Subsequence(四种方法解决最长上升子序列 含二分优化版本)

题干&#xff1a; Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 41944 Accepted: 18453 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any se…

halcon图片上传到mysql_C# 10个线程并发执行Halcon图像算法 报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”...

如题&#xff0c;这个问题本人已经纠结了快三个工作日了。本人不同WinFrom程序一起动就会开启10个线程&#xff0c;并发对10张图片进行算法处理&#xff0c;问题是只要程序一起动就会报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”异常。本人试过将8个线程停掉…

【HDU - 1025】Constructing Roads In JGShining's Kingdom(dp最长上升子序列模型 + 二分优化)

题干&#xff1a; Constructing Roads In JGShinings Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29933 Accepted Submission(s): 8496 Problem Description JGShinings kingdom consists of 2n…

java list详解_Java 中 list 用法案例详解

LIST是个容器接口可以理解为动态数组&#xff0c;传统数组必须定义好数组的个数才可以使用&#xff0c;而容器对象无须定义好数组下标总数&#xff0c;用add()方法即可添加新的成员对象&#xff0c;他可以添加的仅仅只能为对象&#xff0c;不能添加基本数据类型&#xff0c;容器…

【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级)】小乐乐的组合数+(取模,数学,思维)

题干&#xff1a; 小乐乐得知一周有7天之后就对7产生了兴趣。 小乐乐得到了两堆数字数字时连续的。 第一堆包含[1,n]n个数字&#xff0c;第二堆包含[1,m]m个数字。 小乐乐想要从两堆中各挑选出一个整数x,y&#xff0c;使得x,y的和为7的倍数。 请问小乐乐有多少种组合的方式…

java 写文件 属性吗_使用JAVA读写Properties属性文件

自己定义一个属性文件&#xff1a;例如prop.propertiesbaseFilePathD\:/kuanter/resourcetesxabcd我们要做的第一步就是要将文件读取到Properties类对象中&#xff0c;由于load有一个参数是InputStream&#xff0c;所以我们可以用 InputStream的子类FileInputStream将属性文件读…

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】 小乐乐算数字(水题,快速幂,lowbit)

题干&#xff1a; 小乐乐最喜欢玩数字了。 小乐乐最近迷上了2这个整数&#xff0c;他觉得2的幂是一种非常可爱的数字。 小乐乐想知道整数x的最大的 2的幂 &#xff08;2^y&#xff09;的因子。 y为整数。 输入描述: 输入整数x。(1<x<1e18) 输出描述: 输出整数x的最…

java date 相差_java 比较时间相差多少分钟

/** * 返回二个时间相差的分分钟数,如果一个为空&#xff0c;返回为0&#xff1b; * param startDate&#xff0c;比如08&#xff1a;09 * param endDate&#xff0c;如18&#xff1a;09 * return */ public static int getMinutesDiff(String startDate,String endDate){ int …

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐吃糖豆 (fIb博弈)

题干&#xff1a; 小乐乐是一个比较喜欢吃糖豆的小孩子&#xff0c;小乐乐的哥哥大乐乐也同样爱吃糖豆。 作为一个小孩子&#xff0c;他们永远觉得谁吃掉了最后一个糖豆&#xff0c;谁吃的糖豆最多。 为了公平起见小乐乐与大乐乐商量吃糖豆的规则如下&#xff1a; 1. …

html5 sse java_html5----sse实现服务端推送数据给前端

案例基于thinkPHP框架&#xff1a;服务端方法&#xff1a;public function ssefun(){ob_implicit_flush();header(Content-Type: text/event-stream);header(Cache-Control: no-cache);$itime();echo retry:1000.PHP_EOL;//每秒执行一次echo "data: The server time is: {…