ACM之STL专题
punchline_skr
会飞的代码
展开
-
安迪的第一个字典(Uva 10815)
说白了,就是set……刚开始考虑到cin可能会超时,就用scanf,一直输出格式错误,只好按教材上来(不过代码真的短,哈哈)……QAQ#include<bits/stdc++.h>using namespace std;set<string>dict;int main(){ string s,buf; while(cin>>s) ...原创 2018-03-12 19:09:49 · 239 阅读 · 0 评论 -
团体队列(Uva 540)
有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么新人会插队到最后一个队友的身后。如果没有任何一个队友排队,则他会被排到长队的队尾。输入每个团队中所有队员的编号,要求支持如下3种指令:ENQUEUE x:编号为x的人进入长队DEQUEUE:长队的队首出队STOP:停止模拟对于每个DEQUEUE指令,输出出队的人的 编号。每个团体有一个队列,团体整体又形...原创 2018-03-12 19:48:51 · 300 阅读 · 0 评论 -
唯一的雪花(Uva 11572)
检测是否有相同的元素,首先想到的是set……可是在Oj上提交却超时QAQ,哪位知道的评论一下好吗?先谢谢啦……#include<bits/stdc++.h>using namespace std;set<int>s;int a[1000005];int main(){ int t,n; scanf("%d",&t); while(t...原创 2018-03-12 21:49:29 · 265 阅读 · 0 评论 -
复合词(Uva 10391)
涉及到substr()函数,第一次用QAQ……单词长度不长,分成子串在set集合里面查找。担心cin,cout会超时,所以用scanf,printf替代,然而printf不能直接输出string类型,需处理……#include<bits/stdc++.h>using namespace std;set<string>s;int main(){ string ...原创 2018-03-13 21:50:27 · 342 阅读 · 0 评论 -
priority_queue,set,map自定义排序
在使用很多的priority_queue时候默认优先级并不适合题目要求,得自己定义优先级……#include<bits/stdc++.h>using namespace std;struct node{ int x,y; friend bool operator<(node a,node b) { if(a.x!=b.x) ...原创 2018-03-15 14:13:50 · 962 阅读 · 1 评论 -
看病要排序(hdu 1873)
题目:点击打开链接这是一道很典型的优先队列题型,每个医生对应一个优先队列,队列里面不止一个数据成员,所以最好用结构体存储。关键在于自定义优先级……#include<bits/stdc++.h>using namespace std;char a[4];struct node{ int cnt; int rank; friend bool operator...原创 2018-03-15 14:30:40 · 162 阅读 · 0 评论 -
一元多项式加法
除了用链表还可以用STL中的map,^-^#include<bits/stdc++.h>using namespace std;struct node{ int x; int y;}stu[105];map<int,int>s;void f(string x){ int flag=1,t=0,j=1,m,n; for(int i...原创 2018-04-04 22:48:19 · 508 阅读 · 0 评论 -
湫湫系列故事——消灭兔子
刚开始想着贪心来着,但是怎么实现呢?可以借助优先队列,把那些可以消灭兔子的箭所对应的Q币入队,当然这里需要注意兔子的血量需从大到小遍历,那么入队的箭的优先级是Q币小的优先级大,计算一个出队一个……#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;int B[maxn];struct node{ ...原创 2018-04-24 22:23:33 · 271 阅读 · 0 评论 -
逆序单词(hihoCoder 1366)
用字典树可解,但是STL要方便些#include<bits/stdc++.h>using namespace std;map<string,int>m;int main(){ int n,ans=0; scanf("%d",&n); string s; while(n--) { cin>>s...原创 2018-05-04 22:13:02 · 294 阅读 · 6 评论 -
A-最小化价格
怎么就没想到用优先队列呢(遗憾QWQ)……!!!#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;int a[maxn];priority_queue<int,vector<int>,greater<int> >s;//从小到大排序struct node{ ...原创 2018-05-11 23:15:46 · 150 阅读 · 0 评论