bestcoder.hdu.edu.cn
http://bestcoder.hdu.edu.cn/
Problem A
题目链接:
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1001
http://acm.hdu.edu.cn/showproblem.php?pid=5685
题目分析:
因为是中文题目,便不再赘述
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e5 + 5;
int H[MAXN];
char Hstr[MAXN];
int N, l, r;
const int mods = 9973;
typedef long long LL; LL mod_pow(LL x, LL n, LL mod) {
LL res = 1;
while(n > 0) {
if(n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
} int main(){
while(~scanf("%d", &N)){
scanf("%s", Hstr);
int len = strlen(Hstr);
H[0] = 1;
for(int i = 1;i <= len;i ++){
H[i] = H[i - 1] * (Hstr[i - 1] - 28) % mods;
}
while(N --){
scanf("%d%d", &l, &r);
if(l > r) swap(l, r);
printf("%I64d\n", (LL)H[r] * mod_pow(H[l - 1], mods - 2, mods) % mods);
}
}
return 0;
}
Problem B
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5686
题目分析:
1 1 1
2 11 2 2
3 111 21 12 3
4 1111 211 112 121 22 5
5 8
所以,很容易推出 F[i] = F[i-1] + F[i-2]
需要注意的地方是这里必须使用大数加法,不然会报错
代码:
#include <iostream>
#include<string.h>
#include <stdio.h>
using namespace std;
int a[205][205];
int main()
{
memset(a,0,sizeof(a));
a[1][200]=1;a[2][200]=2;
int i,j;
for(i=3;i<=200;i++)
{
for(j=200;j>0;j--)
{
a[i][j]=a[i][j]+a[i-1][j]+a[i-2][j];
if(a[i][j]>9)
{
a[i][j-1]=a[i][j]/10;
a[i][j]=a[i][j]%10;
}
}
}
int n;
while(cin>>n)
{
j=0;
while(a[n][j]==0)j++;
for(;j<=200;j++)
{
cout<<a[n][j];
}
cout<<endl;
}
return 0;
}
Problem C
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5687
题目分析:
使用字典树
代码:
#include<cstdio>
#include<cstring>
#include<stdlib.h>
const int N=26;
struct node{
int flag; // 记录该单词出现的次数;
node *next[N];
node(){
flag=0;
memset(next,0,sizeof(next));
}
};
node *p,*pre,*head=new node();
void Insert(char s[])
{
p=head;
int i=0;
while(s[i]){
int id=s[i++]-'a';
if(p->next[id]==NULL) p->next[id]=new node();
p=p->next[id];
p->flag++; // 标记该分支字母出现的个数;
}
//p->flag++; // 标记改单词出现过,并且记录出现的次数;
}
// 返回该单词出现的次数;
int Query(char s[])
{
p=head;
int i=0;
while(s[i]){
int id=s[i++]-'a';
if(p->next[id]==NULL) return 0;
p=p->next[id];
}
return p->flag;
}
// 不能删除,删除会导致TLE,不删除容易出现内存泄漏MLE
int deal(node *T)
{
for(int i=0;i<N;i++){
if(T->next[i]!=NULL)
deal(T->next[i]);
}
free(T);
return 0;
}
// 该单词的计数-cnt;
void Deal(char s[],int cnt)
{
p=head;
int i=0;
while(s[i]){
int id=s[i++]-'a';
p=p->next[id];
p->flag-=cnt;
}
for(int i=0;i<N;i++){
p->next[i]=NULL;
}
//deal(p);
return ;
}
int main()
{
int n;
char s1[35],s2[35];
while(~scanf("%d",&n)){
head=new node();
for(int i=0;i<n;i++){
scanf("%s %s",s1,s2);
if(strcmp(s1,"insert")==0) Insert(s2);
if(strcmp(s1,"search")==0){
if(Query(s2)) printf("Yes\n");
else printf("No\n");
}
if(strcmp(s1,"delete")==0){
int t=Query(s2); // 前缀为s2的单词出现的次数;
if(t)Deal(s2,t);
}
}
//deal(head);
}
return 0;
}
Problem D
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5688
题目分析:
使用map容器做
代码:
#include<cstdio>
#include<string>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
map<string,int>m;
char s[100]; int main()
{
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
sort(s,s+strlen(s));
m[s]++;
printf("%d\n",m[s]-1);
}
return 0;
}
bestcoder.hdu.edu.cn的更多相关文章
- HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...
- KMP(http://acm.hdu.edu.cn/showproblem.php?pid=1711)
http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<stdio.h> #include<math.h> #inclu ...
- HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632
http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...
- 待补 http://acm.hdu.edu.cn/showproblem.php?pid=6602
http://acm.hdu.edu.cn/showproblem.php?pid=6602 终于能够看懂的题解: https://blog.csdn.net/qq_40871466/article/ ...
- HDU-1257 导弹拦截系统 http://acm.hdu.edu.cn/showproblem.php?pid=1257
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...
- BestCoder HDU 5750 Dertouzos
Dertouzos 题意: 有中文,不说. 题解: 我看了别人的题解,还有个地方没懂, 为什么是 if(d%prime[i]==0) break; ? 代码: #include <bits/st ...
- http://acm.hdu.edu.cn/showproblem.php?pid=2579
#include<stdio.h> #include<string.h> #include<queue> #define N 110 int m, n, k, x1 ...
- KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594
riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...
- HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544
//代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h ...
随机推荐
- oschina娱乐游戏
休闲游戏 123网络游戏 88单机游戏 201游戏模拟器/工具/引擎
- freemarker报错之八
1.错误描写叙述 freemarker.core.ParseException: Encountered "string" at line 21, column 21 in typ ...
- Vi/VIM键盘图, Vi/vim学习图
Vi/vim学习图 引用: Vi键盘图片可视化教程 http://www.cnblogs.com/me115/archive/2010/11/16/1878295.html 网上的文章易流失.感谢分享 ...
- BZOJ 1704: [Usaco2007 Mar]Face The Right Way 自动转身机( 贪心 )
贪心...先枚举k, 然后从左往右扫一遍, 发现位置p的牛的状态不符合就将 [p, p + k ) 的牛都转身, 假如p + k - 1 已经超过了最右边牛的位置那这个k就不符合要求. 符合要求的就可 ...
- 幻世(OurDream)2D图形引擎使用教程11——播放媒体文件(1)
声明:本教程版权归Lizcst Software Lab所有,欢迎转载,但是转载必须保留本段声明文字,并注明文章来源:http://blog.csdn.net/kflizcst 谢谢合作! 播放媒体是 ...
- 高级UIKit-10(UDPSocket)
[day1201_UDPSocket]:utpsocket的使用 使用UDP网络传输,是一种无连接的传输协议,不安全,一般使用在监控视频中或QQ聊天中,该网络传输就向广播传播模式,一对多. 在ios中 ...
- VC6.0 导入资源崩溃
等我以后挣钱了一定买正版! 最近学习Win32编程,为了锻炼自己,在网上下载了一个VC6.0作为开发工具,应该是兼容性的问题吧,VC6 经常闹毛病. 今天导入资源的时候VC6出现崩溃的现象. 马上寻求 ...
- Jquery学习笔记:利用find和children方法获取后代元素
在很多场景下,需要根据一个已知的jquery对象,去查找其满足条件的后代节点. 这时可以利用 find函数和children来处理. find和children函数都可有一个参数,常见的是一个字符串, ...
- JVM调优总结(十一)-反思
垃圾回收的悖论 所谓“成也萧何败萧何”.Java的垃圾回收确实带来了很多好处,为开发带来了便利.但是在一些高性能.高并发的情况下,垃圾回收确成为了制约Java应用的瓶颈.目前JDK的垃圾回收算法,始终 ...
- mysql各版本区别
MySQL 的官网下载地址:http://www.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,开源免费, ...