STL
文章平均质量分 67
ACLJW
这个作者很懒,什么都没留下…
展开
-
10474:Where is the Marble?
Where is the Marble?排序加二分查找#include<cstdio>#include<algorithm>using namespace std;const int maxn = 100000;int n,q,mar[maxn];int main(){ int kase = 0; while(scanf("%d%d",&n...原创 2018-04-15 13:19:26 · 184 阅读 · 0 评论 -
822:Queue and A
Queue and A#include<bits/stdc++.h>using namespace std;const int maxn = 1000 + 5;struct topic{ int n,st,t,b,w = 0;}t;struct person{ int w = 0,st = 0; //the rest time that can do next...原创 2018-04-30 23:50:18 · 229 阅读 · 0 评论 -
814:The Letter Carrier's Rounds
The Letter Carrier's Rounds注意可能有重复的收件人。version 1(20ms):#include<cstdio>#include<iostream>#include<map>#include<set>#include<cstring>#include<algorithm>using n...原创 2018-04-20 17:09:35 · 189 阅读 · 0 评论 -
1593:Alignment of Code
Alignment of Code#include<iostream>#include<cstring>#include<vector>#include<algorithm>#include<sstream>using namespace std;const int maxw = 180 + 5;const int maxl...原创 2018-04-21 01:13:42 · 108 阅读 · 0 评论 -
1596:Bug Hunt
Bug Hunt我的思路:对于每行code,若无等号,直接初始化数组即可,否则依次检查等号左边和右边的表达式是否正确。对于左边的表达式,只需检查到首个数组之前即可,因为可能要对其初始化;对于右边表达式则要全部检查。对于复合表达式要如何检查呢?我的做法是先找出数字下标,确定其最内层数组,然后依次向外找出外层数组。此外还有一些小细节需要特别注意,这次是一次AC,开心。具体代码如下:#include&l...原创 2018-04-25 12:23:54 · 340 阅读 · 0 评论 -
1594:Ducci Sequence
Ducci Sequenceversion 1(130ms):#include<cstdio>using namespace std;const int maxn = 20;int t,n,a[maxn];int main(){ scanf("%d",&t); while(t--){ scanf("%d",&n); ...原创 2018-04-21 22:05:27 · 146 阅读 · 0 评论 -
10935:Throwing cards away I
Throwing cards away I queue#include<cstdio>#include<queue>using namespace std;int n;int main(){ while(scanf("%d",&n) && n){ if(n == 1){ //注意n为1的情况 p...原创 2018-04-21 22:44:45 · 166 阅读 · 0 评论 -
10763:Foreign Exchange
Foreign Exchangeversion 1(100ms):#include<cstdio>#include<map>#include<set>using namespace std;int n;int main(){ while(scanf("%d",&n) && n){ map<int,i...原创 2018-04-21 22:52:20 · 271 阅读 · 0 评论 -
1597:Searching the Web
Searching the Web这道题就 "and" 查询麻烦点,别的还好,但是刚开始超时了。。。version 1(Time limit exceeded):#include<bits/stdc++.h>using namespace std;const int maxn = 100 + 5;typedef pair<int,int> P;vector<s...原创 2018-04-28 21:42:09 · 137 阅读 · 0 评论 -
511:Do You Know the Way to San Jose?
Do You Know the Way to San Jose?题目不难,主要就是排序,不过有些细节需要注意。一个很坑的地方是 map 的两个对角点是不确定的,可能是左上和右下,也可能是左下和右上,而且两个点的顺序也不一定是左右。。。害我找了好久的bug。。。还有就是输出的时候注意单词别拼错了,空格别多打了。。因为这个WA了好几发。。AC大概是现在唯一能让我开心的事情了。#in...原创 2018-04-29 23:44:04 · 216 阅读 · 0 评论 -
442:Matrix Chain Multiplication
Matrix Chain Multiplication这道题比较简单,考察栈在表达式求值中的应用,看了书上代码之后才发现我考虑复杂了。。。其实题目中括号中只有个两个矩阵,我以为会有多个矩阵,所以将"("(用(0,0)代替)也压入了堆栈,用来判断什么时候停止合并。那样的话就特别特别简单了。。。输入数据少打了个回车找了半天bug。。。复杂版:#include<bits/stdc++.h>...原创 2018-05-20 22:11:24 · 137 阅读 · 0 评论 -
10410:Tree Reconstruction
Tree Reconstruction#include<bits/stdc++.h>using namespace std;const int maxn = 1000 + 5;int n,x,root;int pos[maxn];vector<int>A[maxn];int main(){ // freopen("data.in","r",stdi...原创 2018-08-20 23:12:59 · 267 阅读 · 0 评论 -
230:Borrowers
Borrowers又因为输出WA了一发。。。一定要看清楚输出要求啊啊#include<cstdio>#include<iostream>#include<map>#include<vector>#include<cstring>#include<algorithm>using namespace std;cons...原创 2018-04-23 10:48:29 · 134 阅读 · 0 评论 -
221:Urban Elevations
Urban Elevations书上的思路(离散化):把所有x坐标排序去重,则任意两个相邻x坐标形成的区间具有相同属性,一个区间要么完全可见,要么完全不可见。这样,只需在这个区间里任选一个点(例如中点),就能判断出一个建筑物是否在整个区间内可见。如何判断一个建筑物是否在某个x坐标处可见呢?首先,建筑物的坐标中必须包含这个x坐标,其次,建筑物南边不能有另外一个建筑物也包含这个x坐标,并且不比它矮。代...原创 2018-04-18 23:18:08 · 150 阅读 · 0 评论 -
10391:Compound Words
Compound Words我的思路:对于每个单词,依次枚举其所有可能组合的情况,看其两个子单词是否存在于dict中。version 1(30ms):#include<cstdio>#include<iostream>#include<set>#include<cstring>using namespace std;int main(){...原创 2018-04-22 21:17:54 · 129 阅读 · 0 评论 -
101:The Blocks Problem
The Blocks Problem其实四条命令可以简化为两个操作:1. 把某个块上面的块放回原位;2. 把某个块及其上的块放到另一个块所在的堆顶。还可以加一个数组保存每个块的所在的堆,这样写出来的代码比书上还间接哈哈哈。第一次WA是多输出了换行,第二次是以为有多组数据,代码如下:#include<cstdio>#include<vector>#include<a...原创 2018-04-15 17:11:15 · 152 阅读 · 0 评论 -
10815:Andy's First Dictionary
Andy's First Dictionary#include<iostream>#include<set>#include<string>#include<sstream>using namespace std;set<string>dict;int main(){ string s,buf; while(c...原创 2018-04-15 20:48:32 · 124 阅读 · 0 评论 -
156:Ananagrams
Ananagrams思路:对于每一个单词,先存入数组,然后标准化(小写加排序)后的单词的计数值加1,最后输出数组中计数位1的单词即可。version 1(自己写的版本):#include<iostream>#include<map>#include<string>#include<algorithm>using namespace std;...原创 2018-04-15 21:57:27 · 108 阅读 · 0 评论 -
12096:The SetStack Computer
The SetStack Computer为每个不同的集合分配一个唯一的ID,则每个集合都可以表示成所包含元素的ID集合,这样就可以用STL的set<int>来表示了,而整个栈则是一个stack<int>。#include<iostream>#include<cstdio>#include<map>#include<set&g...原创 2018-04-16 21:45:33 · 458 阅读 · 0 评论 -
540:Team Queue
Team Queue本题有两个队列:每个团队有一个队列,而团队整体又形成一个队列,建两个queue即可。#include<cstdio>#include<map>#include<queue>using namespace std;const int maxt = 1000 + 5;int t,n;char cmd[10];int main(){...原创 2018-04-16 23:57:54 · 157 阅读 · 0 评论 -
136:Ugly Numbers
Ugly Numbers从小到大生成各个丑数,最小的丑数是1,而对于任意丑数x,2x、3x和5x也都是丑数。这样,就可以用一个优先队列保存所有已生成的丑数,每次取出最小的丑数,生成3个新的丑数。唯一需要注意的是,同一个丑数有多种生成方式,所以需要判断一个丑数是否已经生成过。#include<iostream>#include<vector>#include<set...原创 2018-04-17 12:39:22 · 104 阅读 · 0 评论 -
400:Unix ls
Unix ls #include<iostream>#include<vector>#include<algorithm>using namespace std;const int len = 60 + 2;void print(const string& s,int len,char extra){ cout<<s; ...原创 2018-04-17 21:21:18 · 100 阅读 · 0 评论 -
1592:Database
Database思路:只枚举c1和c2,然后从上到下扫描各行。每次碰到一个新的行r,把c1,c2两列的内容作为一个二元组存到一个map中。如果map的键值中已经存在这个二元组,该二元组映射到的就是所要求的r1,而当前行就是r2。在主循环之前先做一个预处理——给所有字符串分配一个编号,则整个数据库中每个单元格都变成了整数,上述二元组就变成了两个整数,这个操作同样用到了map。version 1(14...原创 2018-04-17 23:59:59 · 131 阅读 · 0 评论 -
1595:Symmetry
Symmetry我的思路:开始是想着将所有点都存在set里面,找出对称轴,然后对于每一个点确定其对称点是否存在,但是觉得这样效率似乎太低,就放弃了。后来想到了这样做:将所有点按x坐标进行排序,若x坐标相同,则对于对称轴左边的点按y坐标又小到大排序,右边则相反。这样的话如果这些点是左右对称的,那么两端的点一定是对称的,因为经过我上面的排序其实相当于用一维数组将各点在平面上的相对关系表现了出来。然后依...原创 2018-04-22 15:41:46 · 217 阅读 · 0 评论 -
12100:Printer Queue
Printer Queuepriority_queue + queue#include<cstdio>#include<queue>using namespace std;const int maxn = 500000;int t,n,pos;int main(){ scanf("%d",&t); while(t--){ s...原创 2018-04-22 16:51:42 · 214 阅读 · 0 评论 -
12504:Updating a Dictionary
Updating a Dictionaryversion 1:#include<cstdio>#include<iostream>#include<map>#include<set>#include<cstring>using namespace std;const int maxl = 100 + 5;int t,n;c...原创 2018-04-22 16:55:33 · 124 阅读 · 0 评论 -
673:Parentheses Balance
Parentheses Balance之前脑子可能坏掉了。。。简单的栈的应用,要注意的一个地方是一定要用 fgets ,因为如果是空串的话 scanf 会直接读下一行。#include<bits/stdc++.h>using namespace std;const int maxn = 128 + 5;int n;char s[maxn];int main(){...原创 2018-08-21 16:21:32 · 533 阅读 · 0 评论