HDU - 1050
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的更多相关文章
- --hdu 1050 Moving Tables(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...
- hdu 1050 Moving Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- hdu 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 这个题我首先直接用的常规贪心,用的和那个尽可能看更多完整节目那种思路.但是.......一直WA....T ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- hdu 1050 Moving Tables (Greedy)
Problem - 1050 过两天要给12的讲贪心,于是就做一下水贪心练习练习. 代码如下: #include <cstdio> #include <iostream> #i ...
- 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 ...
- hdu 1050 Moving Tables_贪心
题意:你搬n个桌子,桌子从一个地方搬到另一个地方,走廊只允许同时一个桌子通过,教室分布在两边,奇数在一边,偶数在一边,当桌子不冲突时可以同时搬运,冲突时要等别的那个桌子搬完再搬. 思路:因为奇数桌子在 ...
- HDU 1050(搬椅子 数学)
题意是在一个有 400 个房间的走廊中搬动房间里的椅子,如果两次的路线重叠,就要分两次搬动,如果不重叠,就可以一次搬动. 开始的时候直接当成求线段重叠条数的题,发现这种思路完全是错的,比如 1 - 3 ...
- HDU 1050 Moving Tables (贪心)
题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...
随机推荐
- React 系列教程2:编写兰顿蚂蚁演示程序
简介 最早接触兰顿蚂蚁是在做参数化的时候,那时候只感觉好奇,以为是很复杂的东西.因无意中看到生命游戏的 React 实现,所以希望通过兰顿蚂蚁的例子再学习一下 React. 兰顿蚂蚁的规则非常简单: ...
- python rpyc 报错: AttributeError: cannot access 'new'
Error msg: Traceback (most recent call last): File "/home/hpcm/Desktop/test/install/client.py&q ...
- scala的多种集合的使用(4)之列表List(ListBuffer)的操作
1.List列表的创建和添加元素 1)最常见的创建list的方式之一. scala> val list = 1 :: 2 :: 3 :: Nil list: List[Int] = List(1 ...
- springboot 配置文件
– Spring Boot使用一个全局的配置文件 • application.properties • application.yml – 配置文件放在src/main/resources目录或者类路 ...
- 安装Cnario Player 3.8.1.156或其他版本时提示"Warning 4154. Adobe Flash Player 13 ...not correctly installed"
错误提示 安装Cnario Player 3.8.1.156或其他版本时, 有时会出现如下提示: Warning 4154. Adobe Flash Player 13 ...not correctl ...
- Scrapy:腾讯招聘整站数据爬取
项目地址:https://hr.tencent.com/ 步骤一.分析网站结构和待爬取内容 以下省略一万字 步骤二.上代码(不能略了) 1.配置items.py import scrapy class ...
- js 前端常用排序算法总结
(冒泡排序.快排顺序.选择排序.插入排序.归并排序) 下面是前端比较常用的五个算法demo: 冒泡算法:比较两个相邻的数值,if第一个>第二个,交换他们的位置元素项向上移动至正确的顺序. fun ...
- vue中watch检测到不到对象属性的变化的解决方法
watch: { option: { handler(newVal) { console.log(newVal); }, deep: true, immediate: true } }, 需要深层wa ...
- Python进阶8---面向对象基础1
面向对象 语言的分类 Python的类 定义 class ClassName: pass class MyCalss: """A example class"& ...
- element vue 表格编辑
https://xuliangzhan.github.io/vue-element-extends/#/editable/click1