版本号排序

不知道什么傻逼原因,就是过不了

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
void makedata() {
freopen("input.txt", "w", stdout);
cout << << endl; for(int i = ; i < ; i++) cout << << ' '; fclose(stdout);
} VI a[];
bool ok(int x, int y) {
int lx = a[x].size(), ly = a[y].size();
int l = min(lx, ly); for(int i = ; i < l; i++) {
if(a[x][i] < a[y][i]) return true; if(a[x][i] > a[y][i]) return false;
} if(lx <= ly) return true;
else return false;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
cin >> n; for(int i = ; i < n; i++) {
int tmp;
cin >> tmp;
a[i].push_back(tmp); while(getchar() == '.') {
cin >> tmp;
a[i].push_back(tmp);
}
} for(int i = ; i < n; i++) {
for(int j = i + ; j < n; j++) {
if(!ok(i, j)) swap(a[i], a[j]);
}
} for(int i = ; i < n; i++) {
cout << a[i][]; for(int j = ; j < a[i].size(); j++) cout << '.' << a[i][j]; cout << endl;
} return ;
}

自底向上遍历二叉树

叶节点从左到右的顺序就是它们在树的从上到下的遍历中的顺序,按遍历中的顺序不断向上找

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
void makedata() {
freopen("input.txt", "w", stdout);
cout << << endl; for(int i = ; i < ; i++) cout << << ' '; fclose(stdout);
} VI ch[];
bool f[];
int father[];
void traverse(int x) {
while(f[x] == false && x) {
cout << x << endl;
f[x] = true;
x = father[x];
}
}
void dfs(int x) {
if(ch[x].size() == ) traverse(x);
else for(int i = ; i < ch[x].size(); i++) dfs(ch[x][i]);
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
cin >> n;
memset(father, , sizeof(father)); for(int i = ; i < n; i++) {
int u, v;
cin >> u >> v;
father[v] = u;
ch[u].push_back(v);
} for(int i = ; i <= n; i++) {
if(ch[i].size() != ) continue; if(ch[i][] > ch[i][]) {
int tmp = ch[i][];
ch[i][] = ch[i][];
ch[i][] = tmp;
}
} int root = ; while(father[root]) root = father[root]; memset(f, false, sizeof(f));
dfs(root);
return ;
}

hiho字符串2

根据长度dfs,注意一开始是第1代而不是第0代。

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
void makedata() {
freopen("input.txt", "w", stdout);
cout << << endl; for(int i = ; i < ; i++) cout << << ' '; fclose(stdout);
} lint L[][];
const lint INF = (1LL << ); char dfs(string s, int n, lint k) {
char ch = s[];
int len = s.size();
string ss; if(n == ) {
if(k > len) return ;
else return s[k - ];
} if(L[ch][n] >= k) {
if(ch == 'h') ss = "hio"; if(ch == 'i') ss = "hi"; if(ch == 'o') ss = "ho"; return dfs(ss, n - , k);
} else {
k -= L[ch][n];
ss = s.substr(, len - );
return dfs(ss, n, k);
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
L['h'][] = L['i'][] = L['o'][] = ; for(int i = ; i <= ; i++) {
L['h'][i] = L['h'][i - ] + L['i'][i - ] + L['o'][i - ];
L['i'][i] = L['h'][i - ] + L['i'][i - ];
L['o'][i] = L['h'][i - ] + L['o'][i - ]; if(L['h'][i] > INF) L['h'][i] = INF; if(L['i'][i] > INF) L['i'][i] = INF; if(L['o'][i] > INF) L['o'][i] = INF;
} int t, n;
lint k;
cin >> t;
string s = "hiho"; while(t--) {
cin >> n >> k;
cout << dfs(s, n - , k) << endl;;
} return ;
}

最长多数子串

一开始想的是二分+hash,没过。别人用的SAM,想破了脑袋也想不清楚。以前看过SAM,当时看完就觉得:“好叼啊,可是有什么用啊?”,怎么也想不通在哪里能用上,这里别人用了,怎么也想不通到底怎么过的。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<memory>
#include<cmath>
#define maxn 2000003
using namespace std;
int n, m, len, ans, Max, now;
char s[maxn], cap[maxn];
struct SAM {
int ch[maxn][], fa[maxn], maxlen[maxn], Last, sz;
int root, nxt[maxn], size[maxn];
void init() {
sz = ;
root = ++sz;
memset(size, , sizeof(size));
memset(ch[], , sizeof(ch[]));
memset(nxt, , sizeof(nxt));
}
void add(int x) {
int np = ++sz, p = Last;
Last = np;
memset(ch[np], , sizeof(ch[np]));
maxlen[np] = maxlen[p] + ;
while (p && !ch[p][x]) ch[p][x] = np, p = fa[p];
if (!p) fa[np] = ;
else {
int q = ch[p][x];
if (maxlen[p] + == maxlen[q]) fa[np] = q;
else {
int nq = ++sz;
memcpy(ch[nq], ch[q], sizeof(ch[q]));
size[nq] = size[q];
nxt[nq] = nxt[q];
maxlen[nq] = maxlen[p] + ;
fa[nq] = fa[q];
fa[q] = fa[np] = nq;
while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];
}
}
for (; np; np = fa[np])
if (nxt[np] != now) {
size[np]++;
nxt[np] = now;
} else break;
}
};
SAM Sam;
int main() {
while (~scanf("%d%d", &n, &m) && n) {
Sam.init();
for (int i = ; i <= n; i++) {
scanf("%s", s + );
Sam.Last = Sam.root;
len = strlen(s + );
now = i;
for (int j = ; j <= len; j++) Sam.add(s[j] - 'a');
}
Max = ;
ans = ;
for (int i = ; i <= Sam.sz; i++)
if (Sam.size[i] >= m && Sam.maxlen[i] > ans) {
Max = i;
ans = Sam.maxlen[i];
}
printf("%d\n", ans);
}
return ;
}

[hihocoder][Offer收割]编程练习赛43的更多相关文章

  1. hihocoder [Offer收割]编程练习赛4

    描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...

  2. hihocoder [Offer收割]编程练习赛61

    [Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...

  3. ACM学习历程—Hihocoder [Offer收割]编程练习赛1

    比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...

  4. hihocoder offer收割编程练习赛8 C 数组分拆

    思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...

  5. hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)

    题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...

  6. hihoCoder [Offer收割]编程练习赛3 D子矩阵求和

    子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...

  7. hihocoder [Offer收割]编程练习赛52 D 部门聚会

    看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...

  8. hihocoder [Offer收割]编程练习赛14

    A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...

  9. hihocoder [Offer收割]编程练习赛8

    第一次做这种比赛,被自己坑的好惨... A.这道题的关键其实是如果有k和n满足kD+F>nL>kD则不能走无限远,分支看似难整理,其实比较简单,F>L根本就不用算了,明摆着就是Bsi ...

随机推荐

  1. beetl模板入门例子

    加入maven依赖 <dependency> <groupId>org.beetl</groupId> <artifactId>beetl-core&l ...

  2. scala类型系统:24) 理解 higher-kinded-type

    首先我们从最基本的泛型来看: 现在我们对上面泛型中的类型参数再进一步,也是个泛型会如何呢? 可以看到,java中不支持类型参数也是泛型类型的情况,而scala支持.这是一个很重要的区别,scala在类 ...

  3. PDF怎么替换页面,教你一招秒实现

    PDF格式是在办公中比较常用的文件格式之一,虽然很好用,也很容易携带,但也容易出现一个问题,当你想要对PDF文件操作或者修改的时候,才发现PDF文件不是那么容易就能进行编辑和修改的,特别是需要对PDF ...

  4. BZOJ 4278: [ONTAK2015]Tasowanie 后缀数组 + 贪心 + 细节

    Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in", "r", stdin ...

  5. 【转载】深入理解Java的接口和抽象类

    深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...

  6. codeforces 427D Match & Catch(后缀数组,字符串)

    题目 参考:http://blog.csdn.net/xiefubao/article/details/24934617 题意:给两个字符串,求一个最短的子串.使得这个子串在两个字符串中出现的次数都等 ...

  7. [luogu2054 AHOI2005] 洗牌 (数论)

    传送门 Solution 我们考虑每一步牌的变化: 前半部分的牌位置*2 后半部分的牌位置*2-n-1 那么我们可以看做是\(x\times 2^m\equiv l \pmod n\) 于是求个逆元就 ...

  8. Idea里面的postfix

    感谢慕课网IntelliJ IDEA神器使用技巧 闪电侠讲师,感觉有些工具真的是听听别人讲的比自己琢磨快很多 https://www.imooc.com/learn/924 也可以这样找到postfi ...

  9. 第一次训练 密码:acmore

    #include <cstdio> #include <cstring> #define M 100010 #define INF 0x7FFFFFFF #define Min ...

  10. F - Count the Colors

    F - Count the Colors ZOJ - 1610   思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...