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 ...
随机推荐
- 清北考前刷题day2早安
/* 做法一:按h sort一遍,对于一段区间[i,j],高度花费就是h[j]-h[i] 然后枚举区间,把区间内C排序,一个一个尽量选即可. n^3logn 标算:n^3 dp 高度排序,保证从前往后 ...
- eccharts-gl 3D立体柱状图
echarts-gl继承于echarts echarts-gl官方实例https://echarts.baidu.com/examples/index.html#chart-type-globe 代码 ...
- 回调函数,回调函数使用call
回调函数:一个函数b作为参数,给另外一个函数a使用.并且在执行a之后(注意不一定是执行完a),再去执行b这个函数. 上代码: function a(callback) { alert("我是 ...
- jQuery——表单应用(2)
多行文本框应用之高度变化 HTML: <!--表单-多行文本框应用-高度变化--> <!DOCTYPE html> <html> <head> < ...
- [转]C语言常见错误总结1
指针与数组的对比c程序中,指针和数组在不少地方可以相互替换着用,让人产生一种错觉,以为两者是等价的 数组要么在静态存储区被创建(如全局数组),要么在栈上被创建.数组名对应着(而不是指向)一块内存,其地 ...
- ACM_拼接数字
拼接数字 Time Limit: 2000/1000ms (Java/Others) Problem Description: 给定一个正整数数组,现在把数组所有数字都拼接成一个大数字,如何使得拼接后 ...
- HTML基础2——综合案例1——如何用iis配置网站
1.打开iis 如果机子上面没有iis,可以先装一个,不同的系统可能安装步骤不一样,至于iis的安装方法,大家可以去百度找找. 2.准备网站源程序 既然要配置网站,肯定要先准备好网站源程序,网 ...
- 转 linux之sed命令详解
http://jingyan.baidu.com/article/fec4bce2228f60f2618d8bb0.html sed 编辑裁剪文件命令 sed -i "s/\/db\/te ...
- c# Queue实现生产者(Producer)消费者(Consumer)模式
我们在开发过程中经常会遇到需要从一个地方不断获取数据然后又需要交给另一个线程对数据进行二次加工的情况,这种场景适合使用生产者-消费者模式. Demo展示 //中间的容器 public static c ...
- 为什么我的对象被 IntelliJ IDEA 悄悄的修改了?
背景 最近,在复习JUC的时候调试了一把ConcurrentLinkedQueue的offer方法,意外的发现Idea在debug模式下竟然会 "自动修改" 已经创建的Ja ...