CodeForces 455B.A Lot of Games

【生信】全基因组测序(WGS) 1、全基因组测序(WGS) 的定义 2、GWS流程 2.1准备工作——分析软件 2.2原始数据质控 2.3数据预处理 2.4变异检测 阅读详情

B. A Lot of Games

time limit per test 1 second
memory limit per test 256 megabytes

Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.

Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move.

Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him.

Input
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109).

Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn’t exceed 105. Each string of the group consists only of lowercase English letters.

Output
If the player who moves first wins, print “First”, otherwise print “Second” (without the quotes).

Examples
input1

2 3
a
b

output1

First

input2

3 1
a
b
c

output2

First

input3

1 2
ab

output3

Second

Solution

简单的博弈论问题(再加上字典树trie)
对于先手的人,判断出他能否必赢或必输
再对于后手的人,判断出他能否必赢或必输
(关于如何判断,只要树型dp一下)
如果先手的人能必赢和必输,那他可以让自己先输(k−1)(k-1)(k−1)局,最后一局赢就好
如果先手的人能必赢,但不能必输,那么现在我们就要考虑k的奇偶性,不妨设第一个人是A,第二个人是B,第一轮A先手先胜,第二轮B先手必胜,…,即第(2n−1)(2n-1)(2n−1)轮A胜,第2n2n2n轮B胜
如果先手的人不能必胜。。。(那他还怎么赢???不可能赢了啊!!!)

Code

#include <cstdio>
#include <string>
#include <iostream>
#define N 100010
#define C 26

using namespace std;
int trie[N][C], f1[N], f2[N], tot;

inline void insert(string s) {
	int len = s.size(), rt = 0;
	for (int i = 0; i < len; ++i) {
		int id = s[i] - 'a';
		if (!trie[rt][id]) trie[rt][id] = ++tot;
		rt = trie[rt][id];
	}
}

void dfs1(int rt) {
	f1[rt] = 1;
	for (int i = 0; i < C; ++i) {
		if (trie[rt][i]) {
			dfs1(trie[rt][i]);
			if (f1[trie[rt][i]]) {
				f1[rt] = 0;
				return;
			}
		}
	}
}

void dfs2(int rt) {
	bool flag = 1;
	for (int i = 0; i < C; ++i) {
		if (trie[rt][i]) {
			dfs2(trie[rt][i]);
			flag = 0;
			if (f2[trie[rt][i]]) {
				f2[rt] = 0;
				return;
			}
		}
	}
	if (flag) f2[rt] = 0;
	else f2[rt] = 1;
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		string st;
		cin >> st;
		insert(st);
	}
	dfs1(0);//求先手能不能必胜
	dfs2(0);//求先手能不能必输
	if (!f1[0]) {
		if (!f2[0]) printf("First\n");
		else {
			if (k % 2) printf("First\n");
			else printf("Second\n");
		}
	}
	else printf("Second\n");
	return 0;
}
pscad IEEE标准系统搭建说明 pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。 立即下载

相关推荐

山景BP10_128DBG开发板通过蓝牙连接手机放歌实验回顾

最近在学习上海山景公司的BP10_128DBG的开发板,因为网上关于BP10开发板的帖子也比较少,在学习的时候也没有太多的参考资料,基本上都是官方的历程。蓝牙放歌这个demo对我来说也比较复杂,特写下此博客进行记录、总结,大家有需要的可以参考。

weixin_56646002的博客 2020

Codeforces 455B A Lot of Games(博弈)

B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrew, Fedor and Alex are inventive guys.

madaidao的专栏 1064

使用 ONLYOFFICE API 构建 Java 转换器,在 Word 和 PDF 之间进行转换

随着文档处理需求的增加,格式转换成为了一个重要的需求点。由于PDF格式具有跨平台、不易被篡改的特性,将Word格式(.docx)转换为PDF格式(.pdf)的需求尤为强烈。ONLYOFFICE作为一个强大的办公套件,提供了这样的转换功能,使得用户可以轻松地在Word和PDF之间进行转换。

ONLYOFFICE的官方博客 4570

Codeforces #260 (Div. 1) B. A Lot of Games(数据结构:trie+DFS)

B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrew, Fedor and Alex are inventive guys.

小华在努力~ 778

【算法实战】Keystone变换:从原理到MATLAB实现的距离走动校正

本文深入解析Keystone变换在雷达信号处理中的距离走动校正应用,从原理到MATLAB实现全面讲解。通过三种实现方法(DFT+IFFT、Sinc插值、Chirp-Z变换)的对比分析,结合实战案例展示如何有效解决高速目标导致的距离单元跨越问题,提升多普勒频谱聚焦质量。

weixin_29055699的博客 294

软考高级信息系统项目管理师系列论文之:百篇软考高级信息系统项目管理师论文范文

软考高级信息系统项目管理师系列论文之:百篇软考高级信息系统项目管理师论文范文

zhengzaifeidelushang的博客 3579

Codeforces 455B

题目链接:http://codeforces.com/problemset/problem/455/B 题意:给出N个字符串,有2名选手,s一开始是个空串,每回合轮流往里面填字母,使得s为N个字符串其中一个的字串,若不能再往里面填字母则输,输了的下回合先手,问最后一回合谁赢 思路:完全不会……参考了别人的题解,先用字典树保存N个字符串,在用深搜索把每一个节点的状态标记,状态

csdn364988181的博客 783

踩坑2周总结:Python+YOLO26搭建工业级多路视频分析应用,从单路卡顿到16路4K稳跑30FPS

本文分享了工业级多路视频分析系统的实战经验,针对智慧物流园区的车辆违停和人员安全监测需求,提出了一套完整的解决方案。作者通过踩坑实践,总结出多路视频分析的四大核心痛点:视频流解码瓶颈、推理调度混乱、内存占用爆炸和部署兼容性差。 文章详细介绍了技术选型方案,推荐使用FFmpeg+PyAV进行硬件加速解码、YOLO26+TensorRT INT8量化推理、单进程多线程的生产者-消费者架构,以及内存池复用等技术组合。该方案在RTX 4070 Ti上实现了16路4K视频30FPS稳定运行,GPU利用率达85%以上,

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 955

CF455B A Lot of Games(字典树+树上博弈)

题意翻译 Andrew,Fedor和Alex是三个善于创造的人。现在,他们发明了一种字符串双人游戏。 给出n个非空字符串。在游戏中,两位玩家一起建造一个单词。开始时,单词是一个空字符串。两位玩家轮流操作。一位玩家在他的回合中,必须在单词的后面添加一个字母,使得添加后的单词是n个字符串中至少一个的前缀。当一位玩家不能操作时,他就输掉了游戏。 Andrew和Alex决定玩k次。上一局的负者是下一...

sher杨的博客 467

Vue 前端导出页面A4大小pdf,Vue前端导出pdf自动切割换页不切割内容 Vue导出页面pdf自动分页和添加页码 导出的pdf提高清晰度

【代码】Vue 前端导出页面A4大小pdf,Vue前端导出pdf自动切割换页不切割内容 Vue导出页面pdf自动分页和添加页码 导出的pdf提高清晰度。

weixin_41346436的博客 1799

工业视觉实战:用摄像头+AI高精度测量钢板尺寸(附深度分析)

摘要: 钢铁制造业正加速采用基于摄像头与深度学习的视觉测量技术,以取代传统人工测量,实现钢板长、宽、高(厚)的非接触、高精度在线检测。核心方案包括单目视觉(低成本但受限于变形)、双目/多目立体视觉(可精确测量变形钢板)及3D激光扫描(微米级精度)。系统精度受硬件(相机分辨率、镜头)、算法(亚像素技术)及环境稳定性共同影响,综合精度可达±0.1mm。实战中需重点解决热膨胀(需红外测温实时补偿)和钢板变形(必须采用三维方案)两大挑战,并通过工程化设计(散热、防振)确保系统可靠运行。该技术需融合光学、机械与算法,

数字人生 391

codeforces 455B A Lot of Games

题目Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.Given a group of n non-empty strings. During the game two players build the word together, initially t

LazyCrazyCat的博客 539

s8654

The official Snapdragon Ride SX 4.0 development board provides standardized hardware support for the secondary development and functional verification of the s8654 platform.

qq_39257814的博客 6830

codeforces 455B. A Lot of Games

B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrew, Fedor and Alex are inventive guys.

t_xliang的专栏 776

深度学习工具包 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")

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Codeforces 455B A Lot of Games(字典树+博弈)

题目连接: Codeforces 455B A Lot of Games 题目大意:给定n,表示字符串集合。给定k,表示进行了k次游戏,然后是n个字符串。每局开始,字符串为空串,然后两人轮流在末尾追加字符,保证新的字符串为集合中某字符串的前缀,不能操作者输,新一轮由上一句输的人先手。 解题思路:首先对字符集合建立字典树,然后根据博弈的必胜必败性质搜索出先手的决策状态,可决定胜败3,只能

不慌不忙、不急不躁 2200

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

CodeForces 455B A Lot of Games

题目链接:http://codeforces.com/problemset/problem/455/B 题意:两个人玩游戏,给n个字符串,两个人轮流选一个字母加到字符串后面,一开始字符串是空的,而且加完后当前字符串必须是字符串集合中一个字符串的前缀,谁无法再添加字符串谁就输了,他们玩k局这个游戏,上一局输的人下一局先手,问第一局的先手必胜还是后手必胜。 思路:首先建一个trie

DS-K的博客 393

假人有限元模型

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

CodeForces 455B A Lot of Games (博弈论)

A Lot of Games 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/J Description Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a ...

dituonian8372的博客 175

Codeforces 455B A Lot of Games

http://codeforces.com/contest/455/problem/B 题目大意: 给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符串是给定的任意一个字符串的前缀,不能操作时为输,赢得第k次比赛的人会取得最终的胜利,问两人都采取最优策略的情况下,谁会赢得比赛。 思路: 00代表无法控制,10代表胜,01代表必败,11代表能...

weixin_34253126的博客 158

Codeforces 455B A Lot of Games:博弈dp【多局游戏】

题目链接:http://codeforces.com/problemset/problem/455/B 题意:   给你n个字符串,然后进行k局游戏。   每局游戏开始有一个空串,然后双方轮流给这个串的末尾添加字符,并保证新字符串是n个字符串中至少一个串的前缀。   当一方不能添加字符时,这一方输,游戏结束。   每场游戏结束后,这场游戏输的人会成为下一句游戏的先手。   谁...

a1392136的博客 180

【字典树+dp】 codeforces 455B A Lot of Games

00 代表不能控制 01代表bai

yysys 787

CodeForces 455B A Lot of Games 字典树 博弈

给定n个字符串,进行k次游戏,每次游戏初始字符串为空串,两人轮流向新字符串末尾加1个字符且新串必须为n个字符串中的某个的前缀,不能操作的人输。 第i次游戏输的为第i+1次游戏的先手,最后一句赢者胜,求第1次游戏先手是否必胜。 前缀->字典树->判断博弈状态。 对每次游戏有4个状态: 先手可决定胜败,后手可决定胜败,先手必胜,后手必胜。 必胜表示2人轮流胜。 可决定成败表示输k-1次并最

とある黄鱼のOIブログ 775

Codeforces 455B A Lot of Games 字典树上博弈

题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串添加一个小写字母使得加完后的字符串不是n个字符串的前缀。 输家下一轮先手 问是先手必胜还是后手必胜 思路: 对于第一局游戏,若先手能到达必败态和必胜态,则先手会一直输到倒数第二局然后最后一局必胜 所以此时是first 若先手是必胜态或者是必败态,则是轮流赢,跟k的奇偶有关 #inclu

九野的博客 1618

Codeforces455 B. A Lot of Games(DAG上博弈,字典树上dfs)

题意: 给定n个字符串,一开始有一个空串。 两个人轮流操作,每次操作将一个字符加到空串后面,要求加入新字符之后串必须是某个串的前缀。 最后不能进行操作的人输。 总共进行k次比赛,第k次比赛输的人才是真的输。 第x次比赛输的人在第x+1次比赛作为先手。 问最后谁赢。 数据范围:n<=1e5,k<=1e9 解法: 每个前缀对自己的下一个前缀建有向边,那么这个博弈就是DAG上博弈 但是暴力建边会出现重复边,因为是前缀所以想到字典树,那么问题就变成字典树上的DAG博弈了。 因为: 总共进行k次比赛,第k

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 253
上一篇: k次方幂的和
下一篇: spoj GSS1.区间最大子段和(线段树)
北路人
博客等级 码龄9年 21粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值