hdu1050
#include <cstdio>
#include <algorithm>
using namespace std;
#define SIZE 205
struct Data_Type
{
int from, to;
bool flag;
}moving[SIZE];
bool Cmp(const Data_Type a, const Data_Type b)
{
return a.from < b.from;
}
int main(void)
{
int i, testNum, n;
scanf("%d", &testNum);
while (testNum-- != 0)
{
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d%d", &moving[i].from, &moving[i].to);
if (moving[i].from > moving[i].to)
{
int temp = moving[i].from;
moving[i].from = moving[i].to;
moving[i].to = temp;
}
if (moving[i].from % 2 == 0)
{
moving[i].from--;
}
if (moving[i].to % 2 == 1)
{
moving[i].to++;
}
moving[i].flag = false;
}
sort(moving, moving+n, Cmp);
bool completion = false;
int count = -1, priorTo;
while (!completion)
{
completion = true;
count++;
priorTo = 0;
for (i = 0; i < n; i++)
{
if (!moving[i].flag && moving[i].from > priorTo)
{
moving[i].flag = true;
priorTo = moving[i].to;
completion = false;
}
}
}
printf("%d\n", count*10);
}
return 0;
}
hdu1050的更多相关文章
- poj-1083-Moving Tables(hdu-1050)
Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description The f ...
- hdu1050(贪心)
囧 . 想了好久,一开始想的是一个连通图怎样用黑白两色染色,想了各种算法发现都不好做,然后灵机一动这不是网路流吗,然后想怎么建图,如果转换成网络流这题就好做了,建图加个二分应该就可以解决了,最后又发现 ...
- hdu1050 Moving Tables
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1050 求区间上点的最大重叠次数. #include <stdio.h> #include &l ...
- HDU1050(Moving Tables:贪心算法)
解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...
- hdu1050 Moving Tables---贪心
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1050 题目大意:就说有一些桌子需要从某些房间搬到另一些房间,但中间只有一条走廊,且走廊中任何一段只能 ...
- hdu-1050(贪心+模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 思路:由图可知,1对应2,3对应4,以此类推,如果x,y是偶数则变为奇数: 每次输入两个区间,找 ...
- Hdu1050 Moving Tables 2016-05-19 16:08 87人阅读 评论(0) 收藏
Moving Tables Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floo ...
- HDU1050:Moving Tables
pid=1050">Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 贪心算法训练(四)——(HDU1050)Moving Tables
题目描述 在一个狭窄的走廊里将桌子从一个房间移动到另一个房间,走廊的宽度只能允许一个桌子通过.给出 t,表示有 t 组测试数据,再给出 n,表示要移动 n 个桌子.n 下面有 n 行,每行两个数字,表 ...
随机推荐
- 算法(Algorithms)第4版 练习 1.5.3
id数组和treesize数组变化情况: 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 10 components 9 0 1 2 3 4 5 6 7 8 9 1 1 ...
- 大话设计模式--观察者模式 Observer -- C++ 实现实例
大话设计模式--1.观察者模式: 定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象,这个主题对象在状态发生变化时,会通知所有的 观察者对象,使他们能够自动更新自己. 使用场合: 当一 ...
- 使用button的:after伪类选择器内容的跳动
按钮的css样式,想要作个美观一点的按钮,使用:after伪类选择器在按钮后跟随"!!"的符号,但点击按钮时按钮的值内容动,但跟随的"!!"符合不动,这样看起来 ...
- 单机版 RedisUtils({基本操作封装工具类})【三】
<!--集成的RedisJAR--> <!--引入jedis需的jar包--> <dependency> <groupId>redis.clients& ...
- 分享知识-快乐自己:SSH 整合 Demo
楼主A: XML 版 SSH整合Demo https://github.com/MlqBeginner/BlogGardenWarehouse/blob/master/SSH%E6%95%B4%E5% ...
- 机器学习(十九)— xgboost初试kaggle
1.官网下载kaggle数据集Homesite Competition数据集,文件结构大致如下: 2.代码实战 #Parameter grid search with xgboost #featur ...
- 十七 Django框架,文件上传
1.自定义上传[推荐] 请求对象.FILES.get()获取上传文件的对象上传对象.name获取上传文件名称上传对象.chunks()获取上传数据包,字节码类型 html <!DOCTYPE h ...
- Apache配置负载均衡-实例
公司两台服务器都安装了tomcat,配置apache作为负载均衡,当一台服务器出现故障时还能保证业务正常运行. Server1:192.168.1.100 Server2:192.168.1.200 ...
- eslipse 修改tomcat server location 解决HTTP Status 404 – Not Found
Eclipse中tomcat service设置选择window ----show view---services可以看到服务的面板双击tomcat进入配置界面Service Locations(Sp ...
- uoj279温暖会指引我们前行
暖气来啦~ 动态树维护最大生成树裸题 #include<iostream> #include<cstdio> #include<cstdlib> #include& ...