12 2012 档案
摘要:枚举,貌似数据量挺大的,其实不大,就看最深层的tot加了多少次,就可估计出真正的规模//枚举
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=2000000000;
int num[10000];
int main()
{ ll i1,i2,i3,i4;//注意long long 因为虽然按理说是不会爆int,相乘这个过程可能会溢出 int tot=0; for(i1=1;i
阅读全文
摘要:直接暴力的话,O(n2),肯定会超时。分解到两个轴上,通过递推求解,O(nlgn)。要理解这种高效求距离的方法。数轴上的某一点到其他点的距离,可通过从小到大或从大到小递推来做。#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll _int64
using namespace std;
const int maxn=100010;
int x[maxn],y[maxn],rx[maxn],ry[maxn];
ll disx[maxn],disy[maxn];
int n;
l
阅读全文
摘要:字符串匹配。kmp.#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int maxn=100010;
char tran[26],s[maxn];
int next[maxn];
void getv(char * t)//求失配函数
{ int i,j;strlen int m=(t); next[0]=-1; i=0;j=-1; while(i<m-1) { if(j==-1||t[i]==t[j]) { j++;i++; if
阅读全文
摘要:我草!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!靠!以后一定要注意注意判断语句的先后顺序,因为粗心,无数次re,居然调了四个小时,时间啊,心疼#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn=200;
int dis[maxn*maxn+10],m,n,map[maxn][maxn],loc[maxn*maxn+10],p
阅读全文
摘要:哈希我太屎啦,以后一定不能再犯写while循环忘了更改循环条件的错误,导致浪费这么长时间来调试#include <iostream>
#include <cstdio>
using namespace std;
const int mod=10000003;
const int maxn=4100;
struct { int data,sum,next;
}node[maxn*maxn];
int head[mod],f[4][maxn],num;
void insert(int p)
{ int k=(p%mod+mod)%mod; int i=head[k]; wh
阅读全文
摘要:素数唯一分解定理#include <iostream>
#include <math.h>
using namespace std;
long long f[15][110];
int t[110];
int main()
{ long long m,n; for(int i=1;i<=10;i++) { t[i]=0; for(int j=0;j<=i;j++) { for(int k=0;k<=i;k++) { long long x=(long long)(pow(2,double(j))*pow(5,double(k))); if(x<(
阅读全文
摘要:贪心,刚做此题时,就意识到了是贪心,但贪心思路一直没找对,wa了n次,在纠结中终于想出正确的思路#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{ int x,y;
};
node f[25];
bool cmp(node a,node b)
{ return a.y*b.x<b.y*a.x;
}
int main()
{ int n; while(cin>>n) { int i; long long am
阅读全文
摘要:贪心+优先队列#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int maxn=50;
int h[maxn],n;
int main()
{ int tot=0; while(cin>>n&&n) { tot++; int i; priority_queue<int> q1; priority_queue<int,vector<int>,
阅读全文
摘要://枚举+贪心+优先队列
//最有的方案肯定是从起点走到某个点终止,然后在这条路上通过贪心选择最优的选择(每个点应停留的时间)。最后通过比较得出最优的方案
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=26;
int t_spent[maxn],eve[maxn][maxn],cost[maxn],d[maxn];
int n,h;
struct node
{ int num
阅读全文
摘要:#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=55;
string f[maxn];
int n;
bool cmp(string a,string b)
{ return a+b>b+a;
}
int main()
{ while(cin>>n&&n) { for(int i=0;i<n;i++) cin>>f[i]
阅读全文
摘要:又是网络流的建模.二分枚举答案。做这道题时,感觉做过类似的,想都没想就用之前的那个思路做了,结果错的。之前的思路就是,先求出任意两点间的最短路径,然后通过当前枚举的限制,把两点间路径在这个限制内的两点直接i连一条双向边。建s,t,s点到所有点连一条有向边,所有点到t连一条有向边。但这思路是错的,因为虽然在建的图中,任何从s到t的一个流的路径中的相临两点是在限制中,但这些满足限制的边可能经过组合就会大于限制,那么通过这条路径的流肯定是不满足限制的,所以给出的限制在这种情况下就完全违背了限制的初衷,也就会得到错误的结果。任何一个牛要走的话,肯定是从一个点i运动到j(j可以为i),中间怎么走的不需要
阅读全文
摘要:先通过dp求出LIS假设为m,也就是经典的LIS问题。就求出了以点i为终点的LIS,即d[i];然后题目要求输出所有点都不重合的LIS的方案。可以通过最大流来求解。可以想到一个从s到t的流对应于一种方案。LIS的终点很显然只能是d值为m的点,所以在模型中只把d值为m的点向终点t连一条有向边。任何一个LIS的起点一定是d值为1的点所以s向d值为1的点连一条有向边。然后对于每一个点i,把j<i且的d[j]+1=d[i],从j想i连一条边,这样每一条从s出发的路都是一个上升子序列,如果到达终点是t则是一个最长上升子序列,然后因为点都只能用一次,所以设定点的容量为1,这样得到的模型一个流就是最终
阅读全文
摘要:最大权独立子集检查了四个小时,最后发现是输出的问题,哎,抓狂#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int maxn=200*2;
const int maxe=maxn*maxn*4;
const int inf=1<<28;
int val[maxn];
int m,n,s,t,tot,clo;
struct Edge
{ int from,to,next;
};
Edg
阅读全文
摘要:最大权闭合图,建议和我一样不知道这个模型的acmer搜一下——国家集训队2007论文集7.胡伯涛《最小割模型》。下面我就谈一下我对最大权闭合图的理解。知道了最大权闭合图的模型后,此题可看做是求最大权闭合图。首先,原图是一些有着权值的点,那么目的就是在这些点中选择一些点,但选一个点i,必须选择它的前提条件的所有点,那么怎么选才能符合这一限制条件呢。那么在点i和i的前提条件的所有点之间连接一条有向边表示有联系。那么现阶段的问题就转换成了在刚建好的图中选择闭合子图,这一闭合图中的点就是要选择的点。然后因为要求权值最大,最终转换成了最大权闭合子图。然后就是最大权闭合子图怎么求。注意到最后所有的点就只有
阅读全文
摘要:很久没有一次a的感觉啦。关键是建模,建一个有b+2个点的网络流,s为0,t为b+1,1--b为各个棚。二分枚举答案。s到各棚的容量为当前可行区间内,可选择此棚的牛的个数,各棚到t的容量为割棚可容纳牛的个数。数据量不大,直接用的EK.#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn=1001;
const int maxe=25;
const int inf=200000000;
int n,b,tot,s,t;
int flow
阅读全文
摘要:哎,被这道题搞死啦,详细解释在代码中//最小割模型。首先建网络流模型,建立源点s和终点t(分别代表这两块不同的芯片),然后把s和每个点之间连一条容量为1,方向从s到点的边(方向
//一定要确定,因为割的容量的定义),然后从每个点到终点连一条容量为1,方向为点到t的边,然后在有联系的
//两点之间建一条容量为1的无向边(即一对容量为1方向相反的有向边)。建图完成。那么,在这个网络流模型中的一个割
//就对应于一种选择方案,而此方案的花费即割的容量。原因如下:先看所有的点都没有联系的情况,那么所有点和s的边
//和t的边这两条边有且仅有一条边在割去的边的集合中,哪条边割去说明点在哪个芯片上,那么割
阅读全文
摘要:一道基础题,却因为这样那样的粗心,用了这么长时间,和uva10086一模一样#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn=1100;
const int maxe=30000;
const int inf=200000000;
struct Edge
{ int from,to,flow,cap,cost,next;
};
int n,m,tot;
int head[maxn
阅读全文
摘要:网络流之最大流。此题的关键就是建模,看了题目之后一点思路都没有,后来在网上看了解题报告后,才明白了这个过程。首先,在原图中抽象出一个新图。新图是由旧图中的每个milking machine到每个cow的最短路径组成,每条最短路径由原图中的各点间的某些路径组成,抽象为新图中的一条路径,此过程通过floyd算法(各顶点间的最短路径)实现。接下来,就是通过二分来枚举答案。通过给出一个流量的上限,给新图的路径的容量cap赋值,如果小于等于上限cap就为1,反之为0。最后就可将问题转化为新图中,从各milk machine(即源点s)到各cow(即终点t)的最大流(一个流就对应与一头牛)(其实还不完整)
阅读全文

浙公网安备 33010602011771号