hdu 1004 Let the Balloon Rise(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90644 Accepted Submission(s):
34459
floating around. But to tell you a secret, the judges' favorite time is guessing
the most popular problem. When the contest is over, they will count the balloons
of each color and find the result.
This year, they decide to leave this
lovely job to you.
starts with a number N (0 < N <= 1000) -- the total number of balloons
distributed. The next N lines contain one color each. The color of a balloon is
a string of up to 15 lower-case letters.
A test case with N = 0
terminates the input and this test case is not to be processed.
popular problem on a single line. It is guaranteed that there is a unique
solution for each test case.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; struct node
{
node *next[];
int Count;
node()
{
for (int i=; i<; i++)
next[i]=NULL;
Count=;
}
}; char cc[];
node *p,*root=new node();
void insert(char *s)
{
p=root;
for (int i=; s[i]; i++)
{
int k=s[i]-'a';
if (p->next[k]==NULL)
p->next[k]=new node();
p=p->next[k];
}
p->Count++;
} int Search(char *s)
{
p=root;
for (int i=; s[i]; i++)
{
int k=s[i]-'a';
if (p->next[k]==NULL)
return ;
p=p->next[k];
}
//cout<<p->Count<<" "<<"3333333333"<<endl;
return p->Count;
} int main()
{
int t;
char ch[];
int Max;
while (~scanf("%d",&t))
{
Max=;
if (t==)
break;
while (t--)
{
scanf("%s",ch);
//gets(ch);
insert(ch);
int ans=Search(ch);
if (ans>Max)
{
Max=ans;
strcpy(cc,ch);
}
}
printf ("%s\n",cc);
}
return ;
}
hdu 1004 Let the Balloon Rise(字典树)的更多相关文章
- HDU 1004 Let the Balloon Rise(map的使用)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- hdu 1004 Let the Balloon Rise strcmp、map、trie树
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1004 Let the Balloon Rise【STL<map>】
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1004 Let the Balloon Rise map
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- HDU 1004 - Let the Balloon Rise(map 用法样例)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDU 1004 Let the Balloon Rise(map应用)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDU 1004 Let the Balloon Rise(STL初体验之map)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
随机推荐
- 第217天:深入理解Angular双向数据绑定的原理
一.理解angular双向数据绑定 双向绑定是新的前端框架中频繁出现的一个新词汇,也是mvvm的核心原理.angularjs五条核心信念中的数据驱动,便是由双向绑定进行完成. 那么什么是双向绑定,下面 ...
- nowcoder 203J Graph Coloring I(dfs)
题目链接 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染色,满足相邻点不同色. 澜澜不服气,在黑板上画了一个三个点的完全图.修修跟澜澜说,这个图我能找到一个简单奇环. ...
- Django 2.0 学习(21):Django Session
Django Session Session 与Cookie 1.简介 1.Cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们又需要"保持状态",因 ...
- opencv图片转幻灯片视频
/*g++ *.cpp `pkg-config --cflags --libs opencv` -std=c++11*/ #include <opencv2/opencv.hpp> usi ...
- 51nod乘积之和
题目链接 戳我 题意简述 你有长为\(n\)的序列和\(Q\)个询问,每次询问一个\(k\),求用\(k\)个数组成的不同方案的乘积的和. sol 显然要预处理一波. 考虑分治,左右两边都求出来后,怎 ...
- gitlab相关
1.gitlab的概述 1.gitlab是什么 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务. 基础功能免费,高级功能收费 2.为什么要使用gitla ...
- 调用Android系统设置项
Intent mIntent = new Intent(); ComponentName comp = new ComponentName("com.android.settings&quo ...
- spark 性能调优(一) 性能调优的本质、spark资源使用原理、调优要点分析
转载:http://www.cnblogs.com/jcchoiling/p/6440709.html 一.大数据性能调优的本质 编程的时候发现一个惊人的规律,软件是不存在的!所有编程高手级别的人无论 ...
- [USACO18OPEN]Out of Sorts P 冒泡排序理解之二
题目描述 Bessie把快速排序和冒泡排序混在了一起 给一个伪快排的代码: 冒泡: bubble_sort_pass (A) { to length(A)- ], swap A[i] and A[i+ ...
- Facenet Triplet Loss
Triplet Loss 在人脸识别中,Triplet loss被用来进行人脸嵌入的训练.如果你对triplet loss很陌生,可以看一下吴恩达关于这一块的课程.Triplet loss实现起来并不 ...