自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

lh的博客

路漫漫~~~

  • 博客(77)
  • 收藏
  • 关注

原创 九度OJ 1467 二叉排序树

题目1467:二叉排序树 注意是多组数据#include <cstdio>#include <cstdlib>#include <cstring>typedef struct node_ *node;struct node_ { int key; node lc, rc;};int insert(node &t, int fk, int k) { if (t) {

2017-09-24 10:25:58 247

原创 九度OJ 1474 矩阵幂

题目1474:矩阵幂#include <cstdio>#include <cstring>void mul(int a[][15], int b[][15], int ans[][15], int n) { int tmp[15][15]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {

2017-09-24 09:55:54 213

原创 九度oj1473 二进制数

题目1473:二进制数#include <cstdio>void print(int n) { if (!n) return; print(n>>1); printf("%d", n&1);}int main(){ int t; scanf("%d", &t); int n; while(t--) { sca

2017-09-24 09:28:31 380

原创 九度oj 1488 百万富翁问题

九度1488 百万富翁问题 题意感觉有问题。。#include <cstdio>int main(){ printf("%d %d\n", 10*30, (1<<30)-1); return 0;}

2017-09-24 09:20:18 448

原创 tiger 语义分析(类型检查)

为编译器实现类型检查。 在语法分析的基础上,对抽象语法树进行类型检查,并生成相关报错信息。完成语法分析的基础上,还需: types.[ch]: 已给出,描述了tiger语言的数据类型 env.[ch]: 实现值环境、类型环境 semant.[ch]:实现类型检查函数SEM_transProg(A_exp exp) semtest.c: 测试平台,main入口 修改makefi

2017-03-10 20:15:33 2039

原创 tiger 抽象语法树生成

在语法分析基础上添加语义动作,生成tiger语言抽象语法树。官网给出框架和构造函数代码,仅仅需要在tiger.y添加相应语义动作,实现比较容易。文法: 文法稍作改变,增加了tydecs和fundecs来对应书中要求的nametylist和functionlist。由此产生了两个新shift/reduce conflict。 tydecs: tydec . | tydec

2017-03-02 17:59:32 1648

原创 tiger 语法分析实现(无语义)

用bison实现tiger语言的语法分析,只判断语法是否出错,无语义动作。shift/reduce conflict: 按照书上给的语法规则完成tiger.y文件,出现了三类shift/reduce conflict一、else悬挂 exp : IF exp THEN exp . | IF exp THEN exp . ELSE exp可以通过给else赋比then高的优先级消

2017-02-27 17:57:50 1751 2

原创 1029 Median

中位数#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e6 * 2 + 5;long long a[MAXN];int main() { int n, m; scanf("%d", &n); for (int i = 0; i < n

2017-02-27 11:10:45 409

原创 1028 List Sorting (25)

排序#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct stu { int id; char name[10]; int grade;};const int MAXN = 1e5+5;stu s[MAXN];bool cmp1(stu a, stu b) {

2017-02-27 10:58:52 220

原创 1027 Colors in Mars (20)

进制转换#include <cstdio>char t[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C'};void trans(int x) { printf("%c%c", t[x/13], t[x%13]);}int main() { int x, y, z; scanf("%d%d%d", &x, &y

2017-02-27 10:58:15 228

原创 tiger 词法分析实现

用lex实现一个tiger语言的词法分析器.tiger语言词法规范:标识符 以字母开头,由字母、数字和下划线组成的序列。区分大小写字母。注释 可以出现在任意两个单词之间。以/*开始,以*/结束,并且可以嵌套。整型常量 由十进制数字组成的一个序列。没有负整型,对于带负号的整型需返回两个单词字符串常量 由括在双引号之间的零至多个可打印字符、空白符或转义序列组成的序列。 tiger允

2017-02-20 11:50:09 2869 3

原创 PAT甲1123 Is It a Complete AVL Tree (30) --AVL

题意很简单,按avl数进行插入操作,最后进行层序遍历输出,判断是不是一个完全二叉树。还是太菜, avl没写出来。。。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int num, h; node *left,

2016-12-12 12:39:10 632

原创 hdu1180 诡异的楼梯 --bfs+优先级队列

遇到楼梯特殊处理#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int x, y, t; node() {} node(int xx, int yy, int tt):x(xx), y(yy), t(tt)

2016-12-11 14:38:18 238

原创 hdu1728 逃离迷宫 --bfs

题目链接:hdu1728还是bfs走迷宫, 但不再是求最短路,而是问能不能在k次转向内从出发点走到目标点.初始方向不计入次数,可以直接把四个方向全push 队列节点的次数都限制在k次以内,大于k就不用push了#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace st

2016-12-11 11:27:38 305

原创 1025 PAT Ranking (25)

简单的排序#include <bits/stdc++.h>using namespace std;struct node { long long id; int score, loc, locrank, rank; friend bool operator<(const node &a, const node &b) { if (a.score == b.s

2016-12-04 20:21:45 321

原创 1024 Palindromic Number (25)

大数模拟#include <cstdio>#include <cstring>#include <algorithm>using namespace std;bool pal(char a[]) { int len = strlen(a); for (int i = 0; i < len; i++) if (a[i] != a[len-1-i])

2016-12-04 17:23:21 541

原创 1023 Have Fun with Numbers (20) --大数

#include <cstdio>#include <cstring>bool cmp(char x[], char y[], int len) { int vix[10], viy[10]; memset(vix, 0, sizeof(vix)); for (int i = 0; i < len; i++) vix[x[i]-'0']++; mem

2016-12-04 16:32:04 228

原创 1022 Digital Library ---map+set

#include <cstdio>#include <cstring>#include <string>#include <map>#include <set>#include <iostream>#include <algorithm>using namespace std;map<string, set<int> > mp[6];int main() { string s;

2016-12-04 15:56:22 230

原创 1021 Deepest Root --dfs

先判断是不是树,并查集和深搜都可以 求树的直径,两遍搜索,答案为其合集。#include <cstdio>#include <cstring>#include <vector>#include <set>#include <algorithm>using namespace std;const int MAXN = 10010;vector<int> mp[MAXN];bool vis

2016-12-04 15:09:43 191

原创 1020 Tree Traversals --二叉树乱搞

根据后序和中序输出层次遍历的节点序#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int l, r, il, ir; node(){} node(int ll, int rr, int ill, int ir

2016-12-01 21:23:34 437

原创 1019 General Palindromic Number --水题

进制转换判回文#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int num[100];int main() { int n, b; scanf("%d%d", &n, &b); if (!n) { puts("Yes"); puts("

2016-12-01 20:42:21 179

原创 1018 Public Bike Management --dijkstra+dfs

back不具有最优子结构,不能单纯用dijkstra解,找出所有最短可能路径dfs进行比较#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;struct node { int to, lg; node() {}; node(int t,

2016-12-01 20:30:44 270

原创 1017 Queueing at Bank --队列模拟2

忘了time是关键字, 懒得改了,define一下。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;#define time asdfastruct time { int hh, mm, ss; time() {}; time(int

2016-11-29 20:18:45 254

原创 1016 Phone Bills

越做越恶心。。。 For each test case, you must print a phone bill for each customer.print for each customer 花费为0的不是顾客。。。#include <cstdio>#include <cstring>#include <string>#include <set>#include <map

2016-11-29 19:06:57 430

原创 1015 Reversible Primes

素数打表,转置判断#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e5+10;bool isprime[MAXN];void init() { memset(isprime, true, sizeof(isprime)); isprime[0

2016-11-28 20:31:56 365

原创 1014 Waiting in Line --队列模拟

模拟题,注意题意。。。 for those customers who cannot be served before 17:00, you must output “Sorry” instead.17点之前被接待了,服务超过17点也不要紧。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>us

2016-11-28 20:04:04 205

原创 1013 Battle Over Cities --dfs找联通块

如果失去某个城市后分为k个联通块,则最少需k-1条边使其联通#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int MAXN = 1010;vector<int> mp[MAXN];bool vis[MAXN];void dfs(int i,

2016-11-25 18:13:54 263

原创 1012 The Best Rank

成绩排序取所有科目成绩中最高的排名.开了4个数组模拟…. 注意成绩平均分四舍五入,并不能按总分排,其次成绩相等排名并排.#include <cstdio>#include <map>#include <algorithm>using namespace std;const double eps = 1e-8;const int MAXN = 2010;struct node { int

2016-11-25 16:46:55 181

原创 PAT1011 World Cup Betting

水题注意浮点型精度#include <cstdio>const double eps = 1e-9;int main() { double x, sum = 1; for (int i = 0; i < 3; i++) { double max = -1e10; int mi = 0; for (int j = 1; j <= 3; j

2016-11-22 20:54:07 233

原创 1010 Radix ---二分

这个题。。。 有毒 疯狂wa首先最大进制并不是36, 你得二分。。 其次会爆longlong。。 输出格式用lld。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef unsigned long long LL;char a[20

2016-11-20 20:13:05 513

原创 1009 Product of Polynomials --多项式乘法

多项式乘法模拟,注意为0的情况下精度问题,#include <cstdio>#include <cmath>#include <vector>#include <map>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double eps = 1e-9;vector<p

2016-11-19 22:24:19 234

原创 1008 Elevator

模拟#include <cstdio>int main() { int n, ans = 0; scanf("%d", &n); int l = 0, t; while (n--) { scanf("%d", &t); if (l < t) ans += 6 * (t - l); else if

2016-11-19 21:23:51 230

原创 1007 Maximum Subsequence Sum --最大字段和

简单的dp, 但是…… 看清题意,输出的是最大子段和, 子段第一数和最后数(不是下标…)#include <cstdio>const int MAXN = 10010;int a[MAXN];int main(){ int n; scanf("%d", &n); int t, tmp, lt; int ans = -1, l, r; for(int i =

2016-11-19 21:02:40 312

原创 1006 Sign In and Sign Out

两遍排序, 分别找出in最小值和out最大值#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;struct node{ char id[20]; int hh, mm, ss; friend bool operator<(const

2016-11-19 12:21:54 282

原创 1005 Spell It Right --水

大数用字符串保存,各位求和,英文表示输出#include <cstdio>#include <cstring>char s[1000];char to[][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void print(int x) { if (x < 10

2016-11-19 11:54:30 232

原创 1004 Counting Leaves --bfs

统计一棵树上每层的叶节点, bfs#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <algorithm>using namespace std;const int MAXN = 110;vector<int> mp[MAXN];int book[MAXN], ans[MAXN];i

2016-11-19 11:41:03 353

原创 1003 Emergency --dijkstra

team数组保存当前经过路径招的人数,除了出发点初始全为0. pn数组保存最短路径数,初始为0,出发点为1. 最短路松弛时,dist更小时,更新team, pn赋新值; dist相等时, pn加上前驱点的pn值,如果team更多,更新team#include <cstdio>#include <cstring>#include <vector>#include <algorithm>u

2016-11-19 11:31:22 258

原创 1002 A+B for Polynomials

#include <cstdio>#include <map>#include <iostream>using namespace std;int main(){ int k; map<int, double, greater<int> > q; int a; double b; scanf("%d", &k); while(k--) { scanf("%

2016-11-19 11:19:31 197

原创 1001 A+B Format

#include <cstdio>void print(int ans){ if(ans < 1000) { printf("%d", ans); return; } print(ans/1000); printf(",%03d", ans % 1000);}int main(){ int a, b; scanf("%d%d", &a, &b);

2016-11-19 11:18:06 225

原创 POJ1155 TELE【树形dp(背包)】

Apple TreeTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 10035Accepted: 3338DescriptionWshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N n

2016-10-08 15:13:45 345

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除