09 2013 档案
摘要:代码:#include#include#include#includeusing namespace std;const int maxn = 100000 + 100;const int maxlog = 20;int a[maxn],num[maxn],Left[maxn],Right[maxn];int counts[maxn];int n,q;int segcnt;struct RMQ{ int d[maxn][maxlog]; void init() { memset(d,-0x3f,sizeof(d)); for(int i=1; i>...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768算法思路:最核心的就是找到前n个人的传单数总和可以二分。代码:#include#include#include#includeusing namespace std;const int maxn = 20002;long long A[maxn],B[maxn],C[maxn];int N;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); while(cin>>N) { long l
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率。算法思路:n个草莓在圆形上有一个最左边的,为了好理解,先把假设草莓有1-n的不同编号。 现在从n个草莓中选出一个编号A的放在最左边(这个最左边可以随便放),得到C(n,1)*1.然后把其余的n-1草莓不分先后的放在A的右边角大小为(360)/m的扇形区域内就可以了。 所以概率为 n/(m^(n-1));由于20^20超 long long了,所以要用高精度。而且要约分。代码:#include#inc
阅读全文
摘要:题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1046参考博客:http://hi.baidu.com/cloudygoose/item/21fee021a5db348d9d63d17b参考资料(向量的旋转):http://www.cnblogs.com/woodfish1988/archive/2007/09/10/888439.html题目大意:就是已知n个点,n个角。点Mi可以与多边形Ai和Ai+1构成等腰三角形,顶角为ang[i]. 现在要你求出这个多边形的n的顶点。算法思路:刚开始想几何性质,怎么也想不出来一个好的思路。没
阅读全文
摘要:题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1043题目大意:一个2000*2000方格坐标,x,y范围都是【-1000,1000】。现在给你一个圆弧,告诉你圆弧的两个端点和任意一个中间点。现在要你算出最小的矩形(长和宽都要为整数,即四个顶点在方格顶点上)来完全覆盖这个圆弧。算法思路:很明显要算出圆心,这个可以有线段中垂线交求,也可以由方程,只是很麻烦。然后以圆心找出这个圆的左右上下四个极点,判断是否在圆弧上(用叉积即可),与给出的三个点一起维护这段圆弧的四个方向的极大点。然后向上向下取整即可。代码:#include#includ
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/337/D参考博客:http://www.cnblogs.com/chanme/p/3265913题目大意:给你一个n个点的无向树。任意两点的距离为中间经过的边数。现在某个点上有本魔法书,这本书对与这个点距离小于等于d的点有影响。给你收集到的m个受影响的点(信息不一定全对)。要你判断有多少个点可能放魔法书。算法思路:我参考别人的想法,自己开始怎么也想不出好的算法,n也太大。这题用树形dp,两遍dfs来统计出每一个点到所有这个m个受影响点的距离的最大值。只要这个最大值#include#include#in
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/212/E题目大意:给你一个无向树,现在用两种颜色去给这颗树上的节点染色。用(a,b)表示两种颜色分别染的节点数。满足以下条件:1.任何一种颜色至少使用一次,即a>=1&&b>=1。2.两种颜色染的节点不能相邻,即不能有边的两端染不同色。要你使a+b值最大下输出不同的(a,b),按照a升序输出。算法思路:很容易得出一个结论:a+b的最大值就是取n-1,即只有一个点不染色。我们就想到树形dp。先dfs求出以每个节点为根的树的节点数。假如我们讨论以u为根的树的染色方案,我们就要知
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1057题目大意:在二维矩阵中,给你一个起点和至多15个的目标点。要你求出从起点出发经过完所有的点后回到起点的最短路径值。每个点一步可以向 八个方向走。算法思路:一看就觉得是tsp,用状态压缩。而任意两点的距离就是相应横纵坐标差的较大值。具体看代码。代码:#include#include#include#includeusing namespace std;const int maxn = 1>T; for(int cas=1; cas>m>>n; char s
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1051题目大意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上的元音字母或者连续五个以上的辅音字母,则这个字符串是bad,不然就是good.‘?’号可以替换任意字母。替换以后如果既可以出现连续三个以上的元音字母或者连续五个以上的辅音字母,也可以不出现,则输出Mixed.算法思路(参考别人的):这个地方出现不含‘?’的连续三个以上的元音字母或者连续五个以上的辅音字母则为BAD, 如果含‘?’,则看替换后的情况。具体看代码。代码:#include#include.
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值。现在要你破坏任意一个边(要付出相应边权值的代价),使得至少有两个连通块。输出最小代价值。算法思路:这题坑多,要考虑仔细:1.图是边双连通图,就做不到删除一边得到两个连通块,这种情况输出-1. 2.图是连通但不边双联通,就用tarjan找出桥中权值最小的,这里有个巨坑,如果桥最小的权值为0,这时根据题意,要输出1而不是0(看看题就能理解)。3.图不是连通的,就不需要去删边,即直接输出0。4.还要注意,输入的边有可能出现重边,这个要.
阅读全文
摘要:#include #include #include #include #include #include #include #include using namespace std;const int maxw = (1=0; k++){ dp[i][j] += dp[i-1][j-k*(1=0) dfs(n-1,w-num[n]*(1>T; for(int cas=1; cas<=T; cas++) { scanf("%d %d",&A,&B); getW(A); //得到A的...
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/219/D#include#include#include#include#include#includeusing namespace std;const int maxn = 2*1e5+100;int dp[maxn]; //dp[i]表示以i为根遍历全部的点的最小的权值。struct Edge{ int u,v,w; int next; Edge(int u=0,int v=0,int w=0,int next=0): u(u), v(v), w(w), next(next)...
阅读全文
摘要:#include#include#include#include#includeusing namespace std;const int maxn = 100;int dp[maxn][maxn]; //dp[i][j]表示以i为根,保留j个点的最大权值。int N,Q;int G[maxn][maxn];int num[maxn]; //以i为根的树的节点个数。//这里处理的时候要注意可以把边的权值压倒儿子节点。void dfs(int u,int fa){ num[u] = 1; for(int v=1;v0;i--){ //相对于下面的V -> 0 ...
阅读全文
摘要:题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1332#include#include#include#include#include#includeusing namespace std;const double eps = 1e-8;const double PI = acos(-1.0);const double INF = 1000000000000000.000;struct Point{ double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函...
阅读全文
摘要:题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1333#include#include#include#include#include#includeusing namespace std;const double eps = 1e-8;const double PI = acos(-1.0);const double INF = 1000000000000000.000;struct Point{ double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函...
阅读全文
摘要:#include#include#include#include#include#includeusing namespace std;const double eps = 1e-8;const double PI = acos(-1.0);const double INF = 1000000000000000.000;struct Point{ double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函数};typedef Point Vector;Vector operator + (Vector A , ...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1228#include#include#include#include#include#includeusing namespace std;const double eps = 1e-8;const double PI = acos(-1.0);const double INF = 1000000000000000.000;struct Point{ double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函数};typedef Point Ve...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717说明下为啥满足三分:设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y的变化。则f(x)函数单调性有两种:1.先单减,后单增。2.一直单增。设y=m(x) (x>0)表示随时间x的增长,所有点的最大距离y的变化。即m(x)是所有点对构成的f(x)图像取最上面的部分。则m(x)的单调性也只有两种可能:1.先单减,后单增。2.一直单增。 这个地方的证明可以这样:假如时刻t1到时刻t2最大值取得是函数f1(x)的图像,在时刻t2到时刻t3取得是f2(x)的图像,那么由图
阅读全文
摘要:#include#include#include#include#include#includeusing namespace std;const double eps = 1e-8;const double PI = acos(-1.0);const double INF = 100000000.000000;struct Point{ int index; double x,y; Point(double x=0, double y=0) : x(x),y(y){ } //构造函数};typedef Point Vector;Vector operator + (V...
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 100000;const int maxn = 205;const int INF = 0x3f3f3f3f;struct Edge{ int u,v,flow,cap,cost; int next; Edge(int u=0,int v=0,int flow=0,int cap=0,int cost=0,int next=0): u(u), v(v), flow...
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 100000;const int maxn = 305;const int INF = 0x3f3f3f3f;int dist[maxn][maxn];int N,M,K;const int Max = 1000000;struct Edge{ int u,v,flow,cap,cost; int next; Edge(int u=0,int v=0,int flow=0,in...
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1037#include#include#include#includeusing namespace std;const int maxn = 1>T; for(int cas=1; cas>N; for(int i=0; i0) add++; dp[S|1<<j] = min(dp[S|1<<j],dp[S] + add); } } } prin...
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 200010;const int maxn = 100010;const int INF = 0x3f3f3f3f;struct Edge{ int u,v,w; int next; Edge(int u=0,int v=0,int w=0,int next=0): u(u), v(v), w(w) ,next(next){}};struct Heap{ int u,le...
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 65;const int INF = 0x3f3f3f;char G[maxn][maxn];bool vis[maxn][maxn];int ans;int N;int main(){ //freopen("E:\\acm\\input.txt","r",stdin); while(scanf("%d
阅读全文
摘要:#include#include#include#include#include#includeusing namespace std;const int maxe = 50000;const int maxn = 17;const int INF = 0x3f3f3f;vector l[maxn];vector r[maxn];char s[maxn];inline int cal(int a,int b){ int ret = 0; for(int i=a;i=2;i--){ for(int j=N+1;j>i;j--){ ...
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 100500;const int INF = 0x3f3f3f;double dp[maxn];int map[maxn];int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int N,M; while(cin>>N>>M &am
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1036#include #include #include #include #include #include #include using namespace std;const int maxn = 505;int m,n;int dp[maxn][maxn][2];int leftsum[maxn][maxn],upsum[maxn][maxn];int main(){ //freopen("E:\\acm\\input.txt","r"
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1033#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 105;const int INF = 0x3f3f3f;int dp[maxn][maxn]; //dp[i][j]表示字符串中从i到j最少要添加的字母个数。int main(){ //freopen("E:\\acm\\.
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1032#include #include #include #include #include #include #include using namespace std;const int maxn = 33;const int INF = 0x3f3f3f;long long dp[maxn];int sum[9] = {0,0,0,1,1,1,2,4,4};long long int N;inline long long res(int i){ return (1>T..
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4293#include#include#include#includeusing namespace std;const int maxn = 506;int G[maxn][maxn];int dp[maxn]; //dp[i]表示前i个人,最大有多少个人没撒谎。int main(){ //freopen("E:\\acm\\input.txt","r",stdin); int N; while(cin>>N){ memset(G,0,sizeo
阅读全文
摘要:题目链接:http://poj.org/problem?id=2449#include#include#include#include#includeusing namespace std;const int maxn = 1005;const int maxe = 100050;const int INF = 0x3f3f3f3f;struct Edge{ int v,w; int next; Edge(int v=0,int w=0,int next=0): v(v), w(w), next(next){}};struct Heap{ int u,f...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4284#include#include#include#includeusing namespace std;const int maxn = 105;const int maxm = 16;const int INF = 0x3f3f3f3f;int dp[maxm][1>T; while(T--){ cin>>N>>M>>Money; for(int i=0;i w) dist[u][v] = dist[v][u] = w; //...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283#include#include#include#includeusing namespace std;const int maxn = 105;const int INF = 0x3f3f3f3f;int dp[maxn][maxn];//dp[i][j]表示只考虑编号为i到编号为j的人上场的最小不开心值;//枚举i第K(1=>T; for(int cas=1;cas>N; sum[0] = 0; for(int i=1;i=1;i--) ...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2288#include#include#include#includeusing namespace std;const int maxn = 13;typedef long long int ll_int;ll_int dp[maxn][maxn][1>T; while(T--){ int n,m; cin>>n>>m; memset(G,0,sizeof(G)); memset(dp,0,sizeof(dp)); memset(way,0,sizeof...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287#include#include#include#includeusing namespace std;const int maxn = 5500;const int maxm = 1e6;int num[maxm];int map[26] = { 2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9 };int a[7] = {1,10,100,1000,10000,100000};int main(){ //freopen("E:
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280#pragma comment(linker, "/STACK:1024000000,1024000000")#include#include#include#include#includeusing namespace std;const int maxn = 100005;const int maxe = 500000;const int INF = 0x3f3f3f;struct Edge{ int v,flow,cap; int next; Edge(int v=0
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4278#include#include#include#includeusing namespace std;int map1[11] = {0,1,2,0,3,4,5,6,0,7,8};int map2[11] = {1,8,64,512,4096,32768,262144,2097152,16777216,134217728,1073741824};int main(){ //freopen("E:\\acm\\input.txt","r",stdin);
阅读全文
摘要:#include#include#include#includeusing namespace std;const int INF = 32000;const int maxn = 105;int a[maxn];char ans[maxn]; //a[i] = 1代表+,2代表-,3代表*,4代表/ ;int len,goal;bool vis[maxn][INF+1][2]; // vis[i][j][1]=1 表示计算完前i个数字的某种组合可以得到正j,dp[i][j][0]=1则为负jbool dfs(int u,int sum){ if(u == 1){ i...
阅读全文