题意:看电视,计算出最多看多少个电视,已给出电视起始终止时间;
解体思路:思路这个题拿到手没多想,上课的例题,就照葫芦画瓢写了一个;
感悟:虽然刚开始学贪心,第一遍代码就AC了有点小小的成就感;
代码(G++ 0MS)
#include

#include

#include

using namespace std;

struct Ti{

    int s;

    int e;

    bool
operator < (const Ti& other) const

    {

       
if(this->e==other.e)

           
this->s

       
return this->e

    }

};

int main()

{

   
//freopen("in.txt", "r", stdin);

    int
n,s,e,ans=1,d=1;

    Ti
t1[101],t2[101];

   
while(~scanf("%d",&n)&&n)

    {

       
ans=1;

       
d=1;

       
for(int i=0;i

       
{

           
scanf("%d%d",&s,&e);

           
t1[i].s=s;

           
t1[i].e=e;

       
}

       
stable_sort(&t1[0],&t1[n]);//按照节目时间由短到长排列

       
t2[0]=t1[0];//因为第一个是必须看的;

       
//cout<<"t1[0].s="<<t1[0].s<<"
"<<"t1[0].e="<<t1[0].e<<endl;

       
for(int i=1;i

       
{

           
if(t1[i].s>=t2[d-1].e)

           
{

               
//cout<<"t2[d-1].s="<<t2[d-1].s<<"
"<<"t2[d-1].e="<<t2[d-1].e<<endl;

               
t2[d++]=t1[i];

               
ans++;

           
}

           
//cout<<"t1[i].s="<<t1[i].s<<"
"<<"t1[i].e="<<t1[i].e<<endl;

       
}

       
printf("%d\n",ans);

    }

}

Problem E的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. 利用ASP.NET操作IIS (可以制作安装程序)

    很多web安装程序都会在IIS里添加应用程序或者应用程序池,早期用ASP.NET操作IIS非常困难,不过,从7.0开始,微软提供了 Microsoft.Web.Administration 类,可以很 ...

  2. Angular2响应式表单

    本文将半翻译半总结的讲讲ng2官网的另一个未翻译高级教程页面. 原文地址. 文章目的是使用ng2提供的响应式表单技术快速搭出功能完善丰富的界面表单组件. 响应式表单是一项响应式风格的ng2技术,本文将 ...

  3. div内部实现图片旋转、放大、缩小、拖拽

    药药,切克闹,一人我编码累,累把那bug写成堆.秋高气爽空气干燥你一定dei多喝水,过完了这周我就要回去.趁还有几天.你尽情的来跟我怼~~~ 新的一年,很久没更博客了,眼看十一要来了,听说过了十一就等 ...

  4. GitHub使用(一) - 新建个人网站

    1.首先进入“仓库Repositories”,点击“新建New”.

  5. Linux入门之常用命令(1)

    退出系统 exit 图形界面 startx 时间 date 日历 cal [month] [year] 计算器 bc 帮助 man [command]  // info [command] 在线用户 ...

  6. jQuery插件:Ajax将Json数据自动绑定到Form表单

    jQuery注册方法的两种常用方式: //jQuery静态方法注册 //调用方法$.a1() $.extend({ a1: function () { console.log("a1&quo ...

  7. fiddler 监听HttpClient发送的请求

    用HttpClient模拟浏览器发送请求,设置一下代理httpClient.getHostConfiguration().setProxy("127.0.0.1", 8888);

  8. python中package注意事项

    个人工作中的SSD.Cardreader.Camera.Audio模块文档组织形式如下: RclLib __init__.py RclLegacy.py modules AgilentOp.py Uv ...

  9. 小程序解释HTML富文本的两种办法

    今天写着着代码,读取数据库的内容时突然跳出"<span>.<p>. "这些HTML标签.字符,吓一跳:本来如果是写HTML.JS倒也没什么,但是我在写小程序 ...

  10. VB6文件操作自定义函数合集之一

    '--与文件及文件夹操作相关的函数 '--必须引用FSO的ACTIVE OBJECT Dim strList As String '--列表串,返回文件列表 '================ '-- ...