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 ...
随机推荐
- Windows7下安装搭建play框架
作者:Sungeek 出处:http://www.cnblogs.com/Sungeek/ 欢迎转载,也请保留这段声明.谢谢! 1.首先官网下载play的解压包 https://playframewo ...
- Visual Studio通过Web Deploy发布网站报错:An error occurred when the request was processed on the remote computer.
这个问题很奇怪,不管我怎么重启服务器和自己的开发机,都没有用. 在网上找了很多资料,有说可以尝试去读Windows的错误日志,然后通过日志找原因…(详见Stackoverflow:http://sta ...
- xamarin android——数据绑定到控件(二)
本示例为通过媒体内容提供器获取本机中的图片显示在Gallery中. 活动中简单的初始化代码 private void InitGallery() { Gallery gallery = FindVie ...
- CCNA第二讲笔记
网络定义:一组由介质(线缆)互联的网络设备(路由器.交换机)和终端系统(PC): 工作组:局域网范畴,范围最小的局域网,且不涉及网络设备.台式机需要有多块网卡,利用双绞线与其他台式机进行互联,扩展性差 ...
- Android学习1
Activity学习(1) 只有一个Activity 进行Toast通知 Toast是一种短小的提醒,显示一段时间就会消失,试验学习,可以通过一个Button来实现. Button reg=(Butt ...
- PHP取二进制文件头快速判断文件类型
<?php /*文件扩展名说明 *7173 gif *255216 jpg *13780 png *6677 bmp *239187 txt,aspx,asp,sql *208207 xls.d ...
- 关于postgresql——常用操作指令
创建数据库 CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8'; 进入控制台方法,在postgreSQL的安装目的bin下执行命令 ...
- linux驱动系列之s3c2440内存布局
刚开始学习linux在2440上面 linux内核分配标志可以分为三类:行为修饰符.区修饰符.类型. 区修饰符表示从哪儿分配内存,内核把物理内存分为多个区,每个区用于不同的目的. 内存中缓冲区存在的原 ...
- poj 1236 Network of Schools(又是强连通分量+缩点)
http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- 深层解析:构建facebook应用商店推荐引擎
Under the Hood: Building the App Center recommendation engine As more apps on Facebook Platform ha ...