01 2019 档案
摘要:1 //贪心+优先队列(二叉堆) 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int N=1000050; 8 #define val first 9 #define dis second 10 int T,n,l,s,ans,now; 11 typedef pair p;...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 const int size=1000020,p=131; 6 typedef unsigned long long ULL; 7 ULL f[size],key[size]; 8 int T; 9 char tmp1[size],tmp2[size]; 10 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 #define key1 first 4 #define key2 second 5 const int size=2048,p1=131,p2=13331; 6 const int mod1=1e6+3,mod2=1e6+33;//两个大质数 双hash 7 int n,ans; 8 char tmp[s...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int size=1000005,p=131; 4 typedef unsigned long long ULL;//自然溢出 5 ULL f[size],key[size]; 6 int n,T,l1,r1,l2,r2; 7 char tmp[size]; 8 int main(){ 9 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxv=1000; 4 int v[7]={0,1,2,3,5,10,20},w[1005],num[7],tot,f[1005],ans; 5 int main() 6 { 7 scanf("%d%d%d%d%d%d",&num[1],&num[2],&num[3],&num[4...
阅读全文
摘要:1 //拓扑排序 坑点多 考验语文水平 2 #include 3 #include 4 using namespace std; 5 const int maxn=105,maxm=10005; 6 queue q; 7 struct edge{ 8 int to,dis;edge *Nex; 9 }e[maxm],*head[maxn]; 10 int top=-1;...
阅读全文
摘要:1 //拓扑排序求最长路 2 #include 3 #include 4 using namespace std; 5 const int INF=0x3f3f3f3f; 6 const int maxn=1505; 7 const int maxm=50005; 8 struct edge{ 9 int dis,to;edge *Nex; 10 }tmp[maxm]...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 int n,len_ans=1,ans; 5 int a[maxn],d[maxn],len[maxn],f[maxn]; 6 int search(int l,int r,int val) 7 { 8 while(l>1; 11 if(d...
阅读全文
摘要:1 //拓扑排序 2 #include 3 #include 4 using namespace std; 5 const int maxn=100005; 6 const int maxm=200005; 7 struct edge{ 8 int to;edge *Nex; 9 }tmp[maxm],*head[maxn]; 10 int top=-1; 11 bo...
阅读全文
摘要:1 //01背包 价值等于体积 求所剩最小体积 2 #include 3 using namespace std; 4 const int maxn=35; 5 const int maxv=20005; 6 int c,n,v[maxn],f[maxv]; 7 int main() 8 { 9 scanf("%d%d",&c,&n); 10 for(int ...
阅读全文
摘要:1 //01背包 价值等于体积 2 //该题卡常 优化:当价值(体积)已超过背包容积时直接输出背包容积 3 #include 4 using namespace std; 5 const int maxn=5005; 6 const int maxv=50005; 7 int c,n,v[maxn],f[maxv]; 8 int main() 9 { 10 scanf...
阅读全文
摘要:1 //01背包 求背包内物品价值超过某一定值时的最小体积 2 #include 3 using namespace std; 4 const int maxv=10005; 5 const int maxn=10005; 6 int n,v_tot,w_tot,v[maxn],w[maxn],f[maxv],sumv,bound; 7 int main() 8 { 9 ...
阅读全文
摘要:1 //并查集+01背包 2 //用并查集把几件物品合为一件 3 #include 4 using namespace std; 5 const int maxn=10005; 6 const int maxv=10005; 7 int n,m,v_tot,tot,v[maxn],w[maxn],dp[maxv]; 8 struct node{ 9 int fa,c...
阅读全文
摘要:1 //依赖关系最多2种 可以用分组背包水过 2 #include 3 using namespace std; 4 #define w first 5 #define v second 6 const int maxv=32005; 7 const int maxn=65; 8 int n,m,k,tot,f[maxv],ID[maxn]; 9 vector >d[m...
阅读全文
摘要:1 //分组背包 2 #include 3 using namespace std; 4 int n,m,k,tot,f[1005];//tot-组数 5 vector >d[105]; 6 int main() 7 { 8 scanf("%d%d",&m,&n); 9 for(int i=1,x,y,z;i=0;--j)//注意三层循环顺序 12 ...
阅读全文
摘要:1 //二维费用背包 2 #include 3 using namespace std; 4 const int maxn=55; 5 const int maxv1=405; 6 const int maxv2=405; 7 int v1[maxn],v2[maxn],w[maxn],n,v1_tot,v2_tot,f[maxv1][maxv2]; 8 int main() ...
阅读全文
摘要:1 //01背包 价值等于重要度乘体积 2 #include 3 using namespace std; 4 const int maxv=30005; 5 const int maxn=10005; 6 int n,m,v[maxn],w[maxn],f[maxv]; 7 int main() 8 { 9 scanf("%d%d",&m,&n); 10 f...
阅读全文
摘要:1 //完全背包 2 #include 3 using namespace std; 4 const int maxv=100005; 5 const int maxn=10005; 6 int n,m,v[maxn],w[maxn],f[maxv]; 7 int main() 8 { 9 scanf("%d%d",&m,&n); 10 for(int i=1...
阅读全文
摘要:1 //求方案数 定义状态f[i][j] 用前i件物品恰好放够体积为j的背包 方案数 2 #include 3 using namespace std; 4 const int maxm=10005; 5 const int maxn=105; 6 int n,m,v[maxn],f[maxn][maxm]; 7 int main() 8 { 9 scanf("%d%...
阅读全文
摘要:1 //01背包 2 #include 3 using namespace std; 4 const int maxv=1005; 5 const int maxn=105; 6 int n,v_tot,v[maxn],w[maxn],f[maxv],sumv,bound; 7 int main() 8 { 9 scanf("%d%d",&v_tot,&n); 10 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 vector q; 4 int n,opt,x; 5 int main() 6 { 7 scanf("%d",&n); 8 while(n--) 9 { 10 scanf("%d%d",&opt,&x); 11 switch(opt) 12 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=1005; 4 const int maxm=3005; 5 struct edge{int to,nex;}e[maxm]; 6 int head[maxn],tot; 7 int deep[maxn],f[maxn][30]; 8 int T,n,m,q; 9 inline...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 const int maxm=200005; 5 struct node{ 6 int cnt,fa; 7 }f[maxn]; 8 inline void read(int &tmp) 9 { 10 int x=1;char c=getchar(...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 const int INF=0x3f3f3f3f; 5 inline void read(int &tmp) 6 { 7 int x=1;char c=getchar(); 8 for(tmp=0;!isdigit(c);c=getchar()) ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=505; 4 const int maxm=100005; 5 int n,k,sum,tot; 6 struct node{ 7 int cnt,fa; 8 }f[maxn]; 9 int find(int x){return f[x].fa==x?x:f[x].fa...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5050; 4 const int maxm=5000005; 5 int n,m,k,ans; 6 double Max; 7 int monkey[maxn]; 8 typedef pair P; 9 P point[maxn]; 10 #define Dis(x,y) (...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=505; 4 const int maxm=100005; 5 int n,k,Max,tot; 6 struct node{ 7 int cnt,fa; 8 }f[maxn]; 9 int find(int x){return f[x].fa==x?x:f[x].fa...
阅读全文
摘要:1 #include 2 using namespace std; 3 typedef long long ll; 4 ll m,n,x,y,l,t,k,d; 5 void exgcd(ll a,ll b,ll &x,ll &y) {if(!b) {x=1;y=0;d=a;return;}exgcd(b,a%b,y,x);y-=x*(a/b);} 6 int main() 7 { ...
阅读全文
摘要:1 /* 2 性质:一个树里,删掉n条边一定出现n+1个连通块 3 若删去无向连通图中所有权值大于m的边,原图被分割成k个连通块,则最小生成树也被分割成k个联通块 4 */ 5 #include 6 using namespace std; 7 const int maxn=505; 8 const int maxm=250005; 9 struct node{int cn...
阅读全文
摘要:1 /* 2 用kuskal会被卡 3 一边prim一边算两点间距离(边权) 4 否则会MLE 5 另:不开long long见祖宗 6 */ 7 #include 8 using namespace std; 9 const int maxn=5005; 10 const int INF=0x3f3f3f3f; 11 typedef pair P; 12 priority...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=500005; 4 inline void read(int &tmp) 5 { 6 int x=1;char c=getchar(); 7 for(tmp=0;!isdigit(c);c=getchar()) if(c=='-') x=-1; 8 for...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=10005; 4 const int maxm=100005; 5 const int INF=0x3f3f3f3f; 6 inline void read(int &tmp) 7 { 8 int x=1;char c=getchar(); 9 for(tmp...
阅读全文
摘要:1 #include 2 using namespace std; 3 inline void read(int &tmp) 4 { 5 int x=1;char c=getchar(); 6 for(tmp=0;!isdigit(c);c=getchar()) if(c=='-') x=-1; 7 for(;isdigit(c);tmp=tmp*10+c-...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 struct data{ 6 int ID,Time_A,Time_B,rank; 7 inline data(int ID=0,int Time_A=0,int Time_B=0,int rank=0): 8 ID(ID),Time_A(T...
阅读全文