noip模拟赛 遭遇



分析:暴力挺好打的,对于前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模拟赛 遭遇的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- [Swift通天遁地]二、表格表单-(1)创建自定义的UITableViewCell(单元格类)
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 在CentOS下安装VMware tool
VMware tools是虚拟机VMware Workstation自带的一款工具.它的作用就是使用户可以从物理主机直接往虚拟机里面拖文件.如果不安装它,我们是无法进行虚拟机和物理机之间的文件传输的. ...
- codechef : TREDEG , Trees and Degrees
其实有原题,生成树计数 然鹅这题里面是两道题, 50pts 可以用上面那题的做法直接过掉,另外 50pts 要推推式子,搞出 O n 的做法才行(毕竟多项式常数之大您是知道的) 虽说这道题里面是没有 ...
- Enumerable.Union<TSource> 方法
功能:生成两个序列的并集(使用默认的相等比较器). 命名空间: System.Linq 程序集: System.Core.dll 备注:实现此方法时使用了延迟执行. 它直接返回一个对象,该对象存储了执 ...
- xcode 制作静态库文件(.a)
参考: http://www.jb51.net/article/37853.htm 摘要: 1. 获取.a文件的信息 lipo -info /Users/pjk1129/De ...
- linux小白成长之路5————安装Docker
1.安装docker 命令: yum -y install docker   2.启动docker 命令: systemctl start docker.service 3.查看docker版本 ...
- C语言指针的理解以及指针的指针的理解
指针指向的是内存地址编号,内存地址编号指向的是对应的内容. 我们需要一个变量,来储存内存地址编号,这个变量的值是一个内存地址编号,但是我们可以通过修改变量的值,来不断的改变内存地址编号. 但是,我们如 ...
- [ CodeForces 515 D ] Drazil and Tiles
\(\\\) \(Description\) 给出一个\(N\times M\) 的网格,一些位置是障碍,其他位置是空地,求是否存在一个用 \(1\times 2\)的骨牌铺满空地的方案,以及方案是否 ...
- Windows下80端口被进程System&PID=4占用的解决方法
我的占用原因是 SQL Server Reporting Services,停止掉这个服务并设置其为手动启动即可 如果你并没有安装 SQL Server,请参考下文解决 =============== ...
- QS之shell script
1 Invoke Mdoelsim In order to open Modelsim automatically, it is better to use a shell script to inv ...