分析:暴力挺好打的,对于前30%的数据神搜,hi相同的数据将所有的建筑按照c从小到大排序,看最多能跳多少,ci=0的数据将所有的建筑按照h从小到大排序,枚举起点和终点,看能否跳这么多,取个max就可以了.这样70分就到手了.

部分分的提示还是比较明显的,要消除一个参数的影响,那么就按照h从小到大排序,显然只有可能顺着跳过城市,不能跳过去又跳回来.那么就是一个比较简单的dp了:f[i][j]表示跳了i次,最后一次跳到j的最小花费,转移的话枚举j之前的k就能转移了,最后倒叙枚举i看哪一个f[i][j]<=T就可以了.

多个参数有影响的常见策略是消除一个参数的影响,常见的办法就是排序,如果一个点不能经过多次,那么就想一个办法让它强行不经过这个点.

暴力:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, T, ans, vis[];
bool flag1 = true, flag2 = true; struct node
{
int c, h;
}e[]; bool cmp1(node a, node b)
{
return a.c < b.c;
} bool cmp2(node a, node b)
{
return a.h < b.h;
} void dfs(int u, int sum,int tot)
{
ans = max(ans, tot + );
vis[u] = ;
for (int i = ; i <= n; i++)
{
if (!vis[i])
{
int huafei = abs(e[i].h - e[u].h) + e[u].c;
if (sum + huafei <= T)
dfs(i, sum + huafei, tot + );
}
}
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d", &e[i].c);
if (e[i].c != )
flag2 = false;
}
for (int i = ; i <= n; i++)
{
scanf("%d", &e[i].h);
if (i != && e[i].h != e[i - ].h)
flag1 = false;
}
scanf("%d", &T);
if (n <= || (!flag1 && !flag2))
{
for (int i = ; i <= n; i++)
{
memset(vis, , sizeof(vis));
dfs(i,,);
}
printf("%d\n", ans);
}
else
if (flag1)
{
sort(e + , e + + n, cmp1);
int res = , cur = ;
while (cur <= n && res <= T)
{
ans++;
res += e[cur].c;
cur++;
}
printf("%d\n", ans - );
}
else
{
sort(e + , e + + n, cmp2);
for (int i = ; i <= n; i++)
{
int j = i + , res = ;
while (j <= n && res <= T)
{
res += abs(e[j].h - e[j-].h);
j++;
}
ans = max(ans, j - i + );
}
printf("%d\n", ans - );
} return ;
}

正解:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,T;
int f[][]; struct node
{
int c, h;
}e[]; bool cmp(node a, node b)
{
return a.h < b.h;
} int main()
{
memset(f, / , sizeof(f));
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &e[i].c);
for (int i = ; i <= n; i++)
scanf("%d", &e[i].h);
scanf("%d", &T);
sort(e + , e + + n, cmp);
f[][] = e[].c;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
for (int k = j + ; k <= n; k++)
f[i + ][k] = min(f[i + ][k], f[i][j] + e[k].h - e[j].h + e[k].c); for (int i = n; i >= ; i--)
for (int j = ; j <= n; j++)
if (f[i][j] <= T)
{
printf("%d\n", i + );
return ;
}
printf("0\n"); return ;
}

noip模拟赛 遭遇的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. Kafka详解与总结(六)

    索引 稀疏存储,每隔一定字节的数据建立一条索引(这样的目的是为了减少索引文件的大小). 下图为一个partition的索引示意图: 注: 现在对6.和8建立了索引,如果要查找7,则会先查找到8然后,再 ...

  2. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation

    You are given a list of train stations, say from the station 11 to the station 100100. The passenger ...

  3. C#封装访问修饰符

    C# 封装 封装 被定义为"把一个或多个项目封闭在一个物理的或者逻辑的包中".在面向对象程序设计方法论中,封装是为了防止对实现细节的访问. 抽象和封装是面向对象程序设计的相关特性. ...

  4. linux学习之路5 系统常用命令

    日期时间 查看设置当前时间 date +%Y--%m--%d 格式化显示时间 -s " "(切换到超级用户)修改时间 hwclock(clock)用以显示硬件时钟时间 命令 cal ...

  5. mutiset HDOJ 5349 MZL's simple problem

    题目传送门 /* 这题可以用stl的mutiset容器方便求解,我对这东西不熟悉,TLE了几次,最后用读入外挂水过. 题解有O(n)的做法,还以为我是侥幸过的,后来才知道iterator it写在循环 ...

  6. 用Movie显示gif(1)SimpleGif

    代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...

  7. UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素

    "UC浏览器中,设置了position: fixed 的元素会遮挡z-index值更高的同辈元素(非fixed)." 我们使用的artDialog弹窗中,在UC浏览器中,如果页面高 ...

  8. LN : leetcode 283 Move Zeroes

    lc 283 Move Zeroes 283 Move Zeroes Given an array nums, write a function to move all 0's to the end ...

  9. linux 常用shell命令 ls

    ls:查看文件名和目录,用法:$ ls [选项] 1. $ ls 直接输入ls命令,则列出当前目录下的所有文件和目录,不显示详细信息,如类型,大小,日期权限等. 2. $ ls -l -l 选项,每行 ...

  10. Java 基础入门随笔(11) JavaSE版——继承、覆盖、抽象类

    1.面向对象的特征二:继承 定义: 指一个对象直接使用另一对象的属性和方法. 继承好处: 1.提供代码的复用性. 2.让类与类直接产生了关系,给第三个特征多态提供了前提. java中支持单继承.不直接 ...