随笔分类 - STL
摘要:A:裸的广搜题,需要输出路径B:贪心抓住题目的特殊性,每个物品只有1 2 两种体积先按性价比排序,贪心的优先选择性价比高的,某次选了之后体积超了,就剪掉这样子遍历一遍之后还不是答案因为可能会有1体积的空位,而可能通过去掉已选集合中某个1体积的物品,再用一个2体积的物品替代达到更优解所以这里要判断一下View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 100010;struct node { int type; in
阅读全文
摘要:和poj 的hotel差不多,多了一些细节处理的过程给一辆汽车安排空位的时候还需要和前后的车都保持一定的车距,如果前面没车或者后面没车,则可以停在边界上典型的线段树区间合并View Code #include<cstdio>#include<cstring>#include<vector>#include<map>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int max
阅读全文
摘要:BRMQ+LCA+边双连通View Code #include<string.h>#include<stdio.h>#include<vector>#include<math.h>using namespace std;const int M =100100;const double inf = 1e20;inline int min(int a,int b){return a<b?a:b;}int tdfn,tot;int dp[20][2*M],vis[M];int B[2*M],LOG[2*M],used[M],F[2*M],pos[
阅读全文
摘要:iterator lower_bound( const key_type &key ) 函数用法,返回一个迭代器,指向键值>= key的第一个元素。iterator upper_bound( const key_type &key ) 函数用法,返回一个迭代器,指向键值> key的第一个元素。
阅读全文
摘要:View Code struct PP{ int len,num; bool operator<(const PP &b) const{ return len > b.len; }}dis[30010];priority_queue<PP> Q;int vis[30010];void dijkstra(){ while(!Q.empty()) Q.pop(); int i,j,k; PP tmp; memset(vis,0,sizeof(vis)); for(i=1;i<=n;i++) { dis[i].num=...
阅读全文
摘要:在别人的和擦粉约束列表里搜到的这题,看完题目果断感觉是水题根据s[b]-s[a]<=c来建图最后是求s[n]-s[1]的最大值,从1出发走一遍到n的最短路径就好但是超时了,果断不能接受。。。。别人的做法:用栈来代替spfa的队列,或者用dijkstra+heap来做。。晕倒,总之,又学到了一点。。。View Code #include<stdio.h>#include<stack>#include<string.h>using namespace std;const int INF = 9999999;struct NODE{ int v,w; int
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 using namespace std; 5 struct node{ 6 char s[20]; 7 int canshu; 8 int priority; 9 int num;10 bool operator < (const node&b) const{11 if(priority==b.priority)12 return num>b.num;13 ...
阅读全文
摘要:每次选取堆里面最短的两根木头相加,再将所得和重新加入堆中,直到堆的size小于2View Code #include<queue>#include<stdio.h>#include<string.h>#include<vector>using namespace std;struct mycmp{ bool operator()(const int &a,const int &b) { return a>b; }};int main(){ priority_queue<__int64,vector<__int64
阅读全文
摘要:View Code #pragma warning (disable : 4786)#include<stdio.h>#include<map>#include<string>#include<iostream>using namespace std;int main(){ char str[50]; double num=0; map<string,int> M; while(gets(str)!=NULL) { M[str]++; num++; } map<string,int>::iterator it; for..
阅读全文
摘要:View Code #include<queue>#include<iostream>#include<vector>using namespace std;struct mycmp{ bool operator()(const int &a,const int &b) { return a>b; }};//这里表示从小到大排列,最小的数在队头,随时准备走出队列int main(){ int n,k,val; char str[5]; int count; while(scanf("%d%d",&n,&
阅读全文

浙公网安备 33010602011771号