#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
struct Key{
int num;
char ch[4];
};
const Key keys[10] = {
{}, {}, {3, {'a', 'b', 'c'}}, {3, {'d', 'e', 'f'}},
{3, {'g','h','i'}}, {3, {'j', 'k', 'l'}}, {3, {'m','n','o'}},
{4, {'p', 'q','r', 's'}}, {3, { 't', 'u', 'v'}}, {4,{'w', 'x','y','z'}}
};
void printKeyBoard()
{
for (int i = 2; i < 10; i++)
{
cout<<"Key "<<i<<":";
for (int j = 0; j < keys[i].num; j++)
cout<<keys[i].ch[j];
cout<<endl;
}
}
struct MyWord{
char s[101];
int len;
int freq;
bool prefix;
};
MyWord word[1001];
int tFreq[1001];
int nWords;
inline void readScenario()
{
cin>>nWords;
for (int i = 0; i < nWords; i++)
{
cin>>word[i].s>>word[i].freq;
word[i].len = strlen(word[i].s);
}
}
inline void markWords(char qry[], int n)
{
for (int i = 0; i < nWords; i++)
{
if (!word[i].prefix ) continue;
else if (word[i].len < n) { word[i].prefix = false; continue; }
int k;
for (k = 0; k < keys[qry[n-1]].num; k++)
if (keys[qry[n-1]].ch[k] == word[i].s[n-1]) break;
word[i].prefix = k<keys[qry[n-1]].num;
}
}
inline void mostFreqStr(char qry[], int n, char* s)
{
markWords(qry, n);
for (int i = 0; i < nWords; i++)
{
tFreq[i] = 0;
if ( !word[i].prefix ) continue;
for (int j = 0; j < nWords; j++)
if (word[j].prefix && 0 == strncmp(word[i].s, word[j].s, n))
tFreq[i] += word[j].freq;
}
int idx = -1, max = -1;
for(int i = 0; i < nWords; i++)
if (word[i].prefix && max < tFreq[i]) { idx = i; max = tFreq[i]; }
if (max == -1)
{
strcpy(s, "MANUALLY/0");
return ;
}
strncpy(s, word[idx].s, n);
s[n] = '/0';
return ;
}
int main()
{
//printKeyBoard();
int t;// test cases
int n; //Num of query strings
char query[101]; char s[101];
cin>>t;
for (int k = 1; k <= t; k++)
{
cout<<"Scenario #"<<k<<":"<<endl;
readScenario();
cin>>n;
for (int i = 0; i < n; i++)
{
int j;
for (j = 0; j < nWords; j++) word[j].prefix = true;
j = 0;
while (cin>>query[j], query[j] -= '0', query[j++] != 1)
{
mostFreqStr(query, j, s);
cout<<s<<endl;
}
cout<<endl;
}
cout<<endl;
}
}
相关推荐
ROS2前置基础教程 | 小鱼教你用CMake依赖查找流程
上面我们用g++、make、cmake三种方式来编译ros2的C++节点。用cmake虽然成功了,但是CMakeLists.txt的内容依然非常的臃肿,我们需要将其进一步的简化。将上面的CmakLists.txt改成下面的样子 接着继续生成和编译 是不是非常的神奇,为什么可以浓缩成那么短的几句指令呢?find_package查找路径对应的环境变量如下。 打开终端,输入指令: 结果 观察PATH变量,你会发现赫然在其中,中的路径如果以或结尾,则自动回退到上一级目录,接着检查这些目录下的 cmake找到这些目录
ZOJ1038
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1038 同样,抄答案。 整体思路就是按照按键的顺序,构造出一些单词,如果构造出的单词是词典中的单词或者是词典中某些单词的前缀,那么久把构造出的新单词保存到words数组里,当接收到下一个按键时,就从words中枚举每一个单词,与所按得数字键上的所有字母逐一配对,
Xilinx系列学习(一) BRAM的使用,并用PL读取BRAM数据
Xilinx系列学习(一) BRAM的使用,并用PL读取BRAM数据一,Xilinx BRAM介绍二,BRAM对应的IP核调用和使用1,BRAM对应的IP核介绍2,BMG例化IP核的调用 一,Xilinx BRAM介绍 BRAM 就是Block Memory,是Zynq的PL端的存储RAM单元。可以利用BRAM,在PS和PL之间进行数据的交换。Zynq中还有一类存储器,称为分布式随机访问存储器(D...
zoj 1038 T9
题目很简单,意思也很明显。不过感觉这个题过的很顺,代码也还算简单。 #include #include #include #include #include #include #define pb push_back using namespace std; vector vec[12]; struct Node { string s; int p; N
VOWIFI--相关的协议文档
一、3GPP相关协议文档 3GPP 23.402 Architecture enhancements for non-3GPP accesse- //重要 整体框架结构和流程,3GPP和NON-3GPP切换 3GPP 36.304 User Equipment (UE) procedures in idle mode //重要,终端在空闲状态下3GPP与NON-3GPP之间的重选方法 3GP
Jenkins离线安装保姆级教程:从下载.war包到SVN+Maven项目一键部署(附避坑脚本)
本文详细介绍了Jenkins离线安装的全流程,包括.war包下载、SVN+Maven项目配置及自动化部署。特别针对内网环境提供解决方案,涵盖插件管理、开发工具链配置、构建触发器和SSH部署等关键步骤,帮助企业在网络隔离环境下实现高效持续集成。
ZOJ 1038 - T9
用的是map,把相同前缀的词的概率加到一个map里面,找出里面的概率最大的,然后在相同的最大概率中找出字典序最小的. #include #include #include #include #include #include using namespace std; const int b[10][4]={{0},{0},{'a','b','c'},{'d','e','f'},{
从零到一:基于Esp32与LVGL的ST7789屏幕驱动全流程实战
本文详细介绍了基于Esp32与LVGL的ST7789屏幕驱动全流程实战,包括环境准备、驱动文件改造、硬件接口配置、LVGL集成与优化等关键步骤。通过VSCode+ESP-IDF开发环境,读者可以快速掌握SPI模式下的屏幕驱动开发,解决常见问题如颜色错乱、画面撕裂等,并实现LVGL的高效集成与性能优化。
1038
#include #include using namespace std; bool input(double& sum) { sum = 0; int count = -1; cin>>count; if(count==0) return false; double tmp; for(int i=0;i<count;i++) { cin>>tmp; sum +=
17|CI/CD 集成与质量门禁:让精准测试进入发布流水线
本文讲解精准测试如何接入 CI/CD 流水线,并通过质量门禁辅助发布决策。测试开发工程师。Java 后端开发工程师。质量平台 / DevOps 平台建设者。想了解精准测试落地方法的技术负责人。
Java语音革命:用代码打造永不疲倦的AI客服,让客户支持效率飙升300%!
客户支持领域常面临“薛定谔困境”,即无法预知客户来电的意图是投诉还是表扬。通过Java技术,尤其是语音识别和自然语言处理(NLP),可以有效解决这一问题。文章展示了如何利用Java代码构建“声纹量子引擎”,实现客户支持的自动化。核心技术包括录音与预处理、语音识别和语义理解。通过百度AI API和Stanford NLP,系统能够快速、准确地识别客户语音并理解其意图。数据表明,优化后的AI处理时间从15分钟缩短至18秒,语音识别准确率提升至98.5%,并发处理能力达到单实例1000+请求。这些技术显著提升了客
ZOJ-1038
高效的做法应该是用前权能
各大OJ题目分类
登录| 注册 ACM/ICPC专栏各大OJ近期比赛列表各大OJ题目分类负责任的OJ搜索 POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006POJ1008POJ1013POJ1016POJ1017POJ1169POJ1298POJ1326POJ1350P
pscad IEEE标准系统搭建说明
pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
[FZYZOJ 1038] 隧道
P1038 -- 隧道 时间限制:1000MS 内存限制:65536KB Description 一座小镇正在着手建造自己的地铁线路网。小镇坐落在许多小岛上,小岛之间通过隧道或者桥梁连接。地铁就在这些已有的桥梁和隧道的基础上建成。由于地铁主要是在地下,所以桥梁用得越少越好。小镇的居民希望能够仅通过地铁就能在任意两座小岛之间往返旅行。幸运的是,我们有足够多的隧道和桥梁来满足这个要求,...
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
ZOJ Problem Set - 1038 T9
中等难度的字典树。 用到的是DFS+优先队列的方法。比较容易实现,但是效率不太高~ 10ms。(cin,cout); 首先,插入,每个节点要其记录权值。然后DFS每个点,push入队列,对 #include #include #include #include #include #include #include #include #include #include u
win10 跳过U8环境检测的IE WebControls.rar
win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。
bzoj1038 [ ZJOI2008 ] -- 模拟退火+二分
这题正解是半平面交,但可以用模拟退火水过。。。 用模拟退火求x的值,然后二分求y的值就可以了。 当所有端点到这个点的直线按逆时针顺序时这个点可以看到任何位置。 代码: 1 #include<iostream> 2 #include<cstdlib> 3 #include<cstring> 4 #include<...
S - T9
Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u [Submit] [Go Back] [Status] Description
zoj 1011NTA
//#include #include #define MAXN 15 #define MAXK 10#define MAXL 10using namespace std;int m, n, k;struct mypair{ int a, b; mypair *next;
zoj 1028 Flip and Shift
/**证明: 首先, 若n为奇数,则必然可以完成任务 将n个球遍号为1,2,...,n 若从1位置开始,进行 n-1次连续的 (flip, shift, shift), 则 除了球1外, 所有球的位置都 减了2, 而球1最后到达原来球n-1的位置。(见图, 可以知道, 相当于交换球1和2的位置)
计算 高次幂相对某个模数的余( (a ^ n)mod p, n 很大 )
在做google codejam 2008 round 1A problem C 的 时候, 从别人代码里学到的 假如 要计算 (a ^ n) , n很大, 直接计算的话, 是个 O(n)的方法有 O(log (n))的方法,如下: 把n表示成2进制, n = n0 * 1 + n1 * 2 + n2 * 4 + ... + nk * (2^k)则 a^n =[
POJ1097 Roads Scholar
#include #include #include #include using namespace std;const int MAXN = 30;const int MAXDIST = 100000000;int distanc[MAXN][MAXN];//从交点a到b的最短距离 int dist[MAXN][MAXN];//从
zoj1155 triangle war
/**DP 对状态编号, 18条边, 每条边可能实线, 也可能虚线, 有2^18种MaxScore(x) = max { StepScore(rCode, selectedEdgeNum) > 0 ? StepScore + MaxScore(rCode) //选择的边成三角行
zoj 1166 Anagram Checker
/**A seach problem.**/#include #include #include #include #include using namespace std;/**dictionary words**/string word[2000];/**Word in phrase**/string swo
ZOJ 1102 Phylogenetic Trees Inherited (My algorithm , Time limit exeeded)
#include #include using namespace std;int n, l;string s[1025];int cnt[1025][26];string result;inline bool input(){ cin>>n>>l; if ( !n && !l ) return false; for
ZOJ 1093 Monkey and banana
#include #include #define MAXN 30#define MAX(a, b) a>b?a:b#define MIN(a, b) a>b?b:ausing namespace std;struct Block{ int w, l, h;}blks[3*MAXN];int n;
7195



被折叠的 条评论
为什么被折叠?



