CF-48E. Ivan the Fool VS Gorynych the Dragon(bfs+dfs+判重回路)

全局最小割 一个无向连通网络,去掉一个边集可以使其变成两个连通分量则这个边集就是割集;最小割集当然就权和最小的割集。 可以用最小切割最大流定理: 1.min=MAXINT,确定一个源点 2.枚举汇点 3.计算最大流,并确定当前源汇的最小割集,若比min小更新min 4.转到2直到枚举完毕 5.min即为所求输出min     不难看出复杂度很高:枚举汇点要O(n),最 阅读详情

E. Ivan the Fool VS Gorynych the Dragon
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Once upon a time in a kingdom far, far away… Okay, let’s start at the point where Ivan the Fool met Gorynych the Dragon. Ivan took out his magic sword and the battle began. First Gorynych had h heads and t tails. With each strike of the sword Ivan can either cut off several heads (from 1 to n, but not more than Gorynych has at the moment), or several tails (from 1 to m, but not more than Gorynych has at the moment). At the same time, horrible though it seems, Gorynych the Dragon can also grow new heads and tails. And the number of growing heads and tails is determined uniquely by the number of heads or tails cut by the current strike. When the total number of heads and tails exceeds R, Gorynych the Dragon strikes its final blow and destroys Ivan the Fool. That’s why Ivan aims to cut off all the dragon’s heads and tails as quickly as possible and win. The events can also develop in a third way: neither of the opponents can win over the other one and they will continue fighting forever.

The tale goes like this; easy to say, hard to do. Your task is to write a program that will determine the battle’s outcome. Consider that Ivan strikes consecutively. After each blow Gorynych grows a number of new heads and tails depending on the number of cut ones. Gorynych the Dragon is defeated if after the blow he loses all his heads and tails and can’t grow new ones. Ivan fights in the optimal way (fools are lucky), i.e.

  • if Ivan can win, he wins having struck the least number of blows;
  • if it is impossible to defeat Gorynych, but is possible to resist him for an infinitely long period of time, then that’s the strategy Ivan chooses;
  • if Gorynych wins in any case, Ivan aims to resist him for as long as possible.

Input

The first line contains three integers h, t and R (0 ≤ h, t, R ≤ 200, 0 < h + t ≤ R) which represent the initial numbers of Gorynych’s heads and tails and the largest total number of heads and tails with which Gorynych the Dragon does not yet attack. The next line contains integer n (1 ≤ n ≤ 200). The next n contain pairs of non-negative numbers "hi ti" which represent the number of heads and the number of tails correspondingly, that will grow if Gorynych has i heads (1 ≤ i ≤ n) cut. The next line contains an integer m (1 ≤ m ≤ 200) and then — the description of Gorynych’s behavior when his tails are cut off in the format identical to the one described above. All the numbers in the input file do not exceed 200.

Output

Print "Ivan" (without quotes) in the first line if Ivan wins, or "Zmey" (that means a dragon in Russian) if Gorynych the Dragon wins. In the second line print a single integer which represents the number of blows Ivan makes. If the battle will continue forever, print in the first line "Draw".

Sample test(s)
input
2 2 4
2
1 0
0 1
3
0 1
0 1
0 0
output
Ivan
2
input
2 2 4
1
0 1
1
1 0
output
Draw
input
2 2 5
1
1 1
1
3 0
output
Zmey
2

思路:本题数据最多就两百,因此可以使用广搜出猎人斩龙的最佳路数,如果猎人无法斩龙,那就深搜判断是否组成回路,从而形成永久的对战模式,还是不行那就更新猎人最终成为龙的食物的最大路数。


#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int mm=250;
const int oo=1e9;
int vis[mm][mm];
bool yes;
int h,t,r,n,m;
class node
{
  public:int h,t,c;
}hh[mm],tt[mm];
queue<node >q,p;
int dfs(int x,int y)
{ int&ret=vis[x][y];
  int tx,ty;
  if(x+y>r)return 0;
  if(vis[x][y]==-2)
  {
    yes=1;return 0;
  }
  else if(vis[x][y]==-1)
  {
    ret=-2;int dd=-oo,z;
    int bbs;
    bbs=n<x?n:x;
    for(int i=0;i<bbs;i++)
      {
        tx=x+hh[i].h-i-1;ty=y+hh[i].t;
        z=dfs(tx,ty)+1;
        dd=dd>z?dd:z;
      }
      bbs=m<y?m:y;
      for(int i=0;i<bbs;i++)
      {
        tx=x+tt[i].h;ty=y+tt[i].t-i-1;
        z=dfs(tx,ty)+1;
        dd=dd>z?dd:z;
      }
      ret=dd;
  }
  return ret;
}
int main()
{
  while(cin>>h>>t>>r)
  {
    cin>>n;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
    {
      cin>>hh[i].h>>hh[i].t;
    }
    cin>>m;
    for(int j=0;j<m;j++)
    {
      cin>>tt[j].h>>tt[j].t;
    }
    vis[h][t]=1;
     int x,y,zz;
     while(!q.empty())q.pop();
     node z,p;yes=0;
     z.h=h;z.t=t;z.c=0;
     q.push(z);
     while(!q.empty()&&!yes)
     { z=q.front();q.pop();
      int bbs=n<z.h?n:z.h;
      for(int j=0;j<bbs;j++)
      {
        x=z.h+hh[j].h-j-1;y=z.t+hh[j].t;
        if(x+y>r)continue;
        if(!vis[x][y])
        {vis[x][y]=1;
         p.h=x;p.t=y;p.c=z.c+1;
         if(x==0&&y==0)
          { cout<<"Ivan\n"<<p.c<<"\n";yes=1;
            break;
          }
         ///if(x+y>r&&d>z.c){d=z.c;continue;}
         q.push(p);
        }
      }
      bbs=m<z.t?m:z.t;
      for(int j=0;j<bbs;j++)
      {
        x=z.h+tt[j].h;y=z.t+tt[j].t-j-1;
        if(x+y>r)continue;
        if(!vis[x][y])
        {vis[x][y]=1;
         p.h=x;p.t=y;p.c=z.c+1;
         if(x==0&&y==0)
          { cout<<"Ivan\n"<<p.c<<"\n";yes=1;
            break;
          }
         ///if(x+y>r&&d>z.c){d=z.c;continue;}
         q.push(p);
        }
      }
    }
    if(yes)continue;
    memset(vis,-1,sizeof(vis));
    int ans=dfs(h,t);
    if(yes)cout<<"Draw\n";
    else cout<<"Zmey\n"<<ans<<"\n";
  }
}



隔离型全桥LLC谐振变化器建模及参数设计资料【仿真+设计报告+计算书】 内容概要:本文档系统性地提供了隔离型全桥LLC谐振变换器的建模、仿真与参数设计全套技术资料,涵盖Simulink/Plecs仿真模型、详细设计报告及Mathcad计算书,内容涉及开环与闭环控制、软启动过程、恒压恒流双闭环竞争控制等多种工况。资料还拓展至多相交错LLC、双向CLLC拓扑以及V2G(Vehicle-to-Grid)电动汽车充放电等前沿应用场景,并融合状态估计算法(如卡尔曼滤波、扩展卡尔曼滤波、粒子滤波)与神经网络技术进行系统性能优化,配套PPT说明与高水平EI期刊复现案例,为电力电子领域的科研与工程设计提供完整的技术支撑; 适合人群:适用于电力电子、电气工程及其自动化等相关专业的高校研究生、科研人员,以及从事高频DC-DC变换器、新能源电源系统开发的工程师,具备扎实电路理论基础和Matlab/Simulink仿真能力者尤佳; 使用场景及目标:①支撑LLC谐振变换器相关的科研课题、学位论文或项目开发;②开展高频高效电源的参数设计、效率优化与动态响应分析;③学习并复现高水平期刊中先进的控制策略,如变频控制、混合移相控制及智能优化算法;④掌握Simulink/Matlab在电力电子系统建模、控制算法实现与状态估计中的综合应用; 阅读建议:建议结合仿真模型、Mathcad计算书与设计报告三位一体同步研习,重点理解主电路参数设计与闭环控制逻辑之间的耦合关系,优先运行典型算例并调试关键模块,有条件者可进一步推进至硬件原型验证,并积极探索状态估计与人工智能算法在电力系统动态建模中的融合应用。 立即下载

相关推荐

实测iOS和安卓大不同!用NFC触发小程序跳转的完整避坑指南(含NFC Tools配置)

本文深入解析iOS与安卓在NFC触发小程序跳转时的核心差异,提供微信与支付宝小程序的NFC实现方案及优化技巧。涵盖跨平台兼容性测试方法论、性能优化策略及异常处理方案,帮助开发者避开常见陷阱,提升跳转成功率。特别针对NFC Tools配置和微信Universal Link使用进行详细指导。

asdfghjkl978564的博客 434

CodeForces 48 E.Ivan the Fool VS Gorynych the Dragon(SPFA+dfs)

Description 怪兽初始状态有hhh个头,ttt个尾巴,一个勇士要杀掉怪兽,他一次可以砍掉怪兽的iii个头(1≤i≤n)(1≤i≤n)(1\le i\le n)或者砍掉怪兽的jjj个尾巴(1≤j≤m)(1≤j≤m)(1\le j\le m),如果砍掉怪兽的iii个头怪兽会长出来aiaia_i个头和bibib_i个尾巴,砍掉怪兽的jjj个尾巴怪兽会长出来cicic_i个头和didid_i个...

ZSQ 540

图灵奖:计算机科学领域的诺贝尔奖

最后,图灵奖也是计算机科学领域发展的重要推动力之一,它促进了该领域的进步和繁荣。图灵奖作为计算机科学领域的诺贝尔奖,不仅是对获奖者卓越贡献的肯定,更是对整个计算机科学领域的推动和激励。在未来的发展中,我们期待看到更多的科学家和团队在图灵奖的激励下不断取得新的突破和创新成果为计算机科学的发展注入新的活力和动力。Vinton G. Cerf和Robert E. Kahn:2004年图灵奖得主,由于他们在互联网方面开创性的工作而获奖,这包括设计和实现了互联网的基础通讯协议TCP/IP,以及在网络方面的卓越领导。

wangnvshibeib的博客 2626

CF1248C Ivan the Fool and the Probability Theory(计数DP+思维)

传送门 思路: 由题意可知:相邻两行要么相同,要么相反; 假设上述命题为假命题, 那么一定存在a[ i ][ j ] != a[ i ][ j+1 ] , a[ i+1 ][ j ] == a[ i+1 ][ j+1 ] ; 由于要么为黑、要么为白(每个格子只有两种状态) 则这四个格子中一定有一个格子有两个相同颜色的相邻格子, 与题目要求矛盾, 因此上述命题为真命题; 得证。 分析一下第一行的情况...

weixin_43670649的博客 292

LaTeX伪代码字体大小调整全攻略:从algorithm到algorithm2e的实战技巧

本文详细介绍了在LaTeX中调整伪代码字体大小的全面技巧,涵盖algorithm、algorithmicx和algorithm2e等主流算法包的使用方法。从基础命令到高级配置,帮助用户解决学术论文和技术文档中的伪代码排版问题,提升算法展示的专业性和可读性。特别针对不同期刊格式要求,提供了实用的字体调整方案。

weixin_29297127的博客 437

『n8n』初识界面

在首页(Overview),我们和 n8n 最常打交道的是“Workflows”、“Credentials”、“Executions”这几个面板(其实后面2个也会用到,但初学阶段可以先不管)。Workflows 面板可以看到我们创建的所有工作流,所以要给工作流起一个一眼看上去就知道是干嘛的名字。

weixin_39415598的博客 1459

Codeforces Round #594 (Div. 2) C. Ivan the Fool and the Probability Theory (dp 思维)

C. Ivan the Fool and the Probability Theory time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Recently Ivan the Fool decided to beco...

henucm的博客 630

Halcon实战:5分钟搞定线序颜色检测(附完整代码解析)

本文详细介绍了如何使用Halcon在5分钟内实现工业级线序颜色检测的高效方案。通过机器视觉技术,结合实战项目经验,提供完整的代码解析和优化技巧,帮助开发者快速构建鲁棒性强、准确率高的检测系统,适用于电子制造和汽车线束等行业。

weixin_29098367的博客 440

uva 10917 Walk Through the Forest(最短路+DP路径,4级)

Description Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he lik

nealgavin的专栏 2130

自动化测试-自愈技术

随着人工智能的发展,作为一名软件测试工程师,相信大家都会思考如何把这一前沿技术引入到我们的自动化测试当中,想一万遍不如做一遍。,传递当前页面状态,获取之前成功的定位器路径,比较它们,并生成修复的定位器列表。如果修复成功,我们可以使用 Healenium Idea 插件更新我们的自动化测试代码:插件使用修复定位器寻找修复和更新测试代码。的旧定位器去定位按钮的时候,脚本就会报错,提示 “NoSuchElement”的错误异常。现在,我们假设开发人员变更了应用程序的UI界面,改变了这个按钮的id属性,从。

qq_58223744的博客 2660

从零搭建无人机仿真环境:ROS 2与Gazebo Fortress实战指南

本文提供了一份详细的无人机仿真环境搭建实战指南,基于Ubuntu 22.04系统,整合ROS 2 Humble与Gazebo Fortress两大核心工具。通过分步讲解安装、配置及桥接过程,并引入PX4飞控与XTDrone2工具链,帮助开发者快速构建一个稳定、高效的无人机算法开发与测试平台,有效降低真机测试的成本与风险。

water的专栏 428

CF-29C - Mail Stamps(DFS+离散化)

C - Mail Stamps Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 29C Description

nealgavin的专栏 1707

[Dify实战] 合同审阅助手:识别风险条款、生成修改建议-带绑定资源

摘要: Dify合同审阅助手通过AI技术提升合同审阅效率,快速识别风险条款并输出结构化修改建议。方案包括合同输入、关键条款识别、风险评级和报告生成流程,重点关注付款、责任限制等核心条款。采用分层风险分级(高/中/低)和"红线清单"机制,确保审阅标准化。实施建议先建立条款库和模板,通过样本测试优化模型,定期更新规则库。该方案可缩短审阅时间50%以上,提高风险识别准确率,最终实现法务经验的可复用沉淀。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 596

hdu 4756 Install Air Conditioning(MST+全边次小树,4级)

Install Air Conditioning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 174    Accepted Submission(s): 23 Problem Description   

nealgavin的专栏 1443

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

hdu 4650 Minimum Average Weight Path(最短路,5级)

第4场多校联合训练解题报告——详见杭电ACM微博~ Minimum Average Weight Path Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 94    Accepted Submissio

nealgavin的专栏 1389

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

UVA1416 Warfare And Logistics(LA4080)(最短路,5级)

Description The army of United Nations launched a new wave of air strikes on terrorist forces. The objective of the mission is to reduce enemy's logistical mobility. Each air strike will destro

nealgavin的专栏 1342

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

HDU 1068 Girls and Boys(二分图最大独立点集,3级)

Girls and Boys Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status   Appoint description:  System Crawler  (2012-10-30) Description the secon

nealgavin的专栏 1229

uva 1364 - Knights of the Round Table(点双连通分量,5级)

Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising tha

nealgavin的专栏 1224

ZOJ 3780 Paint the Grid Again(topsort)

ZOJ Problem Set - 3780 Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black

nealgavin的专栏 1209

10054 - The Necklace(欧拉回路+DFS,2级)

Problem D: The Necklace  My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure belo

nealgavin的专栏 1184

hdu 4725 The Shortest Path in Nya Graph(堆+dij,最短路,5级)

The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 193    Accepted Submission(s): 38 Problem Description Th

nealgavin的专栏 1167

hdu 4685 Prince and Princess(最大匹配+强连通所点,5级)

Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 248    Accepted Submission(s): 76 Problem Description There are n p

nealgavin的专栏 1149

uva 11374 Airport Express(最短路dijistra+堆优化,4级)

Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. The

nealgavin的专栏 1124

uva 1423 - Guess (topsort,4级)

Given a sequence of integers, a1, a2,..., an , we define its sign matrix S such that, for 1ijn , Sij = `` + " if ai +...+ aj > 0 ; Sij = `` - " if ai +...+ aj  ; and Sij = ``0" otherwise. For exa

nealgavin的专栏 1121

hdu 4679 Terrorist’s destroy (DP or 树直径,4级)

Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 132    Accepted Submission(s): 20 Problem Description There is a ci

nealgavin的专栏 1068
上一篇: LS 22 Longest path on DAG(最短路+SPFA)
下一篇: LS 24 Bracket sequence(DP)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值