CF-63E - Sweets Game(记忆化搜索dp+状态压缩)

CodeForces 1247B2 - TV Subscriptions (Hard Version) 【思维】 题目链接:https://codeforces.com/problemset/problem/1247/B2 题意:就是有k种频道,现在有一个播放频道的序列,问最少需要买多少个频道使得能够连续d天看。 思路:比较简单的题目,我们只需要每次处理长度为d的区间,初始o(n)可以得到算出来需要购买的数量,然后区间右移,把左端点去掉,加上右区间端点,就可以得到一个新的答案,然后每次取最优就可以了。 ... 阅读详情

E - Sweets Game
Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Karlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and himself. Specifically, to play together a game he has just invented with the chocolates. The winner will get the cake as a reward.

The box of chocolates has the form of a hexagon. It contains 19 cells for the chocolates, some of which contain a chocolate. The players move in turns. During one move it is allowed to eat one or several chocolates that lay in the neighboring cells on one line, parallel to one of the box's sides. The picture below shows the examples of allowed moves and of an unacceptable one. The player who cannot make a move loses.

Karlsson makes the first move as he is Lillebror's guest and not vice versa. The players play optimally. Determine who will get the cake.

Input

The input data contains 5 lines, containing 19 words consisting of one symbol. The word "O" means that the cell contains a chocolate and a "." stands for an empty cell. It is guaranteed that the box contains at least one chocolate. See the examples for better understanding.

Output

If Karlsson gets the cake, print "Karlsson" (without the quotes), otherwise print "Lillebror" (yet again without the quotes).

Sample Input

Input
  . . .
 . . O .
. . O O .
 . . . .
  . . .
Output
Lillebror
Input
  . . .
 . . . O
. . . O .
 O . O .
  . O .
Output
Karlsson


思路:总共就19个字符,用二进制压缩,然后枚举记忆化搜索,很像博弈的哪种。


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int kx[]={1,1,1,2,3};///搜索范围
const int ky[]={3,4,5,5,5};
const int dx[]={1,0,1};
const int dy[]={0,1,1};
char s[55][55];
int h[1<<22];
bool ok()
{  int dex=0;
  for(int i=0;i<5;++i)///找出当前状态
    for(int j=kx[i];j<=ky[i];++j)
    {dex<<=1;
     if(s[i][j]=='O')
     dex^=1;
    }
  int&ret=h[dex];///记忆化数组
  if(ret==0)
  { ret=-1;
    for(int i=0;ret<0&&i<5;++i)
      for(int j=kx[i];ret<0&&j<=ky[i];++j)
      for(int k=0;ret<0&&k<3;++k)
      {int tx,ty;
        tx=i;ty=j;
        if(s[tx][ty]!='O')continue;
        while(s[tx][ty]=='O')
        { s[tx][ty]='.';
          tx+=dx[k];ty+=dy[k];
          if(!ok()){ret=1;break;}///只要有满足的路径到必败点就是必胜点
        }
        while(tx^i||ty^j)///未找到还原状态
        {
          tx-=dx[k];ty-=dy[k];
          s[tx][ty]='O';
        }
        s[tx][ty]='O';
      }
  }
  return ret>0;
}
int main()
{  memset(h,0,sizeof(h));
  for(int i=0;i<5;++i)
    for(int j=kx[i];j<=ky[i];++j)
    scanf(" %c",&s[i][j]);
   /** for(int i=0;i<5;++i,puts(""))
    for(int j=kx[i];j<=ky[i];++j)
    printf(" %c",s[i][j]);*/
  if(ok())cout<<"Karlsson\n";
  else cout<<"Lillebror\n";
}



Ubuntu使用cmake出现Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed 解决 Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed 阅读详情

相关推荐

VSCode终端打不开?3分钟搞定Windows下Terminal配置(附最新JSON设置方法)

本文针对Windows系统下VSCode终端无法启动的常见问题,提供了详细的诊断与解决方案。核心在于更新已弃用的旧配置,采用最新的JSON设置方法,通过定义`terminal.integrated.profiles.windows`和指定`terminal.integrated.defaultProfile.windows`,快速修复并优化终端配置,实现三分钟内恢复正常使用。

flower的专栏 741

CodeForces 63 E.Sweets Game(博弈论+dfs)

Description 给出一个六边形的糖盒,里面共191919个放糖的位置,但是初始状态可能不是所有位置都有糖,两个人轮流拿糖,每次可以拿连续的一个或多个糖,谁拿走最后一个糖谁获胜,双方都采取最优策略,问谁胜 Input 输入糖盒初始状态,OOO表示有糖 Output 输出胜者,先手胜则输出LillebrorLillebrorLillebror,后手胜则输出KarlssonKarlss...

ZSQ 498

三级等保网络拓扑图实战:从零搭建符合标准的医院安全架构

本文详细阐述了如何从零开始设计并搭建符合三级等保标准的医院网络安全架构。文章基于“一个中心,三重防护”的核心框架,深入解析了医院网络分区设计、安全域划分、关键安全设备选型与配置等实战要点,并提供了绘制专业网络拓扑图的技巧与等保测评准备指南,旨在帮助医院IT人员系统化地构建既合规又实用的纵深防御体系。

weixin_29326909的博客 504

C - Sweets Eating CodeForces - 1253C

Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer ai . Yui loves sweets, but she can eat...

qq_43708553的博客 355

Linux 之 supervisor安装和使用

运行Supervisor的后台服务,它用来启动和管理那些你需要Supervisor管理的子进程,响应客户端发来的请求,重启意外退出的子进程,将子进程的stdout和stderr写入日志,响应事件等。它是Supervisor最核心的部分。

chang995196962的博客 5545

离散数学 --- 图论基础 --- 图的同构,通路与回路,可达性与最短通路

同一个图(这里的图是抽象的数学定义)可以有不同的图形表示方法1.重数:两点之间的平行边的个数1.得到 n!的过程,一个图中的一个结点在另一个图中对应的结点有n种可能(黄框中定义的图来讨论),这个对应好后下一个结点有 n - 1 种可能,再下一个有n-2种,直到最后一个为1,所有可能的结果就等于 n * (n - 1) *(n - 2)*....*1 = n!2.虽然说找对应结点很困难,但不是没有规律可循的。比如1.两个相互对应的结点的度数要相同;

qq_51947882的博客 7440

【CodeForces 1253C --- Sweets Eating】DP

【CodeForces 1253C --- Sweets Eating】DP Description Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described b...

来日浅谈的博客 1124

Ubuntu20.04系统Cuckoo sandbox所需环境搭建及安装(超详细图文)

请勿叫我大神,我只是互联网的搬运工~ 前言 本教程以Ubuntu20桌面版作为示范,服务器版同样适用,但可能稍微麻烦一点,服务器版本的话安装Xmanage套装使用可能会相对轻松一些,由于后面会使用到vbox的使用,对vbox命令行操作不熟悉的小伙伴用xmanage可能会相对轻松一点。 提示:以下是本篇文章正文内容,下面案例可供参考 安装ubuntu20桌面版 步骤1:转到https://ubuntu.com/download/desktop下载下载.iso。 步骤2:使用您选择的虚拟机监控程序(VMWa

ElsonHY的博客 1万+

C. Sweets Eating

链接:https://codeforces.com/contest/1253/problem/C Tsumugi broughtnndelicious sweets to the Light Music Club. They are numbered from11tonn, where theii-th sweet has a sugar concentration describe...

Luoriliming的博客 344

deepfacelab下载安装及训练(小白篇),以及导出SAEHD为dfm文件,解决broken pipe问题

其中如果用的是RTX30系列显卡的话,需要把WIN10升级到20H4或更新版本,然后打开硬件加速,不然会出现训练时一直卡在第一个迭代不动了,我的服务器版本为22H2,符合。支持WIN10,win11,WIN7,LINUX,不支持mac(因为mac不支持NVIDIA显卡)

caoyongsheng的博客 3887

信道估计准则演进:从LS、MMSE到LMMSE的工程权衡

本文深入探讨了信道估计准则的演进历程,从LS、MMSE到LMMSE的工程权衡。通过对比分析三大经典算法的数学本质、工程实现及适用场景,揭示了在计算复杂度、实时性和性能之间的关键取舍。文章结合4G/5G基站项目实战经验,提供了算法选型的三维决策模型和前沿发展建议,为无线通信系统设计提供实用指导。

weixin_29327525的博客 282

Codeforces Round #600 (Div. 2) C. Sweets Eating

题目链接 C. Sweets Eating time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Tsumugi brought n delicious sweets to the Light Music Club. They are numb...

weixin_45538541的博客 386

基于YOLOv8的农作物病虫害检测系统设计与实现

国内如中国农业大学的科研团队采用改进的Faster R-CNN模型对小麦病害进行检测,取得了较好的效果。农作物病虫害是影响农业生产的重要因素之一,每年因病虫害导致的农作物减产高达20%-40%。YOLO(You Only Look Once)系列算法作为目标检测领域的代表性模型,以其高效、准确的特点在众多领域得到广泛应用。YOLOv8作为该系列的最新版本,在精度和速度上都有显著提升,非常适合农作物病虫害检测这类需要实时处理的应用场景。然而,现有研究仍存在一些不足:一是模型复杂度高,难以部署到移动设备;

YOLO 794

Sweets for Everyone!(CF-248D)

Problem Description For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! ...

Alex_McAvoy的博客 776

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

CodeForces 1253 C. Sweets Eating DP

一、内容 Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer aiYui loves sweets, but she can e...

Tizzi的博客 997

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Sweets Eating(贪心+前缀和)

Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer ai. Yui loves sweets, but she can eat ...

amazingee的博客 1368

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

eating machine=chi huo

ddd

weixin_34221112的博客 122

C. Sweets Eating cf1253(贪心)

Tsumugi brought ???? delicious sweets to the Light Music Club. They are numbered from 1 to ????, where the ????-th sweet has a sugar concentration described by an integer ????????. Yui loves sweets, but she can eat ...

tomjobs的博客 1255

C The Party and Sweets(思维 + 贪心)

题目链接 题意:n个男孩,m个女孩,第i个男孩送出的最小糖果为b[i],送给m个女孩,第i个女孩收到的最小的糖果为g[i],且b[i],g[i],全部要取到,问送出的最少糖果 题解:明显可以贪心做。 先对b[i] 和g[i]进行排序,首先n个男孩肯定要送出b[i],可以求出此时最小的一个值∑b[i] * m 。同时所有的g[i]要取到,那么便遍历一遍g[i]-b[n-1],解释:首先要取最小,先满...

Victor的博客 606

Sweets Eating

分析 一个贪心加找规律的题目,关键在于这个规律。 先考虑i和i-1之间多了什么,其实就相当于再i-1的序列的最开头插入了一个a[i],对于i-1个数集体后移,其中只有离i-m+1有m个单位距离的数对解有影响,因为它们的天数改变了,那么ans[i]=ans[i-1]+a[i]+sum[i];sum[i]表示前面说的那些数的和,sum[i]与sum[i-m]之间有关系:sum[i]=sum[i-m]+...

萌新的博客 339

C - Sweets Eating 前缀和 + 思维找规律

传送门 思路:1.找出最优策略 2.优化代码 最主要的是如何优化代码,我们发现m是一个周期,在m周期类的元素不会受到影响,一旦到达一个周期,那么此时的数值就要整体移一位,这个可以用前缀和来实现。 设dp[i]为第i天的最小惩罚,如果i > m dp[i]就会等于第i - m天在原来的二倍基础上再加当前位于m周期内的数。(这个就要用到前缀和实现)。 #include<iostream&g...

weixin_43960370的博客 608

CodeForces 1253C Sweets Eating

一共n个糖果,每天最多吃m个。糖果第d天吃的花费是a[i] * d 问你吃k块糖果的最小花费是多少。其实应该是一个贪心的思路。让糖果从大小排序然后求个前缀和就行了。 AC代码: #include <cstdio> #include <vector> #include <queue> #include <cstring> #include...

邵光亮的博客 423

Sweets Eating CodeForces - 1253C(思维+前缀和)

Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer ai. Yui loves sweets, but she can eat ...

starlet_kiss的博客 441

Codeforces Round #600 (Div. 2) C. Sweets Eating

题目链接:https://codeforces.com/contest/1253/problem/C 思路:我们可以知道值最小的糖果最后吃,所以先给糖果排个序,然后求出前缀和(隔m个数的数的前缀和,a1+a(1+m)+a(1+2*m)+.......)加进来的糖果只会影响他前m个位置的糖果,每一次后一天只需要在前一天基础加一个这个前缀和就好了, AC代码: #include<iost...

ecjtu_17_TY的博客 278
上一篇: CF-63C - Bulls and Cows(枚举)
下一篇: hdu 1556 Color the ball(线段树+懒惰标记)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值