Fundamental Datastructure
11988 - Broken Keyboard (a.k.a. Beiju Text)
可以用deque来模拟。
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
#include <queue>
using namespace std; const int MAX = ; char ch[MAX]; int main() {
while (scanf("%s", ch) != EOF) {
deque<string> Q;
string buffer = "";
int toward = ;
int n = strlen(ch); for (int i = ; i < n; i++) {
if (ch[i] == '[') {
if (toward > ) Q.push_back(buffer);
else Q.push_front(buffer);
toward = -;
buffer = "";
} else if (ch[i] == ']') {
if (toward > ) Q.push_back(buffer);
else Q.push_front(buffer);
toward = ;
buffer = "";
} else {
buffer += ch[i];
}
} if (toward > ) Q.push_back(buffer);
else Q.push_front(buffer); for (int i = ; i < Q.size(); i++) {
printf("%s", Q[i].c_str());
}
printf("\n");
}
}
一点点解析。
#include <cstdio>
#include <vector>
using namespace std; const int MAXN = ; int n, bfs[MAXN], dfs[MAXN];
int idx[MAXN], root[MAXN]; int main() {
while (scanf("%d", &n) != EOF) {
for (int i = ; i < n; i++) scanf("%d", &bfs[i]);
for (int i = ; i < n; i++) scanf("%d", &dfs[i]);
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
if (bfs[i] == dfs[j]) {
idx[i] = j;
break;
}
}
}
int p = ;
for (int i = ; i < n; i++) {
root[i] = bfs[];
}
vector<vector<int> > tree(n + );
while (p < n) {
vector<int> sons;
sons.push_back(p);
int max_idx = idx[p];
int i;
for (i = p + ; i < n; i++) {
if (root[idx[i]] != root[idx[p]] || idx[i] < max_idx) {
break;
}
max_idx = idx[i];
sons.push_back(i);
}
tree[root[idx[p]]] = sons;
p = i;
for (i = sons.size() - ; i >= ; i--) {
int j = idx[sons[i]];
int r = root[j];
while (j < n && root[j] == r) {
root[j++] = bfs[sons[i]];
}
}
}
for (int j = ; j <= n; j++) {
printf("%d:", j);
for (int k = ; k < tree[j].size(); k++) {
printf(" %d", bfs[tree[j][k]]);
}
printf("\n");
}
}
}
行列互换后排序。
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std; struct Data {
int r, c, v;
bool operator < (const Data& d) const {
if (r != d.r) {
return r < d.r;
} else {
return c < d.c;
}
}
}; int main() {
int m, n;
while (scanf("%d%d", &m, &n) != EOF) {
vector<Data> datas;
for (int i = ; i <= m; i++) {
int r;
scanf("%d", &r);
for (int j = ; j < r; j++) {
Data d;
scanf("%d", &d.r);
d.c = i;
datas.push_back(d);
}
for (int j = ; j < r; j++) {
scanf("%d", &datas[datas.size() - r + j].v);
}
}
sort(datas.begin(), datas.end());
int mm = , i = ;
printf("%d %d\n", n, m);
while (mm <= n) {
vector<Data> row;
while (i < datas.size() && datas[i].r == mm) {
row.push_back(datas[i]);
i++;
}
mm++;
printf("%d", (int)row.size());
for (int j = ; j < row.size(); j++) {
printf(" %d", row[j].c);
}
printf("\n");
for (int j = ; j < row.size(); j++) {
if (j) printf(" ");
printf("%d", row[j].v);
}
printf("\n");
}
}
}
Fundamental Datastructure的更多相关文章
- enhance convenience rather than contribute to the fundamental power of the language
Computer Science An Overview _J. Glenn Brookshear _11th Edition Universal Programming Languages In ...
- 【DataStructure In Python】Python实现各种排序算法
使用Python实现直接插入排序.希尔排序.简单选择排序.冒泡排序.快速排序.归并排序.基数排序. #! /usr/bin/env python # DataStructure Sort # Inse ...
- 【DataStructure In Python】Python模拟栈和队列
用Python模拟栈和队列主要是利用List,当然也可以使用collection的deque.以下内容为栈: #! /usr/bin/env python # DataStructure Stack ...
- 【DataStructure In Python】Python模拟链表
最近一直在学习Python和Perl这两门语言,两者共同点很多,也有不多.希望通过这样的模拟练习可以让自己更熟悉语言,虽然很多时候觉得这样用Python或者Perl并没有体现这两者的真正价值. #! ...
- Fundamental types
Fundamental types void type boolean type character types integer types Modifiers signedness size Pro ...
- Google's Machine Learning Crash Course #01# Introducing ML & Framing & Fundamental terminology
INDEX Introducing ML Framing Fundamental machine learning terminology Introducing ML What you learn ...
- Fundamental theorem of arithmetic 为什么1不是质数
https://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic In number theory, the fundamental th ...
- The fundamental differences between "GET" and "POST"
The HTML specifications technically define the difference between "GET" and "POST&quo ...
- This instability is a fundamental problem for gradient-based learning in deep neural networks. vanishing exploding gradient problem
The unstable gradient problem: The fundamental problem here isn't so much the vanishing gradient pro ...
随机推荐
- Xamarin 实现android gridview 多选
参考文章:http://blog.csdn.net/zhouyuanjing/article/details/8372686 GridView初始化代码: gridViewStudent = Find ...
- PHP文件操作
1.递归获取目录下文件的个数 function getFileCount($dir){ if(!is_dir($dir)) return false; //打开目录 $handle = opendir ...
- Mongodb DB shell数据操作
shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的. Ø 数据库 1.Help查看命令提示 help db.help(); db.yo ...
- ASP.NET工具
每个开发人员现在应该下载的十种必备工具 发布日期: 7/20/2004 | 更新日期: 7/20/2004 本文自发布以来已经增加了新信息. 请参阅下面的编辑更新. 本文讨论: • 用于编写单元测试的 ...
- main函数的正确格式
main函数称之为主函数,一个C程序总是从main()函数开始执行的.在关于C语言的网贴和图书中,可以看到main函数的多种格式,这些格式,有的是正确的,有的是不正确的,为了避免错误,现归纳整理如下. ...
- AJAX 原理(转摘)
在写这篇文章之前,曾经写过一篇关于AJAX技术的随笔,不过涉及到的方面很窄,对AJAX技术的背景.原理.优缺点等各个方面都很少涉及null.这次写这篇文章的背景是因为公司需要对内部程序员做一个培训.项 ...
- 数据结构二叉树的递归与非递归遍历之java,javascript,php实现可编译(1)java
前一段时间,学习数据结构的各种算法,概念不难理解,只是被C++的指针给弄的犯糊涂,于是用java,web,javascript,分别去实现数据结构的各种算法. 二叉树的遍历,本分享只是以二叉树中的先序 ...
- Hadoop 相关链接
Apache 软件下载 http://mirror.bit.edu.cn/apache/ 相关文档链接: Apache Hadoop 2.5.2 http://hadoop.apache.org ...
- 【多路复用】I/O多路复用
http://www.tuicool.com/articles/RBvqUz C#下用select方法实现socket服务端
- EXTJS 4.2 资料 控件之Grid Columns 列renderer 绑定事件
columns: [ { header: '序号', xtype: 'rownumberer', align: 'center', width: 100 }, { header: 'CompanyId ...