首页 > 其他分享 >Codeforces Beta Round #22 (Div. 2 Only)-D. Segments

Codeforces Beta Round #22 (Div. 2 Only)-D. Segments

时间:2023-06-12 17:32:10浏览次数:35  
标签:node 22 int Segments ++ Only ans input mins


原题链接


D. Segments



time limit per test



memory limit per test



input



output



You are given n



Input



The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n



Output



The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.



Examples



input



2
0 2
2 5



output



1
2



input



5
0 3
4 2
4 8
8 10
7 7



output



3
7 10 3







把所有线段按照左端点从小到大排序,放在node[]数组中,因为nod[0]木棒一定要被钉,那么现在求在node[0]木棒被钉的基础上最多能钉多少木棒。设mins = node[0].r

便利for(i = 1; i < n; i++)若node[i].l > mins那么i之前的木棒可以用一根钉子钉在一起,否则mins = min(mins, node[i].r);

以此类推.....


#include <bits/stdc++.h>
#define maxn 100005
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct Node{
	int l, r;
	friend bool operator < (const Node&a, const Node&b){
		return a.l < b.l;
	}
}node[1005];
vector<int> v;
int main(){
	
//	freopen("in.txt", "r", stdin);
	int n, t = 0;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
	 scanf("%d%d", &node[i].l, &node[i].r);
	 if(node[i].l > node[i].r)
	  swap(node[i].l, node[i].r);
   }
	sort(node, node+n);
	int ans = 0;
	int mins = node[0].r;
	for(int i = 1; i < n; i++){
		if(node[i].l > mins){
			ans++;
		    v.push_back(mins);
			mins = node[i].r;
		}
		else{
			mins = min(mins, node[i].r);
		}
	}
	v.push_back(mins);
	ans++;
	printf("%d\n", ans);
	printf("%d", v[0]);
	for(int i = 1; i < ans; i++)
	 printf(" %d", v[i]);
	puts("");
	
	return 0;
}




标签:node,22,int,Segments,++,Only,ans,input,mins
From: https://blog.51cto.com/u_16158872/6464285

相关文章

  • 关于VS2022使用EF生成实体模型报错的问题:运行转换:System.NullReferenceException:对象
    起因:之前版本vs2022生成EF模型一直没有问题,在更新了最新的vs2022之后,版本号17.6+,出现此问题:运行转换:System.NullReferenceException:对象引用未设置为对象的示例。在Microsoft.VisualStudio.TextTemplatingD21DB4521EFD493FAE41A9CE9DA80C875F3084552987498BD518713BDE91D14A......
  • LightOJ 1422 Halloween Costumes (区间DP)
    题意:你要连续去很多个舞会,给出n个舞会你需要穿的衣服的编号,一旦脱下就不能再穿,但是可以一件套一件,问最少需要准备多少件衣服。思路:区间DP,令dp[i][j]为第i到第j天需要的衣服,那么对于第i天,如果考虑后面没有和它重复的话,那么dp[i][j]=dp[i+1][j]+1,如果存在某一天a[i]==a[k],dp[i][j]=......
  • SM2259XT2开卡长江TAS,附SM2259XT2开卡工具,我更喜欢MAS1102量产工具
    闲的没事干,测一下59xt2+TAS,用的公版主控板,跳线按官方的来,电压给1v2,vcc不用管默认,都能用。随便焊一下,ce齐全,单颗2ce128G,单帖分布2ch/1ce。跑个rdt看看,DDR800。开卡工具是从量产部落下载的YMTC_TAS开卡工具。RDTMaxECC均在十几二十,全新自封片,还算不错体质。直接开卡,轻松开出来,容量aut......
  • 工业互联网2022年工作计划
    ......
  • 喜报|Only&Home新时尚数码家电品牌入驻北京南站,开启消费新风尚
    来源:北京日报网北京南站,做为中国首座高标准现代化的大型综合交通枢纽。位于中国北京市丰台区,是中国铁路北京局集团有限公司管辖的特等站,是北京的第二大火车站,也是北京面积最大、接发车次最多的火车站。2023年6月,Only&Home做为新时尚数码家电品牌,系列产品正式应邀入驻北京南站VIP候......
  • 论文解读 | IROS 2022:基于三维激光雷达的语义位置识别和姿态估计
    原创|文BFT机器人01研究背景这篇论文的背景是在自动驾驶和机器人导航等领域,需要实现高精度、高效率的定位和地点识别。然而,传统的基于GPS或视觉的方法存在一些局限性,尤其在城市峡谷等环境中无法提供准确的位置信息。为了解决这一问题,使用3DLiDAR进行定位和地点识别已经成为一......
  • x01.os.22: 填补一下
    制作LiveCD参考ubuntu官方推荐一键制作在deepin上操作,脚本需要更改为:RELEASE=bionic,makecd.sh代码如下:#!/bin/bash#Author:Redbrother#Email:[email protected]#license:None#data:201910#scriptsin/usr/share/debootstrap/scripts########......
  • English Learning Articles 2022-06-11 Your teen wants to get in shape this summer
    Yourteenwantstogetinshapethissummer?Whattosayandwhentoworry|CNN Ifyourchildrensaytheywanttostartexercisingorworkingoutmorethissummer,don’tcelebratejustyet.Iknowmostparentswouldbethrilledtoseetheirteenstakin......
  • 龙芯中科发布的 《龙芯生态白皮书(2022年)》的.NET 生态章节节选
    3月27日,全面反映LoongArch产业生态发展最新成果的《龙芯生态白皮书(2022年)》正式对外发布,白皮书下载地址:https://kdocs.cn/l/ce5Emg1C2pPd,我将其中涉及到.NET部分的内容节选出来,可以看到龙芯对.NET的支持的非常的不错,我知道他们有个几十人的.NET编译器团队在全职推进.NET的LoongA......
  • ubuntu22.04设置静态ip
    设置虚拟机网络修改配置文件查看配置文件ls/etc/netplansudovi01-network-manager-all.yaml//添加如下配置network:ethernets:ens33:dhcp4:false//关闭dhcpaddresses:[192.168.5.21/24]//设置静态ipoptional:trueroutes:......