- 博客(18)
- 收藏
- 关注
原创 食物链
题目 很经典的并查集题目 反集做法:开三倍的数组,分别是吃x的和x吃的。#include <cstdio>#include <iostream>#include <cmath> using namespace std;const int MAXN=200000;int f1[MAXN];int find(int x)//找爸+路径压缩{ if(f1[x]==x) retur
2017-02-26 10:43:11 208
原创 银河英雄传说(带权并查集)(草稿)
题目#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int MAXN=31000;int f[MAXN],min1;int front[MAXN],behind[MAXN];int find(int x){ if(f[x]==x) return x; in
2017-02-22 15:22:56 483
原创 团伙
题目#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int f1[2001],f[2001];int ff(int x) { if(f1[x]!=x) f1[x]=ff(f1[x]); return f1[x]; //找祖宗(路径压缩)}int main()
2017-02-19 09:04:43 273
原创 数组模拟链表
#include <cstdio>#include <iostream>#include <algorithm>#include <vector>using namespace std;int head[1000],next[1000],num[1000];int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i
2017-02-17 17:42:31 577 2
原创 最小生成树(prime)
#include <cstdio>#include <iostream>#include <cstring> using namespace std;int dis[1000],sum=0,f[1000],a[1001][1001],ans[1000][3],p[1000];int main(){ int n,m,t=0; scanf("%d%d",&n,&m); m
2017-02-15 15:50:01 311
原创 裸的tarjan(模板)
#include <cstdio>#include <iostream>#include <vector>using namespace std;vector <int> q[1000];int color[10000],c=0,num=0,low[1000],dfn[1000],top=0,f[1000],s[1000],maxf=-1;void dfs(int x){ dfn
2017-02-15 15:48:46 365
原创 烦人的幻灯片(确实烦人啊)
思路:这也是个类拓扑排序,给区间编号,然后有一个点在其范围,这个区间的入度就增加,每次遍历所有区间,然后挑出入度为1的区间,数组记录,因为他要求按区间顺序输出。#include <cstdio>#include <iostream>using namespace std;struct po{ int x1; int y1; int x2; int y2;
2017-02-09 15:58:57 542
原创 奖金(类拓扑排序)
思路:将有要求的人入度增加,每次遍历所有点,将入度为0的点挑出来,记录在一个数组中,最后在删除其出度,每轮循环发工资钱数加1便可以保证总工资最少了。#include <cstdio>#include <iostream>using namespace std;int r[100000],c[100000][1000],sum=0,d[1000000];int main(){ int
2017-02-09 15:47:45 593
原创 能量项链
题目 思路跟合并石子一毛一样呢#include <cstdio>#include <iostream>using namespace std;int n;int a[1000],f[1000][1000];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { int x; scanf
2017-02-08 15:56:15 289
原创 金明的预算方案
题目 分析一下,若想选附件,必然要选其主件,看上去是个依赖背包问题,也就是树形DP,但是这个题目限制了一个问题,也就是一个主件至多有2个附件,那么也就只有4种方案,只选主件,选主件和附件1,选主件和附件2,选主件和附件1和附件2。只有4种方案,所以将其转化成为一个组合背包问题。#include <cstdio>#include <iostream>#include <cstring>usin
2017-02-08 11:08:29 852
原创 乌龟棋
记忆化(330ms)?#include <cstdio>#include <iostream>using namespace std;int s[1000],n,m,ss[6][2],dp[40][40][40][40];int dfs(int i,int s1,int s2,int s3,int s4){ if(i==n) return 0; if(s1!=0)
2017-02-08 09:18:03 284
原创 n皇后(位运算版)
其实我也没觉得多快233333333#include <cstdio>#include <iostream>#include <algorithm>#include <queue> using namespace std;int uplimit,sum=0,x=0,n;int a[20];queue <int> que;void print()//输出函数{ for(int
2017-02-07 15:08:20 301
原创 数字三角形
题目 分析一下,不难发现,其实这几个数系数是对应行数杨辉三角形的数(又是这破东西!!!)然后判断一下算出来的数比sum大还是小剪一下枝就行了#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;int n,k;int a[1000],yh[1000][1
2017-02-07 09:24:09 210
原创 01迷宫
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>using namespace std;int n,m;char map[1002][1002];int dx[5]={0,1,-1,0,0},dy[5]={0,0,0,1,-1};int f[1002
2017-02-06 17:11:07 480
原创 抓住那头牛
链接#include <cstdio>#include <iostream>using namespace std;int x1,x2,min1=0;struct n{ int pos; int time;}d[200000];int f[200000];int main(){ scanf("%d%d",&x1,&x2); d[1].pos=x1;
2017-02-06 11:40:23 283
原创 算24
题目#include <cstdio>#include <iostream>#include <cstring>#include <math.h>using namespace std;double a[5];bool f[5];const double p=0.000001;bool dfs(int x)//bool型容易判断有无方案{ if(x==4)//第一个数钦定了
2017-02-06 09:45:53 327
原创 靶状数独
靶状数组题目链接 90分,而且超时很严重,与或运算不会23333333int len=max(a1[0],b1[0])+1; while(len>0 && !c[len]) len--; printf("%d",c[len]); for(int i=len-1;i>=1;i--) { printf("%03d",c[i]); } 16:26
2017-02-05 16:45:05 364
原创 QBXT的总结(day 1)
1搜索: 先写出基本的搜索模板,然后将大小变量放入dfs返回值去,根据dfs中变量的数量开相应维数的数组,写出记忆化搜索,再根据边界条件和记忆化搜索写出dp。 2差值维护: 给定n个数ai,有m次操作,每个操作是给al~ar增加一个数k。最终输出操作完后的这n个数的值。首先令s[i]=a[i]-a[i-1]。那么a[i]=a[i-1]+s[i]。每次令s[l]+=k,s[r+1]-=k。最后由
2017-02-04 10:49:23 265
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人