题目链接:推桌子

题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次。

思路:贪心,首先按照S从小到大排序,决策:从第一个开始找最长的一条可以同时进行的操作,循环操作。

易错点:1 这里的操作不是一定 S> L的 会有L< S

    2  给你一个例子就知道了,  1 3

                   4 5  这个操作的时候这个正确的应该是20,为什么,自己看图就知道了

代码:

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef struct numb
{
int l,r;
}numb; numb a[205]; bool fun(numb x,numb y)
{
return x.l < y.l ? true:false;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int i;
memset(a,0,sizeof(a));
for(i = 0; i < n; i++)
{
scanf("%d%d",&a[i].l,&a[i].r);
if(a[i].l > a[i].r)
{
int ans = a[i].l;
a[i].l = a[i].r;
a[i].r = ans;
}
}
sort(a,a+n,fun);
int t = 0;
int max = 0;
int j = 0;
int flag = 1;
while(flag)
{
for(j = 0; j < n; ++j)
{if(a[j].l != 0)
{
max = a[j].r;
a[j].l = 0;
a[j].r = 0;
break;
}
if( j+1 == n)
{
flag = 0;
break;
}
}
if(!flag)
break;
t++;
for(i = j+1; i < n; i++)
{
if(max %2 == 1)
{
if(a[i].l > max +1)
{
max = a[i].r;
a[i].l = 0;
a[i].r = 0;
} }
else
if(a[i].l > max)
{
max = a[i].r;
a[i].l = 0;
a[i].r = 0;
}
}
}
printf("%d\n",t*10);
}
return 0;
}

nyist 220 推桌子的更多相关文章

  1. nyoj 220——推桌子——————【贪心】

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Computer Maker) Company has re ...

  2. nyoj220 推桌子(贪心算法)

    这道题太坑了,from 和to有可能写反,还得正过来: 推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Co ...

  3. ACM 推桌子

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Computer Maker) Company has re ...

  4. ny220 推桌子

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has rent ...

  5. iOS---iOS10适配iOS当前所有系统的远程推送

    一.iOS推送通知简介 众所周知苹果的推送通知从iOS3开始出现, 每一年都会更新一些新的用法. 譬如iOS7出现的Silent remote notifications(远程静默推送), iOS8出 ...

  6. socket.io简单入门(一.实现简单的图表推送)

    引子:随着nodejs蓬勃发展,虽然主要业务系统因为架构健壮性不会选择nodejs座位应用服务器.但是大量的内部系统却可以使用nodejs试水,大量的前端开发人员转入全堆开发也是一个因素. 研究本例主 ...

  7. nyist 518 取球游戏

    http://acm.nyist.net/JudgeOnline/problem.php?pid=518 取球游戏 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 今 ...

  8. 采用PopupWin控制消息推送功能

    最近的项目需要,急需实现消息推送功能.接连试了很多办法,让我们用JavaScript为了实现啊,其效果是不咋好,最后,我发现了一个PopupWin这个,看着眼前的成绩不错,开始使用. 1.准备工作.先 ...

  9. Android端 配置极光推送

    由于业务须要,androidclient须要加推送.原来採用的百度推送.可是小米手机有时候收不到.后来换成了极光推送,极光的话全部设备都能收到推送,可是在高峰的时候会推迟.博主说的免费版的,收费的没用 ...

随机推荐

  1. 常用Python第三方库 简介

    如果说强大的标准库奠定了python发展的基石,丰富的第三方库则是python不断发展的保证,随着python的发展一些稳定的第三库被加入到了标准库里面,这里有6000多个第三方库的介绍:点这里或者访 ...

  2. The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)

    The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...

  3. Android studio mac版本快捷键

    Mac下快捷键的符号所对应的按键 ⌥—> option|alt ⇧—>shift ⌃—>control ⌘—>command ⎋—>esc 注: 与F6/F7/F12等F ...

  4. Js把URL中的参数解析为一个对象

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. Viewing the Raw SQL Statement(xcode で)

    Thanks to Core Data. Even without learning SQL and database, you’re able to perform create, select, ...

  6. 重拾php---以及zend-studio 的使用快捷方式

    感觉好久没有碰php了,今天心血来潮,重新入门.先整理一下刚刚学习的笔记. 一个字符串是用双引号括起来的一个词或一个句字,比如:“Hi,imooc!”.你可以用PHP语言输出把这个字符串输出,像这样: ...

  7. python模块—urllib

    1. 网页操作 urllib.urlopen(url[,data[,proxies]]) 打开一个url,返回一个文件对象,然后可以进行类似文件对象操作 url:远程数据的路径,即网址 data:表示 ...

  8. 宏定义&CodeBlocks&Glib

    一.gcc的参数中-Dmacro             等价于代码里   #define macro -Dmacro=value  等价于代码里   #define macro value -Uma ...

  9. git忽略特殊文件

    忽略特殊文件 有些时候,你必须把某些文件放到Git工作目录中,但又不能提交它们,比如保存了数据库密码的配置文件啦,等等,每次git status都会显示Untracked files ...,有强迫症 ...

  10. aliyun 启用ECS iptables

    iptables -t nat -A POSTROUTING -s 0.0.0.0/24 -o eth0 -j MASQUERADEservice iptables saveecho 1 > / ...