wa了5遍?!!

(1)前4遍,思路没简化,企图模拟整个过程,但是调用sort函数时由于没有把奇数的屋子和偶数的屋子统一,排序出了问题。

思路:遍历n段,每次只扫未被标记过的一段,ans++并且从该段出发,访问到第n段,将所有和该段不重叠的段标记为1,ans不变。

代码:

#include<bits/stdc++.h>
using namespace std;
#define maxn 500
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ll long long
struct gg{
int s,e;
}a[maxn];
int vis[maxn]; int cmp(gg k1,gg k2){
return k1.s<k2.s;
} int main()
{
int T;
cin>>T;
while(T--){
int n;
memset(vis,0,sizeof(vis));
scanf("%d",&n);
rep(i,0,n){
int x,y;
scanf("%d%d",&a[i].s,&a[i].e);
if(a[i].s>a[i].e)
swap(a[i].s,a[i].e);
a[i].s=a[i].s%2==0?a[i].s:a[i].s+1;
a[i].e=a[i].e%2==0?a[i].e:a[i].e+1;
}
sort(a,a+n,cmp); int ans=0; rep(i,0,n){
if(!vis[i]){
int last=a[i].e;
ans++,vis[i]=1;
rep(j,i+1,n){
if(!vis[j]){
if(a[j].s>last){
last=a[j].e;
vis[j]=1;
}
}
}
}
} ans*=10;
printf("%d\n",ans); } return 0;
}

  (2)简化思路:把从一个屋子到另一个屋子看作线段,计算所有线段中被重叠次数最多的线段对应的重叠次数。理解:和某线段不重叠的线段不计入总时间。只要知道重叠次数最多的线段,就能知道有多少线段要计入总时间。

代码:

#include<bits/stdc++.h>
using namespace std;
#define maxn 500
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ll long long int vis[maxn];
int main()
{
int T;
cin>>T;
while(T--){
int n;
memset(vis,0,sizeof(vis));
scanf("%d",&n);
rep(i,0,n){
int x,y;
scanf("%d%d",&x,&y);
if(x>y)
swap(x,y);
if(x%2)
x++;
if(y%2)
y++;
for(int j=x;j<=y;j+=2)
vis[j]++;
}
int ans=0;
rep(i,0,401){
ans=max(ans,vis[i]);
}
ans*=10;
printf("%d\n",ans);
}
return 0;
}

  

HDU - 1050的更多相关文章

  1. --hdu 1050 Moving Tables(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...

  2. hdu 1050 Moving Tables 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...

  3. hdu 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 这个题我首先直接用的常规贪心,用的和那个尽可能看更多完整节目那种思路.但是.......一直WA....T ...

  4. HDU – 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...

  5. hdu 1050 Moving Tables (Greedy)

    Problem - 1050 过两天要给12的讲贪心,于是就做一下水贪心练习练习. 代码如下: #include <cstdio> #include <iostream> #i ...

  6. hdu 1050 (preinitilization or postcleansing, std::fill) 分类: hdoj 2015-06-18 11:33 34人阅读 评论(0) 收藏

    errors, clauses in place, logical ones, should be avoided. #include <cstdio> #include <cstr ...

  7. hdu 1050 Moving Tables_贪心

    题意:你搬n个桌子,桌子从一个地方搬到另一个地方,走廊只允许同时一个桌子通过,教室分布在两边,奇数在一边,偶数在一边,当桌子不冲突时可以同时搬运,冲突时要等别的那个桌子搬完再搬. 思路:因为奇数桌子在 ...

  8. HDU 1050(搬椅子 数学)

    题意是在一个有 400 个房间的走廊中搬动房间里的椅子,如果两次的路线重叠,就要分两次搬动,如果不重叠,就可以一次搬动. 开始的时候直接当成求线段重叠条数的题,发现这种思路完全是错的,比如 1 - 3 ...

  9. HDU 1050 Moving Tables (贪心)

    题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...

随机推荐

  1. 破解idea地址

    https://blog.csdn.net/animatecat/article/details/81483174

  2. nginx简单的命令

    nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t #测试配置是否有语法错误 nginx [-?hvVtq] [-s si ...

  3. Webstorm的一些常用快捷键

    ctrl+/ 单行注释ctrl+shift+/块注释Ctrl+X 删除行Ctrl+D 复制行Ctrl+B 快速打开光标处的类或方法Ctrl+F 查找文本Ctrl+R 替换文本ctrl+shift+ + ...

  4. RedisCache 缓存

    /// <summary> /// 这是包装过公用的,用于本站而已. /// </summary> /// <author>rixiao</author> ...

  5. Java代理模式之Cglib代理

    Cglib代理,也叫做子类代理.在内存中构建一个子类对象从而实现对目标对象功能的扩展. CGLIB包的底层是通过使用一个小而快的字节码处理框架ASM,来转换字节码并生成新的类.不鼓励直接使用ASM,因 ...

  6. Manual write code to record error log in .net by Global.asax

    完整的Glabal.asax代码: <%@ Application Language="C#" %> <script RunAt="server&quo ...

  7. [模板] 2-SAT 问题

    简介 2-SAT (2-satisfiability) 问题形如: 给定一些变量 \(x_i \in \{true, false\}\); 给定一些一元/二元约束条件, 如 \(x_i \land \ ...

  8. 高新兴 ME3630-W 4G 模块 Android 平台适配

    2019-04-26 关键字:高新兴 ME3630-W 适配.rk3128 移植 4G 模块 本篇文章系笔者在移植 高新兴物联 ME3630-W 4G 模块到运行着 Android4.4 操作系统的 ...

  9. yk-随记

    $config = Loader::loadConfig('smarty');

  10. selenium自动化测试python

    一.环境部署 1.selenium安装 pip3 install selenium 1.安装浏览器驱动 WebDriver 需要通过浏览器驱动来与浏览器交互,以下列出几种常用的浏览器驱动下载地址: C ...