当前位置:网站首页>区间问题 : 今年暑假不AC
区间问题 : 今年暑假不AC
2022-08-02 03:22:00 【寒江飞冰】
题目描述
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%…”
确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
输入
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
输出
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
样例输入
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0
样例输出
5
方法一:结构体+排序
#include<bits/stdc++.h>
using namespace std;
struct Node{
int a;
int b;
};
bool cmp(Node x,Node y)
{
return x.b<y.b;
}
int main()
{
int n;
while(cin>>n&&n!=0)
{
Node m[n];
for(int i=0;i<n;i++)
{
cin>>m[i].a>>m[i].b;
}
sort(m,m+n,cmp);
int count=1; // 排好序之后 第一个肯定是能看的 因为它的结束时间最早
int temp=m[0].b;
for(int i=1;i<n;i++) // 如果第二个的开始时间大于等于上一个的结束时间
{
if(m[i].a>=temp) // 第二个肯定能看 依次循环
{
count++;
temp=m[i].b;
}
}
cout<<count;
}
方法二:pair函数
#include<bits/stdc++.h>
using namespace std;
const int Max=10000;
int N,S[Max],T[Max];
pair<int,int> itv[Max];
void solve(){
for(int i=0;i<N;i++)
{
itv[i].first=T[i];//pair函数以first进行整体排序
itv[i].second=S[i];
}
sort(itv,itv+N);
int ans=0,t=0;
for(int i=0;i<N;i++)
{
if(t<=itv[i].second){
ans++;
t=itv[i].first;
}
}
cout<<ans<<endl;
}
int main()
{
while(cin>>N&&N!=0)
{
for(int i=0;i<N;i++)
{
cin>>S[i]>>T[i];
}
solve();
}
}
边栏推荐
- AttributeError: Can't get attribute 'SPPF' on
- 3 minutes to take you to understand WeChat applet development
- 微信小程序实现文本安全监测
- ssm各类配置模板
- Basic usage of Monaco Editor
- subprocess.CalledProcessError: Command 'pip install 'thop'' returned non-zero exit status 1.
- 枚举法方法:(leetcode1300)转变数组后最接近目标值的数组和
- yolov5调用ip摄像头时出现的问题
- [Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
- AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
猜你喜欢
Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
mysql中如何查看表是否被锁
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
kettle 安装与配置
DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机
亚马逊卖家怎么提升转化率
ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决
随机推荐
最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机
oracle inner join and outer join
STM32 CAN过滤器
枚举法方法:(leetcode1300)转变数组后最接近目标值的数组和
化学试剂磷脂-聚乙二醇-羟基,DSPE-PEG-OH,DSPE-PEG-Hydroxyl,MW:5000
SOCKS5
配置mmdet来训练Swin-Transformer之一配置环境
跨域问题解决
require模块化语法
DOM操作---放大镜案例
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
我的小笔记 =》其他东东
由中序遍历和后序遍历得到前序遍历(树的遍历)
亚马逊卖家怎么提升转化率
pyppeteer使用样例脚本
第一篇博客
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
【面经】米哈游数据开发一面二面面经