Codeforces Gym 100379L Game with a string 博弈+交互题

交互题 Codeforces 883 div3. F 理清思路一步步实现即可。 阅读详情

题目大意:

有26堆石子,你可以选其中的若干堆取走每个选定堆中的一颗石子,没法取的人失败。你需要选择先手和后手,然后与程序交互,给出必胜的方案。

做法:

  • 我们先看只有一堆的情况,如果这一堆中的石子数为偶数,那么先手必败,反之如果是奇数,那么先手必胜;
  • 我们可以推广到26堆的情况,如果不存在奇数堆的石子那么先手必败,否则先手必胜。
  • 至此,我们得到了一个最优方案。如果不存在奇数堆的石子那么我们选则后手,否则选先手。
  • 每次将奇数堆的石子取走,使得对方面临必败状态即可。

代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
using namespace std;
char str[1000];
set<int>s[26];
int hand=2,oper[1000],os,ct;
bool get()
{
    int p;
    scanf("%d",&os);
    if(os==-1)return true;
    while(os--)
    {
        scanf("%d",&p);
        s[str[p-1]-'a'].erase(p);
    }
    return false;
}
int main()
{
    scanf("%s",str);
    int len=strlen(str);
    for(int i=0;i<len;i++)s[str[i]-'a'].insert(i+1);
    for(int i=0;i<26;i++)
        if(s[i].size()%2){hand=1;break;} //存在奇数堆选先手 
    printf("%d\n",hand);
    fflush(stdout);
    if(hand==2)get();
    while(1){
        int ct=0;
        for(int i=0;i<26;i++)
            if(s[i].size()%2)
            {
                oper[ct++]=*s[i].begin();
                s[i].erase(s[i].begin());
                //拿掉奇数堆 
            }
        printf("%d",ct);
        for(int i=0;i<ct;i++)printf(" %d",oper[i]);
        printf("\n");
        fflush(stdout);
        if(get())break;
    }
    return 0;
}
交互 Codeforces Round 1040 Interactive RBS Codeforce 交互题 好题 妙题 阅读详情

相关推荐

简单交互题选讲&交互题浅谈

文章目录一些定义与技巧一些例题例1. [CF1167B]Lost NumbersDescriptionSolution例2. [CF1407C]Chocalate BunnyDescriptionSolution例3. [CF1451E2]Bitwise QueriesDescriptionSolutionSummary例4. [CF1114E]Arithmetic ProgressionDescriptionSolutionSummary 一些定义与技巧 交互题,顾名思义,你需要用电脑与官方机器交流,从而

Cherrt的博客 5842

Codeforces Round #838 (Div. 2) D. GCD Queries (交互题)

input: output: 题目大意:有一个长度为n的序列,其为0~n-1的全排列,但是你并不知道这个排列具体是什么,现在你可以进行询问,每次询问两个数的gcd的值,最多询问2n次,最终你要确定0可能存在的位置以‘!x y’的形式输出,只要x,y的位置上有一个是0就算猜对。解题思路:每次取3个位置上的数x,y,z,然后询问ans1=gcd(x,y),ans2=gcd(y,z)的值,如果gcd(x,y)==gcd(y,z),那么我们可以确定y一定不是0,因为如果y=0,那么gcd(x,y)=x,gc

weixin_54562114的博客 450

交互题解题报告

文章目录交互格式IO交互grader交互其他注意事项交互题的本地测试准备IO交互测试grader交互测试题解猜数字2拉面比较 交互格式 交互题一般分为两种:IO交互和grader交互 IO交互 需要包含对应的交互库头文件。 一般题目会在题面定义好每种操作的格式,选手通过打印对应的字符串进行交互。 每次输出后要即时清空缓存,保证交互正常进行。 对于cout,endl时会自动清除缓存。 对于printf,可以使用**fflush(stdout)**清除缓存。 例题:猜数字2 grader交互 需要包含对应的交互

Cafard的博客 1897

Codeforces Round 930 (Div. 2)题解

我们还是想办法从这道题的特殊的地方入手,题目中给的数组是一个排列,从0到n-1的排列,那么最大的数显然是n-1,然后要找出n-1为0的哪些位置为1的数,显然两者进行|运算的值应该最大,但是如果仅仅是找或运算的话,那么n-1为1的位置,且找到的数对应位置也为1的位置的那种值如何排除呢,显然我们的目标值中1的个数最少,目标值为1的位置所有找到的值对应的位置应该也是1,但是应该比目标值大。(1<=n<=5e5)获取n的第i位是否是1,判断n>>i&1是否为1,如果为1,就说明n的第i位为1,否则就是0.

m0_74120503的博客 1188

信息学交互题的写法和注意事项总结

信息学交互题的写法和注意事项总结:交互题要求选手与“裁判”进行多次输入输出的交互,通常以多轮交互实现问题的解决。题目的核心在于:如何通过“询问”或“操作”逐步推导出答案或实现目标。

lry421308的博客 1313

sysrepo 开发者指南(一个基于libyang与支持rpc的数据库)

sysrepo 开发者指南(一个基于libyang与支持rpc的数据库) 日志记录 默认情况下,所有 Sysrepo 日志记录都处于关闭状态。如果启用,日志消息有 3 种输出。它们可以写入stderr、由 处理syslog或简单地传递给回调。 请务必注意,启用 Sysrepo 日志记录也会修改libyang日志记录设置。错误消息被视为标准 Sysrepo 错误,其他严重性较低的消息完全隐藏。要更改此行为,只需在启用 Sysrepo 日志记录后调整libyang日志记录设置。 此外,几乎每个 Sysrepo

weixin_43489394的博客 9245

Codeforces Round 930 (Div. 2)(A,B,C,D)

Codeforces Round 930 (Div. 2)(A,B,C,D)

qq_45809243的博客 1037

泛微OAe9-自定义资源看板

OA中,有一个很好用的功能:会议室预约。对于一间设立的会议室,同一时间段内,肯定会有不同的人预约同一间会议室,并且,在资源看板里,能看清各个时间段会议室的占用情况,可是会议室资源是有限的,显然不可能让多个人在同一时间段内预约同一间会议室,如会议室已占用,其他人再次申请时,应当拒绝预约。

小松鼠的博客 1862

关于交互题---Idleness limit exceeded(codeforces)

Idleness limit exceeded的中文:懒惰超过限制。----来自有道翻译 大概意思是在该输出的情况下没有输出数据 比如这个:   而且一般都会提醒你:(在每条输出之后加) After outputting each line, don't forget to flush the output. For example: fflush(stdout) in C/C++...

xuanweiace的博客 6611

手把手教你用三菱PLC控制JET伺服原点:从硬件接线到GXWORKS3程序调试

本文详细介绍了如何使用三菱PLC控制JET伺服系统实现原点回归功能,涵盖硬件接线、参数配置到GX Works3程序调试的全流程。通过实战指南,帮助工程师快速掌握伺服控制技术,提升工业自动化项目的实施效率。

weixin_30642561的博客 544

of_graph_get_remote_port

isp { compatible = "isp"; core@0 { id = <0>; ports { #address-cells = <1>; #size-cells = <0>; port@0 { reg = <0>; ...

wmzjzwlzs的专栏 1168

Codeforces Round 931 (Div. 2)题解

思路:这里的操作是异或,所以我们从二进制的角度来考虑,显然只有两者二进制位不同的时候才需要改变,每一位上如果需要变,要么是0变1,要么是1变0,对于0变1,n实际上会变大,所以我们要找一个更高位1变0来和它同步变化,否则n^x>n,就不满足要求。所以我们可以先遍历它们二进制的每一位,然后标记一下每一位,如果是1变0,标记成1,如果是0变1标记成2,然后从小往大遍历,每次当一个标记为2的位需要改变的时候,我们就往前找到一个标记为1的位和它一起变,否则如果找不到就直接退出输出-1,如此便可解决。

m0_74120503的博客 892

2021哈工大网安837考研初试经验贴

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

weixin_41797880的博客 6533

Codeforces Round 948 (Div. 2) E. Tensor(思维题-交互)

(6)否则,记las的两个父亲为f1、f2(也就是上图的点6、点7),如果能往f1后面续,就往f1后面续,否则往f2后面续。新来的点3,可以接在点4后,也可以接在点5后,也可以接在点6后,也可以接在点7后,因为在链中间的点后面续新的点,都可以看成是在交点后面续新的点,不影响两条链的性质。而此时应该是10->9->6->3->2,另一条链8->7->5->4->1。而这种情况的出现,说明前面有一个只询问了1次的点,也就是在点5下面的点4,可以发现,在点5形成Y字型,后接点4之后,新来的点3并没有续到点4上,

小衣同学的博客 1226

保姆级教程:中科蓝讯Downloader配置详解,从软硬开关机到EQ调音一步到位

本文详细介绍了中科蓝讯Downloader的配置流程,从硬件初始化到音频调优的全方位指南。涵盖软硬开关机选择、电源管理、DAC校准、EQ调音等关键步骤,帮助开发者高效完成配置并避免常见问题。特别适合需要精确控制音频设备和电源管理的中科蓝讯芯片开发者。

weixin_33670786的博客 314

Unity 编辑器篇|(一)MenuItem菜单栏

"一级菜单/二级菜单上/三级菜单""一级菜单/二级菜单中 %#_B""一级菜单/二级菜单下 %&_C""一级菜单/二级菜单中 %#_B""一级菜单/二级菜单下 %&_C""GameObject/二级菜单""CONTEXT/组件名/菜单名""一级菜单/二级菜单上 #_A""Assets/二级菜单""一级菜单/二级菜单下""一级菜单/二级菜单上""一级菜单/二级菜单中""一级菜单/二级菜单下""一级菜单/二级菜单下""一级菜单/二级菜单上""一级菜单/二级菜单中""一级菜单/二级菜单下""自定义/Test"

游戏开发小Y的博客 13万+

[交互题][二分]Codeforces#415 (Div. 1) 809B. Glad to see you!

题意戳这里题解第一次做交互题。 要求60次询问之内出结果。可以想到大概用的就是二分之类的方法。 考虑二分,每次怎么才能判断 [L,mid][L,mid] 和 [mid+1,R][mid+1,R] 哪一部分一定有点呢? 比较巧妙的办法,询问 (mid,mid+1)(mid,mid+1),就能判断离中间最近的是在哪边,往那一边走一定能找到。 题目要求的是找到两个点,我们先 get(1,n)get

Lynstery's blog 804

看懂 SAP S/4HANA 产品主数据里的 GTIN:一串号码背后的全球商品识别与业务协同

SAP S/4HANA中的GTIN管理是企业供应链运营的关键环节。本文深入解析GTIN的业务内涵及其在SAP系统中的实现方式:1) GTIN是全球通用的商品标识码,不同于企业内部物料编码;2) SAP主数据中GTIN与计量单位强绑定,需为不同包装层级维护独立GTIN;3) 同一产品可能因渠道、供应商差异存在多个GTIN;4) GTIN贯穿零售POS、仓储管理、EDI订单等核心业务流程;5) 通过典型案例说明错误维护GTIN将导致收银异常、仓库作业低效等运营问题。文章强调GTIN管理需结合包装层级、计量单位等

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1444

Codeforces Round 951 (Div. 2) F. Kostyanych‘s Theorem(思维题 交互好题)

而一直问n-1显然肯定不行,这样会导致剩下的删边越来越多,最后剩下一堆小于n-2的。还会输出一个和这个点v当前没有连边的点x,如果x有多个,也输出点号最小的x。2. 如果问出来的是n-1,n-1可以和子图内的点任意连,插入到任何地方,1. 如果问出来的是n-2,显然删掉这个点的子图还满足这个条件,递归子图。交互题,n(n

小衣同学的博客 798

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

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

D. Fixed Point Guessing——交互题+二分

Problem - D - Codeforces

m0_61094896的博客 265

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Codeforces Round 945 (Div. 2) 题解分享

Div2 945 A~D

2301_80105412的博客 2002

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CodeForces - 1698D 交互题

CodeForces - 1698D 交互题。

m0_74482218的博客 1042

【算法竞赛学习笔记】交互题入门

title : 交互题 tags : ACM,交互 date : 2022-2-11 author : Linno 交互题 通俗来讲,交互题与平时题目的输入输出反过来,是让你设计程序去向用户提出询问,由用户给出答案,并且在这基础上由程序推断出正确答案的一种形式。在下面第一道例题中会认识到交互题的基本写法。 应用cf上的话说明怎样调整输入输出: //This is an interactive problem. Remember to flush your output while communicati.

SC_Linno的博客 6349

交互题入门

纪念一下第一次A掉交互题。 インタラクティブ練習 (Interactive Sorting) B - インタラクティブ練習 (Interactive Sorting) Time Limit: 2 sec / Memory Limit: 256 MB Score : 300 points Problem Statement This is an interactive task. ...

yali_hzy的博客 2868

Codeforces Searching Local Minimum(交互题)

Searching Local Minimum This is an interactive problem. Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation a1,a2,…,an of integers 1 to n. You are asked to find any index k (1≤k≤n) which is a local minimum

weixin_46155777的博客 525

Codeforces 1305 D. Kuroni and the Celebration(交互题)

题目链接 题目大意: 这是一个交互题,一颗固定的树,题目给出所树上的边,然后我们可以询问不超过$\lfloor x /2\rfloor$次,最后输出树的根节点。 解题思路: 我们可以 ...

qq_41818939的博客 272
上一篇: Codeforces Gym 100203D Different vectors 最小表示法
下一篇: POJ 2010 Moo University - Financial Aid (优先队列/二分答案)
NKWBTB
博客等级 码龄16年 4粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址