随笔分类 - uva
摘要:01背包,输出方案#include#include#include#define maxn 100009using namespace std;int f[maxn];int num[30];int g[30][maxn];int cot[30];int main(){ int n,v; int sum; while(scanf("%d",&sum)!=EOF) { scanf("%d",&n); memset(f,0,sizeof f); memset(g,0,sizeof g); for(int i=1;i=0...
阅读全文
摘要:这是一个线段树的题目;我记得一个月前在cf上也做过一个类似的题目; 1 #include 2 #include 3 #include 4 #define maxn 100010 5 #define bon 1000010 6 using namespace std; 7 int cover[bon=0)21 {22 cover[rt=0) return cover[rt];30 int mid=(l+r)>>1;31 pushdown(rt);32 if(x=r)39 {40 cover[rt]=i;41 ...
阅读全文
摘要:dp,用优先队列存,上个节点节点覆盖下来的长度;不过还不是很明白; 1 #include 2 #include 3 #include 4 #define maxn 1005 5 #define inf 999999 6 using namespace std; 7 struct node 8 { 9 int id;10 int v;11 node(int id=0,int v=0):id(id),v(v){}12 bool operatort.v;15 }16 };17 priority_queueq1,q2;18 19 int f[maxn],a[ma...
阅读全文
摘要:一个简单的搜索;反正树的结构不会变,只需要把节点的名称换一下就行;可惜比赛的时候思路不清晰; 1 #include 2 #define maxn 5050 3 #include 4 #include 5 #include 6 using namespace std; 7 int age[maxn]; 8 int biao[maxn]; 9 bool vis[maxn];10 vectorve[maxn],pa[maxn];11 char s[10];12 int ans;13 void dfs(int x,int v)14 {15 vis[x]=1;16 pa[v].push_...
阅读全文
摘要:利用单调性求最短连续子序列的和大于等于s; 1 #include 2 #include 3 #include 4 #define maxn 100009 5 using namespace std; 6 7 int sum[maxn]; 8 int main() 9 {10 int n,s,x;11 while(scanf("%d%d",&n,&s)!=EOF)12 {13 memset(sum,0,sizeof sum);14 int ans=n+1;15 for(int i=1;isum[i]-s)continue;...
阅读全文
摘要:扫描线,注意这个题目要求的是开区间; 1 #include 2 #include 3 #define maxn 100009 4 using namespace std; 5 6 void update(int x,int a,int w,double& l,double& r) 7 { 8 if(a==0) 9 {10 if(x=w)r=l-1;11 }12 else if(a>0)13 {14 l=max(l,-(double)x/a);15 r=min(r,(double)(w-x)/a);16 ...
阅读全文
摘要:求最大的公共前缀;用后缀数组做;其实暴力也可以过; 1 #include 2 #include 3 #include 4 #define maxn 2009 5 using namespace std; 6 7 int s[maxn]; 8 int sa[maxn],t[maxn],t2[maxn],c[maxn],n; 9 10 void build_sa(int m) 11 { 12 int *x=t,*y=t2; 13 for(int i=0; i=0; i--)sa[--c[x[i]]]=i; 17 for(int k=1; k=k)y[p...
阅读全文
摘要:非常容易的一个题;只要判断两种基因相差的最小值就行; 1 #include 2 #include 3 #include 4 using namespace std; 5 6 bool a[105],b[105]; 7 int x,y; 8 9 int main()10 {11 int n,ca=1;12 while(scanf("%d",&n)==1)13 {14 memset(a,0,sizeof a);15 memset(b,0,sizeof b);16 bool flag=0;17 while(n...
阅读全文
摘要:模拟题;比赛的时候忘记把1变成64位的1了,跪了好久; 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 unsigned long long val[250]; 8 int num[250]; 9 mapmp;10 char s[100];11 char jkl[111];12 int main()13 {14 int d,b,v;15 while(scanf("%d%d",&b,&v)!=EOF)16 {17 mp.clear();18 fo...
阅读全文
摘要:大水题,不解释啦! 1 #include 2 #include 3 #define maxn 50 4 using namespace std; 5 6 char s[maxn],t[maxn]; 7 8 int main() 9 {10 int tt,ca=1;11 scanf("%d",&tt);12 getchar();13 while(tt--)14 {15 gets(s);16 gets(t);17 int l1=strlen(t);18 int l2=strlen(s);19...
阅读全文
摘要:最小生成树,然后看他有多少个连通分量,每个连通分量有个飞机场,最后看所有剩下的边是否有大于飞机场的费用,有的话,改成飞机场;比赛的时候一直没想明白,╮(╯▽╰)╭; 1 #include 2 #include 3 #include 4 #define maxn 100009 5 using namespace std; 6 int n,m,a; 7 struct edge 8 { 9 int u,v,w;10 bool operator=a)53 {54 num++;55 ans-=pen[...
阅读全文
摘要:对x的坐标三分; 1 #include 2 #include 3 #define maxn 10009 4 using namespace std; 5 double a[maxn],b[maxn],c[maxn]; 6 int n; 7 double f(double x) 8 { 9 double ans=-999999999.0,t;10 for(int i=0;i<n;i++)11 {12 t=a[i]*x*x+b[i]*x+c[i];13 ans=max(ans,t);14 }15 return ans;16 }...
阅读全文
摘要:半平面交,二分;注意,题目的点是顺时针给出的; 1 #include 2 #include 3 #include 4 #define maxn 50010 5 #define eps 1e-6 6 using namespace std; 7 8 int dcmp(double x) 9 { 10 return fabs(x) 0 ? 1 : -1); 11 } 12 13 struct Point 14 { 15 double x; 16 double y; 17 Point(double x = 0, double y = 0):x(...
阅读全文
摘要:半平面交的题;这个题目的亮点就是建模; 1 #include 2 #include 3 #include 4 #define maxn 109 5 #define eps 1e-6 6 using namespace std; 7 8 int dcmp(double x) 9 { 10 return fabs(x) 0 ? 1 : -1); 11 } 12 13 struct Point 14 { 15 double x; 16 double y; 17 Point(double x = 0, double y = 0):x(x), y(...
阅读全文
摘要:半平面的交,二分的方法; 1 #include 2 #include 3 #include 4 #define eps 1e-6 5 using namespace std; 6 7 int dcmp(double x) 8 { 9 return fabs(x) 0 ? 1 : -1); 10 } 11 12 struct Point 13 { 14 double x; 15 double y; 16 Point(double x = 0, double y = 0):x(x), y(y) {} 17 }; 18 typedef Poin...
阅读全文
摘要:旋转卡壳算法;直接在这个上面粘的模板主要用途:用于求凸包的直径、宽度,两个不相交凸包间的最大距离和最小距离···这题就是求凸包的直径 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 1...
阅读全文
摘要:当退化成点和线段的时候,可以不进行特判;因为这种情况已经包括进条件1.2里面了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 ...
阅读全文
摘要:凸包+一点直线的知识; 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 double y; 19 20 Point(...
阅读全文
摘要:主要是凸包的应用; 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 double y; 19 20 Point(do...
阅读全文
摘要:这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖;如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见;然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见,并且可以把这条圆弧下面的第一个圆重新标记为可见;另外,圆弧可见还是不可见利用它的中点来进行判断; 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 const int maxn = 100 + 10; 10 const double eps = 1e-1...
阅读全文