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. c#基础学习汇总----------继承

    封装,继承,多态.这是面向对象的思想,也可以说是最基本的东西.说到继承,直接的说他就是面向对象中类与类之间的一种关系.通过继承,使得子类具有父类公有的受保护访问权限的属性和方法,同时子类可以通过加入新 ...

  2. (hdu)1257 最少拦截系统

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦 ...

  3. 怎样把SEL放进NSArray里

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3805270.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  4. htm5实现视差动画

    requestAnimationFrame.js window.requestAnimFrame = (function() { return window.requestAnimationFrame ...

  5. 使用Dreamweaver批量删除PHP项目中的单行注释和多行注释

    1.删除单行注释 打开Dreamweaver的查找工具,选择正则替换如图: 里面的//.*是正则匹配单行注释的表达式   2.删除多行注释 同样用正则查找匹配,直接上图咯:  其中正则表达式为/\*[ ...

  6. Demo学习: ClientInfo

    ClientInfo 获取客户端环境参数,从0.9版本开始新增了TUniClientInfoRec对象,可以得到客户端的一些信息,之前为了获取浏览器版本号需要自己写函数,现在可以直接使用TUniCli ...

  7. Spark Streaming揭秘 Day26 JobGenerator源码图解

    Spark Streaming揭秘 Day26 JobGenerator源码图解 今天主要解析一下JobGenerator,它相当于一个转换器,和机器学习的pipeline比较类似,因为最终运行在Sp ...

  8. 怎样下载安装Firebug和使用Firebug

    Firebug是基于火狐(FireFox)浏览器的一个插件,它的作用是给Web页面开发者一个很好的测试前端页面代码的工具.所以深受网页开发者或网页布局爱好者的喜爱.像我们用DIV+CSS和html所写 ...

  9. iOS Icon尺寸、iPhone Ratina 分辨率

    高清晰度的iPhone和iPod touch(单位:像素) 启动影像 :640 x 960 APP图标:114 x 114 App Store商店:1024 x 1024 Spotlight搜索小图标 ...

  10. 转载:传说中的T检验

    第二周结束:传说中的T检验 小耿2014-01-21 10:58 本文和上一篇笔记一样:语言十分啰嗦.请大家忍耐…… 以前我不懂统计的时候(现在也不懂),只知道数据出来了要做三件事:1,检验一下数据是 ...