紫书
shinimashzi
这个作者很懒,什么都没留下…
展开
-
UVa 140 Bandwidth
求全排列,这些排列中,有关系的元素下表差的最大值 中间的最小值 然而并没有用剪枝。。#include <cstdio>#include <cstring>#include <iostream>#include <vector>#include <cmath>#include <set>#include <algorithm>using namespace std;#define i原创 2017-03-16 20:24:17 · 209 阅读 · 0 评论 -
Uva1594 Ducci Sequence
大意: 有 1. (8, 11, 2, 7) → (3, 9, 5, 1) → (6, 4, 4, 2) → (2, 0, 2, 4) → (2, 2, 2, 2) → (0, 0, 0, 0). 2. (4, 2, 0, 2, 0) → (2, 2, 2, 2, 4) → (0,0,0,2,2) → (0, 0, 2, 0, 2) → (0, 2, 2, 2, 2) → (2, 0,原创 2017-04-05 20:01:10 · 142 阅读 · 0 评论 -
Uva221 Urban Elevations /离散化思想
主要大意:给几个立体的矩形块,判断在某一方向能看到哪几个矩形块注意点: 1.离散化思想,由于是实数点,不可能把所有的点都遍历一遍,所以我们只能将所有的x坐标和x+width坐标排序并去重,相邻两个坐标之间看作一个遍历的位置。这个区间要么完全可见,要么完全不可见, 如果对任意一个矩形块,这个位置可见,并且前方没有能完全遮住它的矩形块(y < it && heigh >= it),那么这个矩形块就原创 2017-04-07 16:02:04 · 596 阅读 · 0 评论 -
UVA - 12100-Printer Queue
题目大意: 模拟打印机, 取出打印机队列的首个,判断在队列中是否有比它更紧急的任务要处理,若是有,将它插入到队尾(凭什么?!) ,若是没有,打印它。输出到打印目标打印完成的时间。题目大意就是主要思路。 其实可以再开个优先级队列一起模拟的。#include<iostream>#include <queue>#include <cstdio>#include <cstring>using原创 2017-04-07 16:23:10 · 217 阅读 · 0 评论 -
UVA - 10935-Throwing cards away I
题目大意: 花式丢牌。 取出牌的第一张,丢一张,再让新的插入牌最后。思路:这种题目即思路。队列模拟。#include<bits/stdc++.h>using namespace std;queue<int> q;vector<int> dis;int main(){ int n; while(~scanf("%d",&n) && n) { while原创 2017-04-07 16:52:36 · 189 阅读 · 0 评论 -
UVA - 10763 Foreign Exchange
题目大意: 有人想从a->b 有人想从b->a 这两种人的数量必须相等。思路:用 一个 map<pair<int,int > ,int >vis 来标记a->b的人数,如果与 b->a的人数不同,就判错#include <bits/stdc++.h>using namespace std;map<pair<int,int>,int >data;int main(){ int n;原创 2017-04-07 17:41:32 · 153 阅读 · 0 评论 -
UVA - 10391 Compound Words
题目 : You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary. In原创 2017-04-07 17:58:20 · 142 阅读 · 0 评论 -
Uva 1595 Symmetry
题目大意:寻找散的点有没有对称轴。思路:用map<int,set<int> > 是因为同一个坐标可能有不同的纵坐标。 从最前和最后开始扫,判断他们的对称轴和点的纵坐标是否相同。在对称轴上的点可以不判断。#include <bits/stdc++.h>using namespace std;#define maxn 1005#define EPS 1e-9map<int,set<int> >原创 2017-04-07 18:06:55 · 165 阅读 · 0 评论 -
UVA - 1596 Bug Hunt
题目大意: 有两种语句,一种定义 a[size] 另外一种赋值 a[id] = b[id] / a[id] = value; 类似这种主要思路:用map<string,int> 存放变量名和变量名对应的size, map<string,map<int,int> > 来存放哪几个id是被初始化过的了,只有这里面的值可以出现在[]里面。check() 递归检查类似a[b[c[id]]] 这种原创 2017-04-10 09:23:55 · 736 阅读 · 0 评论 -
UVA - 1597 Searching the Web
题目大意:简易版的搜索,只有4种情况, 查询单词a,查询a and b,查询a or b,查询not a,输出相应的结果,注意a and b是同一篇文章里的有a的内容和有b的内容,a和b不一定需要在同一行。思考:题意即思路。只是我写的比较麻烦。。map<string,set<Pair> > word 存放word在哪些文章的行出现过,因为set可以自己排序,所以用了set。vector<str原创 2017-04-10 19:52:17 · 254 阅读 · 0 评论 -
UVA - 210 Concurrency Simulator
题意: 给你很多个程序块,每个程序块只能一次执行Q个时间,若是在Q个时间内未执行完,则插入队列Q1尾部。 有unlock和lock操作,不能有两个程序同时执行lock操作,当前面的程序申请了lock操作,后面的想再申请,直接放入另一个队列Q2的尾部,当unlock操作执行时,取出Q2的首元素,加入Q1的前端。思路:把题目看懂这个题就成功了一大半。双向队列,我用的数组模拟。#include<bit原创 2017-04-13 08:58:58 · 274 阅读 · 0 评论 -
UVA - 442 C - Matrix Chain Multiplication
题目 : 计算一个矩阵乘法的次数讲道理,应该用struct的,但是最近几天写stl写傻了。。。直接上了pair,也不知道是为什么。。。#include <algorithm>#include <cstring>#include <iostream>#include <cstdio>#include <queue>#include <stack>#include <map>using n原创 2017-04-13 09:04:54 · 247 阅读 · 0 评论 -
Uva 122 Trees on the level
大意: 给出二叉树,求层次遍历,第一次试着用数组模拟链表建树。 #include <algorithm>#include <cstring>#include <cstdio>#include <iostream>#include <sstream>#include <queue>using namespace std;#define maxn 2005struct btnode{原创 2017-04-13 21:55:51 · 320 阅读 · 1 评论 -
UVA - 548 Tree
题意 : 给你一颗二叉树,给定中序和后序,求叶子结点到根结点的最小值。思路:由中序和后序求树,然后dfs~#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <sstream>#include <queue>using namespace std;#define maxn原创 2017-04-14 15:47:01 · 151 阅读 · 0 评论 -
Uva-839 + Uva-699
两题类似,所以放在一起了。839 题目大意: 判断天平是否平衡。 思路:按前序遍历的顺序建树,在建树的同时可以判断是否平衡。代码:#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>#include <queue>#include <set>using namespace std;int f原创 2017-04-14 16:05:00 · 250 阅读 · 0 评论 -
UVA - 297 Quadtrees
题意: 四分树涂色,一共32*32个格子,涂两遍,最后统计涂了色的格子数量。 思路:边建树边涂色,我是把32*32看作一个1024的长条,然后可以算出编号多少到多少要涂色,因为只关系最后涂了色的格子数量,所以顺序不是很重要。代码:#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#includ原创 2017-04-14 18:57:49 · 189 阅读 · 0 评论 -
UVA - 572 Oil Deposits
题目:The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits.GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides原创 2017-04-14 19:05:10 · 193 阅读 · 0 评论 -
Uva1593 Alignment of Code
题目大意:让我们把代码对齐,缩进空格注意的点: 每行的最后一个单词是不需要空格的。#include <bits/stdc++.h>using namespace std;#define maxn 1005vector<string> data[maxn];int main(){ //freopen("D://in.txt","r",stdin); char c; int原创 2017-04-05 19:54:32 · 161 阅读 · 0 评论 -
UVA - 814 The Letter Carrier's Rounds
大意:模拟邮件交互。这个题目真是一言难尽。。不是很想用string类,导致写的特别的丑,由于读取信息的数组开小了还RE了几发,感觉还是需要用一下string类的。#include <bits/stdc++.h>using namespace std;set<string> addr;int readmta(){ char s[40],a[40];int n; while(1)原创 2017-04-05 14:51:04 · 318 阅读 · 0 评论 -
Uva 400 - Unix ls
题意: 给出几个字符串,按给定格式输出。 简单题,#include <bits/stdc++.h>using namespace std;#define maxn 105struct str{ char s[100]; int slen;}data[maxn];int n;int cmp(str a,str b){ int flag = strcmp(a.s,原创 2017-04-04 14:13:07 · 206 阅读 · 0 评论 -
UVA - 129 Krypton Factor
题目:You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the contestants are tested原创 2017-03-14 20:16:36 · 198 阅读 · 0 评论 -
算法竞赛第七章
例题:Uva1601/埃及分数问题/Uva11212 待续 Uva1601/11212 基本都参考了网上的代码,感觉自己的思想还不够,代码写的还不够…Uva1601 //这题基本是看的网上大佬的代码大意是几个点从初始位置到结束位置,求最短的时间。最多三个点,2*2的格子里必有障碍物。 主要考建图! 看了书,对于把空格提出来建图十分不理解,以为标记一下就可以了,是我太天真….这一题可以用原创 2017-03-30 09:44:24 · 387 阅读 · 0 评论 -
Uva213 Message Decoding
例题:uva213 Uva512 Uva12412 习题:Uva213 //主要考字符串的读取,可以多想想,有没有简洁一点的读法 Uva512 //模拟文档的操作过程原创 2017-03-30 21:21:55 · 282 阅读 · 0 评论 -
Uva512 Spreadsheet Tracking
题意: 模拟文档的操作,增加删除,最后查询初始单元格的位置。不需要每次都变,直接在询问的时候模拟过程就好。不是很复杂。 但是今天不知道怎么回事,老是出一些奇怪的错误…废了很长时间。哎。#include <bits/stdc++.h>using namespace std;#define maxn 60int m,n;struct p{ int way; int n;原创 2017-03-30 21:26:28 · 299 阅读 · 0 评论 -
紫书第四章总结3.30-4.02
例题:uva213 Uva512 Uva12412 习题:Uva1589 Uva253 Uva201例题: Uva213 //主要考字符串的读取,可以多想想,有没有简洁一点的读法 Uva213题解 Uva512 //模拟文档的操作过程 Uva512题解 Uva12412 //..c语言程序设计,更生气的是还没过..代码有点长 Uva12412题解 习题: Uv原创 2017-03-30 21:29:28 · 224 阅读 · 0 评论 -
Uva12412
模拟//代码还没过..不知道错哪了,放两天改c语言程序设计#include <cstdio>#include <iostream>#include <cstring>#include <vector>#include <algorithm>using namespace std;#define maxn 1000005const double EPS = 1e-5;struct stu原创 2017-03-31 19:45:58 · 394 阅读 · 2 评论 -
Uva201 Squares
模拟,找正方形有多少个,昨天uva又炸了,今天才看到结果。 终于看到了一个不那么恶心的模拟…课设那题WA了10发…还没过,先放一放再看吧。题目: A children’s board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots.原创 2017-04-01 08:45:22 · 331 阅读 · 0 评论 -
Uva253 Cube painting
题目: 两个正方体是否等价。写的代码有点丑…改一下再发一次吧。#include <bits/stdc++.h>using namespace std;char s[20];char a[10],b[10];int check(){ char rot[10]; for(int i = 0; i < 6; i++) { strcpy(rot,b);原创 2017-04-01 10:05:38 · 204 阅读 · 0 评论 -
UVA - 10474 Where is the Marble?
题意:给n个整数,排序,给出询问,看第一个出现的那个整数的下标。1~N简单题。#include <cstdio>#include <algorithm>#include <cstring>using namespace std;#define maxn 100005int m,n;int data[maxn];int main(){ int num = 1; while原创 2017-04-03 09:09:10 · 173 阅读 · 0 评论 -
UVA - 101 The Blocks Problem
题意:模拟堆砖块的过程。 vector的应用。#include <iostream>#include <cstdio>#include <cstring>#include <vector>using namespace std;vector<int> data[100];int n;int fin(int a){ for(int i = 0; i < n ; i++)原创 2017-04-03 09:11:07 · 130 阅读 · 0 评论 -
UVA - 10815 Andy's First Dictionary
简单题,主要教set的应用 输出多少个不重复的单词,但我个人不是很想用string,所以就用getchar()读入了。#include <cstdio>#include <set>#include <algorithm>#include <cstring>#include <iostream>using namespace std;#define maxn 10005set<stri原创 2017-04-03 09:12:58 · 178 阅读 · 0 评论 -
UVA - 156 Ananagrams
题目大意: 输出不能重排成另外一个单词的单词,在比较时不分大小写,但是输出时要分。map的基本应用Input Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up原创 2017-04-03 17:22:55 · 164 阅读 · 0 评论 -
Uva 1589 xiangqi
模拟是否将死的局面。 马 : 向各个方向先走两步,再往垂直与这个方向上走一步,若这个方向的第一个位置有棋子,则这个方向上不能走。炮: 直线方向上的第一个棋子和第二个棋子之间的位置都可以吃。车: 上下左右将/帅: 不能见面,若是见面,使它们见面的那一方输,所以开始时要特判一下,如果此时将帅见面了,则是黑方输,输出NO这里特别注意的是,将是可以吃棋子的,也即是可以有将先吃了一颗红方的棋,然后另外的棋子原创 2017-04-03 19:56:23 · 236 阅读 · 0 评论 -
Uva 1592 Database
题意: 数据库的表,找r1,r2,c1,c2 使表中(r1,c1) = (r2,c1) (r1,c2) = (r2,c2) map的应用 给每个字符串编个号,这样比较便于处理,也能减少时间。#include <bits/stdc++.h>using namespace std;#define maxn 10010#define Pair pair<int,int>vector<int>原创 2017-04-04 13:53:44 · 220 阅读 · 0 评论 -
Uva 12096 The SetStack Computer
题意:模拟栈的情况,但是这个栈处理的元素是集合。 紫书的思路 将所有集合都编号,用map来进行编号。 set 中的set_union() 取a,b并集到c中去 set_intersection() 同时包含a,b中的元素,将其复制到c中去#include <cstdio>#include <cstring>#include <iostream>#include <st原创 2017-04-04 14:07:04 · 177 阅读 · 0 评论 -
UVA - 136 Ugly Numbers
题意: 数字包括1,以及2,3,5,2x,3x,5x…..#include <bits/stdc++.h>using namespace std;#define LL long longpriority_queue<LL , vector<LL> , greater<LL> > pq;set<LL> s;int pri[3] = {2,3,5};int solve(){ s.i原创 2017-04-04 14:10:46 · 176 阅读 · 0 评论 -
UVA - 1103 Ancient Messages
题目大意: 给你几个符号,然后用点来表示那个位置有没有被涂黑,每个点是16进制,所以先得把它转换成2进制,判断符号类型,然后按字典序输出。思路:讲道理这个脑洞我是开不出来的,还是按紫书的思路写的,因为每个字符的内部的空白块的个数不一样,具体做法是把符号外部的空白格子标记,然后把每个符号标记,在标记符号的同时,找周围有没有空白的格子,如果有,肯定是符号内部的空白格,因为此时外部的空白格已经全部被标记过原创 2017-04-15 11:37:52 · 694 阅读 · 1 评论