codeforces 6D
2 seconds
64 megabytes
standard input
standard output
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 1
2 2 2
- 3
2 2 2
- 4 3 1
1 4 1 1
- 4
2 2 3 3
(万万没想到啊,这题竟然可以用深搜。。我满脑子想的都是纯暴力,又是一道看了题解才恍然大悟的题
题意:n个人站成一排,发火球攻击,选择攻击的人受到a点伤害,其相邻的人受到b点伤害,目的是让所有人的血量都小于0,求最小攻击次数。
解题思路:因为火球只能攻击2-n-1,所以搜索的判断条件是前一个人的血量得小于0,结束条件是n的血量小于0。其实知道是搜索后,就挺好想的了
我的ac代码:
- 1 #include <iostream>
- 2 #include <cstdio>
- 3 #include <map>
- 4 using namespace std;
- 5 const int maxn = 22222;
- 6 int nu[maxn],ans=0x3f3f3f3f;
- 7 int res[maxn],num[maxn];
- 8
- 9 int n,a,b,len=0;
- 10 void dfs(int x,int c) {
- 11 if(c>=ans) return ;
- 12 if(x==n) {
- 13 if(nu[x]<0){
- 14 ans=c;
- 15 for(int k=0;k<ans;++k) {
- 16 res[k]=num[k];
- 17 }
- 18 }
- 19 return ;
- 20 }
- 21 for(int j=0;j<=max(nu[x-1]/b+1,max(nu[x]/b+1,nu[x+1]/b+1));++j) {
- 22 if(nu[x-1]<b*j) {
- 23 nu[x-1]-=b*j;
- 24 nu[x]-=a*j;
- 25 nu[x+1]-=b*j;
- 26 for(int k=0;k<j;++k) {
- 27 num[len++]=x;
- 28 // cout<<i<<endl;
- 29 }
- 30 dfs(x+1,c+j);
- 31 len-=j;
- 32 nu[x-1]+=b*j;
- 33 nu[x]+=a*j;
- 34 nu[x+1]+=b*j;
- 35 }
- 36 }
- 37
- 38 }
- 39 int main() {
- 40 ios::sync_with_stdio(false);
- 41 cin.tie(0);cout.tie(0);
- 42 cin>>n>>a>>b;
- 43 for(int i=1;i<=n;++i) {
- 44 cin>>nu[i];
- 45 }
- 46 dfs(2,0);
- 47 cout<<ans<<endl;
- 48 for(int i=0;i<ans;++i) cout<<res[i]<<" ";
- 49 return 0;
- 50 }
高手ac代码:(vector真是好啊
- 1 #include<bits/stdc++.h>
- 2 using namespace std;
- 3 int ans=9999999;
- 4 int h[100];
- 5 int a,b,n;
- 6 vector<int>V;
- 7 vector<int>V2;
- 8 void dfs(int x,int times)
- 9 {
- 10 if(times>=ans)return;
- 11 if(x==n)
- 12 {
- 13 if(h[x]<0){
- 14 V2=V;
- 15 ans=times;
- 16 }
- 17 return ;
- 18 }
- 19 for(int i=0; i <= max( h[x-1]/b+1,max( h[x]/a+1, h[x+1]/b+1) );i++)
- 20 {
- 21 if(h[x-1]<b*i)
- 22 {
- 23 h[x-1] -= b*i;
- 24 h[x] -= a*i;
- 25 h[x+1] -= b*i;
- 26 for(int j=0;j<i;j++) V.push_back(x);
- 27 dfs(x+1,times+i);
- 28 for(int j=0;j<i;j++) V.pop_back();
- 29 h[x-1] += b*i;
- 30 h[x] += a*i;
- 31 h[x+1] += b*i;
- 32 }
- 33 }
- 34 }
- 35 int main()
- 36 {
- 37 cin>>n>>a>>b;
- 38 for(int i=1;i<=n;i++)cin>>h[i];
- 39 dfs(2,0);
- 40 cout<<ans<<endl;
- 41 for(int i=0;i<V2.size();i++)cout<<V2[i]<<" ";
- 42 cout<<endl;
- 43 return 0;
- 44 }
codeforces 6D的更多相关文章
- Codeforces 6D Lizards and Basements 2 dfs+暴力
题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- Codeforces Global Round 6D(VECTOR<ARRAY<INT,3> >)
一个人只要存在债务关系,那么他的债务可以和这整个债务关系网中任何人连边,和他当初借出或欠下的人没有关系.只需要记录他的债务值即可. #define HAVE_STRUCT_TIMESPEC #incl ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
- Codeforces 1375F - Integer Game(交互)
Codeforces 题面传送门 & 洛谷题面传送门 一个奇怪的做法. 首先我们猜测答案总是 First.考虑什么样的情况能够一步把对方一步干掉.方便起见我们假设 \(a<b<c\ ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- 两节锂电池保护IC,芯片电路图如何设计
两节锂电池出了充电电路外,必须搭配的也就是两节锂电池的保护板电路和芯片了.对两节节串联可再充电锂离子/锂聚合物电池的过充电.过放电和过电流进行保护.和电池反接保护功能,这些都是极其重要的. 首先设计两 ...
- 1.Spring的基本应用
1.1概述 1.1.1 Spring是什么 Spring一个轻量级的框架,以IOC(控制反转)和AOP(面向切面编程)为内核,Spring在表现层提供了Spring MVC的框架整和功能,在业务逻辑层 ...
- Crunch
Crunch 目录 1. 简介 2. 命令格式 3. options可选参数 3.1 -b number[type] 3.2 -c number 3.3 -d numbersymbol 3.4 -e ...
- Graceful restart of a server with active WebSocket
Graceful restart of a server with active WebSocket Simonwep/graceful-ws: ⛓ Graceful WebSocket wrappe ...
- 前序遍历 排序 二叉搜索树 递归函数的数学定义 return 递归函数不能定义为内联函数 f(x0)由f(f(x0))决定
遍历二叉树 traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...
- 在Centos7上安装Python+Selenium+Chrome+Chromedriver
1.下载Chrome 上一篇文章已经演示过了Python+Selenium+Firefox+Geckodriver安装步骤并通过自动化脚本打开百度 因此当前只需要安装Chrome和Chromedriv ...
- three.js cannon.js物理引擎之制作拥有物理特性的汽车
今天郭先生说一说使用cannon.js的车辆辅助类让我们的汽车模型拥有物理特性.效果图如下,在线案例请点击博客原文. 下面我们说一下今天要使用的两个类,并简单的看看他们的物理意义 1. Raycast ...
- Vue技术点整理-指令
我们通常给一个元素添加 v-if / v-show 来做权限管理,但如果判断条件繁琐且多个地方需要判断,这种方式的代码不仅不优雅而且冗余. 针对这种情况,我们可以通过全局自定义指令来处理:我们先在新建 ...
- Stream API处理集合
使用流来遍历集合 简介 如何工作 总结 从集合或数组创建流 简介 如何工作 结论 聚合流的值 简介 如何工作 结论 转载 使用流来遍历集合 简介: Java的集合框架,如List和Map接口及Arra ...
- Cookie (设置与读取、超时设置、指定路径、显示用户上次登录时间)
Cooike简介 Cookie 是在 HTTP 协议下,服务器或脚本可以维护客户工作站上信息的一种方式.Cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的 ...