STL
穷源溯流
路很长,尽管走便是。
展开
-
NC15203 投票统计(离散化)
其实这个题用 map 的话很好解决本题采用离散化解决,利用桶排的思想,因为桶无法申请那么大的内存,所以进行离散化const int N=1e5+5; int i,j,k; int n,m,t; pii a[N],cnt[N]; vector<int> v,ans;int get_id(int x){ return lower_bound(v.begin(),v.end(),x)-v.begin()+1;}bool ...原创 2020-11-22 15:47:32 · 234 阅读 · 0 评论 -
约瑟夫环(STL链表)
//#include <bits/stdc++.h>#include <iostream>#include <algorithm>#include <list>using namespace std;#define FOR(i,a,b) for(int i=a;i<=b;i++)#define null NULLconst double pi=3.14;const int N=2e5+5; int a[N];in...原创 2020-10-27 08:30:08 · 263 阅读 · 0 评论 -
P1168 中位数(vector 实现 set)
int n,m,t; int i,j,k; vector<int> v;int main(){ //IOS; while(sd(n)==1){ for(i=1;i<=n;i++){ int x; sd(x); v.insert(upper_bound(v.begin(),v.end(),x),x); if(i&1) p...原创 2020-07-27 22:48:02 · 365 阅读 · 0 评论 -
E2. Voting (Hard Version)(思维)
有 n 个人,每个人有 mi 和 pi ,mi 代表着如果有 mi 个人投票给他,那么他就免费投票给他,否则你需要花费pi的代价来收买他。请问最少花费多少使得所有人都投他。看到 m 数组的数据范围,m 数组作为数组下标应该是没得跑了,有贪心策略我们应该选择 pi 尽量少的那些人,但是同时要照顾到 m 数组。因为要贿赂的总人数我们不知道,但借用优先队列(小根堆),将目前为止的最少需要的贿赂人数贿赂。向题目中提到的:m :1 2 2 4 5,只需贿赂 m[5] 即可,这样贪心策略就...原创 2020-07-15 16:14:09 · 285 阅读 · 0 评论 -
F. Asya And Kittens(List+并查集)
有 n 只猫,原来分别在一个笼子里,但是相邻的猫想一起玩就将它们放在一个笼子里,但是现在它们凑成了一堆,问他们原来在几号笼子里const int N=15*1e4+5; int n,m,t; int i,j,k; int fa[N]; list<int> l[N];int Find(int x){ return fa[x]==x? x: fa[x]=Find(fa[x]);}int main(){ IOS; wh...原创 2020-07-12 16:36:00 · 208 阅读 · 0 评论 -
Symmetry UVA - 1595( set+pair )
YESNOYES我们假设对称轴坐标为 x ,那么这 n 个点中每两个对称的点的横坐标 <X1, Xn> <X2,Xn-1> 满足X1+Xn=2*x或者是位于对称轴上的数 <Xm> (Xm*2 = x*2)所有数的横坐标相加则为 n*x,假设我们要判断 Xn 是否有对称点,只需要证明 2*x-Xn=X1即可,我们在等式两边 同 ×n,即可避免除法运算计算对称轴 Pair p[N]; set<Pair> all;...原创 2020-06-24 14:49:53 · 177 阅读 · 0 评论 -
Compound Words
#include<iostream>#include<cstring>#include<algorithm>#include<map>#include<set>using namespace std;const int maxn = 120010;int main(){ set<string> s; string str; while(cin>>str) { s.insert(str); ...原创 2020-06-23 23:52:14 · 391 阅读 · 0 评论 -
substr() 函数
包含头文件 <string>s . substr( pos , len ) ;从初始位置 pos 开始读取长度为 len 个字符#include <iostream>#include <iostream>int main(){ std::string s="12345 abc"; std::cout << s.substr(0,5) << std::endl; std::cout << s.s原创 2020-06-23 23:50:12 · 10614 阅读 · 0 评论 -
Foreign Exchange(map)
Sample Input101 22 13 44 3100 200200 10057 22 571 22 1101 23 45 67 89 1011 1213 1415 1617 1819 200Sample OutputYESNO int n,m,t; int i,j,k; map<Pair,int> mp;int main(){ //IOS; while(~sd(n)...原创 2020-06-23 21:40:28 · 192 阅读 · 0 评论 -
to_string() 函数
包含头文件 <string>功能:将括号内的 数字 转化为 字符串to_string( idata )#include <string>#include <iostream>int main(){ std::string s="the pi is "; std::cout << s << std::endl; s += std:: to_string(3.141592653589); std:原创 2020-06-23 20:59:15 · 14849 阅读 · 0 评论 -
Ducci Sequence (水题)
题目链接1000此操作之内,若可以全变为 0 则输出 zero ,否则 loop,(大写) int n,m,t; int i,j,k; int a[N];int main(){ IOS; rush(){ cin>>n; int num=1001; bool f=0; for(i=0;i<n;i++) cin>>a[i]; while(n..原创 2020-06-23 20:48:03 · 193 阅读 · 0 评论 -
B. Make Them Equal(set)
You are given a sequencea1,a2,…,ana1,a2,…,anconsisting ofnnintegers.You can choose any non-negative integerDD(i.e.D≥0D≥0), and for eachaiaiyou can:addDD(only once), i. e. performai:=ai+Dai:=ai+D, or subtractDD(only once), i. e. performa...原创 2020-06-14 10:47:43 · 356 阅读 · 0 评论 -
Rails
波普什市有一个著名的火车站。那里的乡村有着令人难以置信的丘陵。这个车站建于上个世纪。不幸的是,当时的资金极为有限。只能建立一条地面轨道。此外,事实证明,空间站可能只是一个死胡同(见图),由于缺乏可用的空间,它只能有一个轨道。在这里插入图片描述当地的传统是,从A方向到达的每一列火车都会继续向B方向行驶,教练也会以某种方式重新组织起来。假设从A方向到达的列车编号为N<=1000辆客车,编号为1,2,…,N。列车重组主管必须知道是否有可能将客车继续沿B方向行驶,以便其顺序为A1、a2、.a。帮助他并编写原创 2020-06-11 20:51:30 · 680 阅读 · 0 评论 -
F. Consecutive Subsequence(dp与map)
You are given an integer array of lengthnn.You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to[x,...原创 2020-06-07 13:16:21 · 281 阅读 · 0 评论 -
Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. T...原创 2020-06-06 10:46:39 · 203 阅读 · 0 评论 -
Team Queue
题意有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一个队友身后。如果没有任何一个队友排队,则他会排到长队的队尾。输入每个团队中所有队员的编号,要求支持如下3种指令(前两种指令可以穿插进行)。ENQUEUE:编号为X的人进入长队。DEQUEUE:长队队首出队。STOP:停止模拟。对于每个DEQUEUE指令,输出出队的人的编号。输入输入文件中有一组或多组测试数据。每组测试数据开始有t个团队。下面t行,每行的第一个数字代表这个团队人数,...原创 2020-06-04 14:37:40 · 474 阅读 · 0 评论 -
Ugly Numbers
题意丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来,结果如下:1,2,3,4,5,6,8,9,10,12,15……求第1500个丑数输入没有输入输出The 1500'th ugly number is <number>.#pragma GCC optimize(2)#include <bits/stdc++.h>#define rush() int T;cin>>T;while(T--)#define...原创 2020-06-03 22:55:08 · 312 阅读 · 0 评论 -
Ananagrams(map)
Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot fo原创 2020-06-01 21:36:36 · 267 阅读 · 0 评论 -
Andys First Dictionary
DescriptionAndy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From .原创 2020-06-01 20:40:13 · 236 阅读 · 0 评论 -
set简单应用
描述给定N个单词(每个单词长度不超过100,单词字符串内仅包含小写字母)。请求出N个单词中共有多少个不同的单词。输入第1行包含1个正整数N。接下来N行每行包含一个字符串。输出一个整数,代表不同单词的个数样例输入5lalalahahahahahalalalahaha 样例输出3#include <iostream>#i...原创 2019-12-14 15:08:38 · 311 阅读 · 0 评论 -
Where is the Marble?
//#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int idata=1000+5;int k,i,j;//int dp[idata][idata];int step[idata];int n,m;int flag;int...原创 2020-02-28 18:36:35 · 146 阅读 · 0 评论