CF_6D_LizardsAndBasements_2
来源:互联网 发布:sql count用法详解 编辑:程序博客网 时间:2024/05/20 07:54
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
3 2 12 2 2
32 2 2
4 3 11 4 1 1
42 2 3 3
题意:
给出n个弓箭手给出他们的血量hi
法师每次可以选择2到n-1中的一个弓箭手砸一发法术
然后这个法术会对中间的弓箭手造成a点伤害,两侧的b点
然后问最少多少次怎么砸可以把他们都杀掉
这个题暴力勉强可以过1700ms……时限好像2000ms
从左往右打
因为每次至少把最左边能波及到的那个杀死
最多就是把影响到的都杀死
只要这样在这个范围枚举dfs即可
#include <iostream>#include <stdio.h>using namespace std;const int M=20;int h[M];int n,a,b;int ans=1e9;int ansn[150],anss[150];int ceil(int x,int y) //x/y结果向上取整{ if(x<=0) return 0; if(x%y) return x/y+1; return x/y;}void dfs(int p,int pre,int now,int pos,int num){ int t=max(ceil(pre,b),ceil(now,a)); t=max(t,ceil(pos,b)); //<<p<<" "<<pre<<" "<<now<<" "<<pos<<" "<<t<<endl; if(p==n-1) { for(int i=1;i<=t;i++) ansn[i+num]=n-1; num+=t; if(num<ans) { ans=num; for(int i=1;i<=num;i++) anss[i]=ansn[i]; } return; } //cout<<pre<<" "<<b<<" "<<ceil(pre,b); for(int i=ceil(pre,b);i<=t;i++) { for(int j=1;j<=i;j++) ansn[num+j]=p; //cout<<"i "<<i<<endl; dfs(p+1,now-i*a,pos-i*b,h[p+2],num+i); }}int main(){ scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++) scanf("%d",&h[i]); for(int i=1;i<=n;i++) h[i]++; dfs(2,h[1],h[2],h[3],0); printf("%d\n",ans); for(int i=1;i<ans;i++) printf("%d ",anss[i]); printf("%d\n",anss[ans]); return 0;}
- CF_6D_LizardsAndBasements_2
- C语言经典小程序(热门题型)
- android 自动初始化控件 不用注解不用findViewByid
- 百度地图为啥定位不了
- 支持向量机—线性可分支持向量机与硬间隔最大化
- 第四周项目3①-小学生算术能力测试系统
- CF_6D_LizardsAndBasements_2
- STM32 串口采用DMA方式收发
- GDAL库进度信息编写示例
- 分享一个linux指令手册指南
- zoj3228(AC自动机进阶)
- shell教程三:基本语法
- SecureCRT远程连接到虚拟机Ubuntu Linux上
- Spring 3.x中三种Bean配置方式比较
- 关键帧的边缘检测