zoukankan      html  css  js  c++  java
  • 题解 CF6D Lizards and Basements 2

    $dfs$ 好啊

    题意

    有一队人,你可以用火球点某个人,会对当前人造成a点伤害,对旁边的人造成b点伤害。

    不能打1号和n号,求最少多少发点死所有人。

    Note 

    一个人被打死当且仅当它的血量 <0。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cstdlib>
     6 #include<algorithm>
     7 #include<string>
     8 #define ll long long
     9 #define maxn 100005
    10 #define inf 2147483647
    11 #define mod 10003
    12 #define eps 1e-6
    13 #define pi acos(-1.0)
    14 #define de(x) ((x)*(x))
    15 using namespace std; 
    16 inline int read(){
    17 int x=0,f=1; char ch=getchar();
    18 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    19 while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    20 return x*f;
    21 }
    22 int n,a,b,h[15],tot,ans;
    23 int p[155],val[155];
    24 inline void check(){
    25 int yu=max(h[n-1]/a+(h[n-1]>=0),h[n]/b+(h[n]>=0));
    26 for(int i=1;i<=yu;i++) p[++tot]=n-1;
    27 if(ans>tot){
    28 for(int i=1;i<=tot;i++) val[i]=p[i];
    29 ans=tot;
    30 }
    31 tot-=yu;
    32 }
    33 inline void dfs(int now){//标准的dfs
    34 if(now>n-1) {check();return;}
    35 if(h[now-1]<0) dfs(now+1);
    36 int last=tot,A=h[now-1],B=h[now],C=h[now+1];
    37 while(1){
    38 h[now]-=a; h[now-1]-=b;
    39 h[now+1]-=b; p[++tot]=now;
    40 if(h[now-1]<0) dfs(now+1);
    41 if((h[now-1]<0&&h[now]<0)||tot>=ans){
    42 tot=last;
    43 h[now-1]=A; h[now]=B; h[now+1]=C;
    44 break;
    45 }
    46 }
    47 }
    48 signed main(){
    49 n=read(); a=read(); b=read();
    50 for(int i=1;i<=n;i++) h[i]=read();
    51 ans=inf; tot=0;
    52 dfs(2);
    53 printf("%d
    ",ans);
    54 for(int i=1;i<=ans;i++) printf("%d ",val[i]);
    55 return 0;
    56 }
    yyy
    不随波,追随梦;不逐流,攀耸峰。不卑,补我所失;不亢,胜我所向。
  • 相关阅读:
    Codeforces 946D
    Codeforces 817F
    Codeforces 931F
    Codeforces 932D
    Graph HDU
    Chef and Graph Queries CodeChef
    Lucky Array Codeforces
    Calculation 2 HDU
    洛谷 P3455 [POI2007]ZAP-Queries || 洛谷P2522,bzoj2301
    洛谷 P2398 GCD SUM || uva11417,uva11426,uva11424,洛谷P1390,洛谷P2257,洛谷P2568
  • 原文地址:https://www.cnblogs.com/cbyyc/p/11440424.html
Copyright © 2011-2022 走看看