版本号排序

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

#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. Linux删除重复内容命令uniq笔记

    针对文本文件,有时候我们需要删除其中重复的行.或者统计重复行的总次数,这时候可以采用Linux系统下的uniq命令实现相应的功能. 语法格式:uniq [-ic] 常用参数说明: -i 忽略大小写 - ...

  2. 微信小程序-蓝牙连接

    最近的项目需要使用小程序的蓝牙功能与硬件设备进行连接相互传送数据指令,联调过程中发现一些问题,于是想着记录下来,方便以后查看! 1.0一般使用蓝牙功能肯定是想连接某一个蓝牙设备,所以需要知道这个蓝牙设 ...

  3. 56.doc values

    主要知识点 doc values     搜索的时候,要依靠倒排索引:在54小节中写到在聚合排序的时候如果仅仅依靠倒排索引的话是不能得出准确的结果的,需要依靠正排索引,所谓的正排索引,其实就是doc ...

  4. 单例模式的理解【php】

    单例模式(Singleton Pattern):顾名思义,就是只有一个实例.作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 为什么要使用单例模式 1.P ...

  5. react 父组件 向 子组件 传值

    父组件 import React, { Component } from 'react'; import Test from './component/test'; //声明welcome组件 cla ...

  6. python 图片滑动窗口

    METHOD #1: No smooth, just scaling. def pyramid(image, scale=1.5, minSize=(30, 30)): # yield the ori ...

  7. oracle 工具:tkprof

    https://docs.oracle.com/cd/B10501_01/server.920/a96533/ex_plan.htm http://blog.csdn.net/dba_waterbin ...

  8. 洛谷—— P1097 统计数字

    https://www.luogu.org/problem/show?pid=1097 题目描述 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9).已知不相同的数 ...

  9. Android中验证输入是否为汉字及手机号,邮箱验证,IP地址可用port号验证

    1,验证是否为汉字 // 验证昵称 private boolean verifyNickname() { String nickname = edt_username.getText().toStri ...

  10. 关于Linux静态库和动态库的分析

    关于Linux静态库和动态库的分析 关于Linux静态库和动态库的分析 1.什么是库 在windows平台和linux平台下都大量存在着库. 本质上来说库是一种可运行代码的二进制形式.能够被操作系统加 ...