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");
}
}

10410 - Tree Reconstruction

一点点解析。

#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");
}
}
}

10895 - Matrix Transpose

行列互换后排序。

#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的更多相关文章

  1. 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  ...

  2. 【DataStructure In Python】Python实现各种排序算法

    使用Python实现直接插入排序.希尔排序.简单选择排序.冒泡排序.快速排序.归并排序.基数排序. #! /usr/bin/env python # DataStructure Sort # Inse ...

  3. 【DataStructure In Python】Python模拟栈和队列

    用Python模拟栈和队列主要是利用List,当然也可以使用collection的deque.以下内容为栈: #! /usr/bin/env python # DataStructure Stack ...

  4. 【DataStructure In Python】Python模拟链表

    最近一直在学习Python和Perl这两门语言,两者共同点很多,也有不多.希望通过这样的模拟练习可以让自己更熟悉语言,虽然很多时候觉得这样用Python或者Perl并没有体现这两者的真正价值. #! ...

  5. Fundamental types

    Fundamental types void type boolean type character types integer types Modifiers signedness size Pro ...

  6. 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 ...

  7. Fundamental theorem of arithmetic 为什么1不是质数

    https://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic In number theory, the fundamental th ...

  8. The fundamental differences between "GET" and "POST"

    The HTML specifications technically define the difference between "GET" and "POST&quo ...

  9. 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 ...

随机推荐

  1. 公交CPU卡原理

    现在的公交卡已经开始逐步的采用IC卡(CPU卡?什么东东?),而且在国家交通部的推动下,开始了全国范围内的互联互通.以后,手里只用拿着一张卡,就可以走遍全国,而且如果支持在线充值的话,基本上就不用在车 ...

  2. Java多线程(六) 线程系列总结

    多线程系列终于终结得差不多,本人对该系列所做的总结大致如下: 线程锁模块耗费了大量的时间,底层的AQS实现比较复杂.仍然没有时间总结源码部分,能够坚持写下这么几个篇幅的内容真心佩服自己....希望继续 ...

  3. js 执行效率

    循环 在JavaScript中,我们可以使用for(;;),while(),for(in)三种循环,这三种循环中for(in)的效率极差,因为他需要查询散列键,只要可以就应该尽量少用.for(;;)和 ...

  4. 开发问题记录——AE开发提示80040111错误

    System.runtime.interpServices.ComException(0X80040111): 80040111 ClassFactory无法供应请求的类(异常来自HRESULT:0X ...

  5. KnockoutJS(1)-数据模型

    前言 说到数据模型(ViewModel),就不得不提到MVVM模式,接触过WPF和Silverlight的人应该对这个模式比较熟悉. 不熟悉也没多大关系,因为KnockoutJS的使用相对简单. MV ...

  6. CentOs7&zookeeper

    下载安装包 wget http://www.apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.6.tar.gz 解压 tar xzvf zookeep ...

  7. Javascript倒计时页面跳转

    在js中实现页面定时跳转我们要使用setInterval或setTimeOut函数,还可以使用页面的meta实现. 例1: <script type="text/javascript& ...

  8. 解决WPF图片模糊最佳方法(绑定PixelWidth与PixelHeight)

    从事WPF开发一年有余,对于图片显示模糊相信很多人都遇到过.网络上查找能得到一堆解决方法,但都是会带来其他负面影响得不到最佳效果.其实,有些图片会因为垂直分辨率/水平分辨率不同而造成在WPF界面上显示 ...

  9. OO之策略模式

    以下为策略模式详解: 引子: 使用策略就是要实现可扩展性,那么多态是不可少的.何谓可扩展性呢? 比如:我们用面向对象的思想来设计飞机,基类为飞机,飞机可以有很多种,客机,直升机,战斗机等,不同种类的飞 ...

  10. ashx与验证码

    using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; us ...