1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that ton…
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the…
几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=10005; int n,m,h[N],cnt,ans,tmp,dfn[N],low[N],s[N],top; bool v[N]; struct qwe { int ne,to; }e[N*10]; int read() { i…
http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句话没啥用.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the…
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the…
Description 约翰的N(2≤N≤10000)只奶牛非常兴奋,因为这是舞会之夜!她们穿上礼服和新鞋子,别上鲜花,她们要表演圆舞.     只有奶牛才能表演这种圆舞.圆舞需要一些绳索和一个圆形的水池.奶牛们围在池边站好,顺时针顺序由1到N编号.每只奶牛都面对水池,这样她就能看到其他的每一只奶牛.为了跳这种圆舞,她们找了M(2≤M≤50000)条绳索.若干只奶牛的蹄上握着绳索的一端,绳索沿顺时针方绕过水池,另一端则捆在另一些奶牛身上.这样,一些奶牛就可以牵引另一些奶牛.有的奶牛可能握有很多绳…
裸的强连通 ; type node=record f,t:longint; end; var n,m,dgr,i,u,v,num,ans:longint; bfsdgr,low,head,f:array[..maxe] of longint; b:array[..maxe] of node; p:array[..maxe] of boolean; procedure insert(u,v:longint); begin with b[i] do begin f:=head[u]; t:=v; e…
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm>   using namespace std;   const int maxn = 5009;   struct edge { int…
http://www.lydsy.com/JudgeOnline/problem.php?id=1720 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 177  Solved: 90[Submit][Status][Discuss] Description Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corr…
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afterno…
题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are t…
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶牛们的分数均为0.如果N是奇数,那么奶牛就会把它乘以3后再加1.如果N是偶数,那么这个数就会被除以2.数字每变动一次,这头奶牛就得到1分.当N的值等于1时,游戏结束,此时的分数就是这头奶牛在这局游戏中的最终得分. 以下是N的初始值为5时,一局游戏的完整过程: N 操作后所得数 注释 总分 5 16 3*5+1…
居然要用高精度! 懒得operator了,转移是裸的完全背包 #include<iostream> #include<cstdio> using namespace std; int n,k,f[1005][45]; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(p=='-') f=-1; p=getchar(); } while(p>='0'&&p<…
模拟 #include<iostream> #include<cstdio> using namespace std; int n,ans; int main() { scanf("%d",&n); for(;n>1;ans++) { if(n&1) n=n*3+1; else n>>=1; } printf("%d\n",ans); return 0; }…
本来以为是一道数学题,一顿XJBT导式子,结果就是个幼儿园都会的模拟. Code: #include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ll n; scanf("%lld",&n); int ans=0; for(;n>1;++ans){ if(n%2==0) n>>=1; else n=n*3+1; } printf("%d"…
http://www.lydsy.com/JudgeOnline/problem.php?id=1604 这题太神了... 简直就是 神思想+神做法+神stl.. 被stl整的我想cry...首先,,erase的时候如果没有这个元素......那么.....(TAT)否则你就要先find(重载<)然后要注意multiset,因为你重载的<运算只判<的话会将值相同(假如这是个结构,有多种元素,它只会判断你重载符号的运算满不满足,,而不去匹配其它项..所以会错..)的去掉.....// up…
http://www.lydsy.com/JudgeOnline/problem.php?id=1638 一条边(u, v)经过的数量=度0到u的数量×v到n的数量 两次记忆化dfs算出他们即可 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include…
http://www.lydsy.com/JudgeOnline/problem.php?id=1641 这种水题无意义... #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using namespace std…
Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 <= H <= 1,000,000) of the tallest cow along with…
金组题什么的都要绕个弯才能AC..不想银组套模板= = 题目大意:给n个点,求最小边长使得此正方形内的点数不少于c个 首先一看题就知道要二分边长len 本来打算用二维前缀和来判断,显然时间会爆,而且坐标最大10000是不可行的 为保证效率,检验的时间应该在O(n2) 所以我们先给x排个序,以每个点的x坐标为左边界,x+len-1为右边界 然后以y为关键字从小到大序后枚举点,用双指针法O(n)更新len以内能保存多少个点 点数大于等于c就可行 #include<stdio.h> #include…
Description 给出一个无向图,求将他构造成双连通图所需加的最少边数. Sol Tarjan求割边+缩点. 求出割边,然后缩点. 将双连通分量缩成一个点,然后重建图,建出来的就是一棵树,因为每一条边都是桥. 然后每次合并这棵树上的叶节点两点距离LCA最远的点,这样就会形成一个环,是双连通的,然后进行(ans+1)/2次操作就可以了. 其实就是(叶节点个数+1)/2 Code #include<cstdio> #include<vector> #include<iost…
Description The pasture contains a small, contiguous grove of trees that has no 'holes' in the middle of the it. Bessie wonders: how far is it to walk around that grove and get back to my starting position? She's just sure there is a way to do it by…
[算法]并查集+平衡树+数学+扫描线 [题解] 经典曼哈顿距离转切比雪夫距离. 曼哈顿距离:S=|x1-x2|+|y1-y2|<=c 即:max(x1-x2+y1-y2,x1-x2-y1+y2,-x1+x2+y1-y2,-x1+x2-y1+y2) 令X1=x1+y1,Y1=x1-y1,则转化为 切比雪夫距离:S=max(|X1-X2|,|Y1-Y2|)<=c. 为什么要转化为切比雪夫距离?因为这种形式很容易操作. 想象两者的几何意义,哈夫曼距离<=c是竖着的正方形,而切比雪夫距离<…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1656 题意: 给你一个n*m的地图,'.'表示空地,'X'表示树林,'*'表示起点. 所有'X'为一个连通块. 对于每一个点,你可以向周围八个方向走,均算作一步. 让你找出一条路径,能够将所有'X'包围. 问你路径最短为多少. 题解: bfs + 射线法. 找出最上面(x坐标最小)的一个'X',并向上方作一条射线,标记为'#'. 从起点开始bfs,并且不能穿过射线(即'#'不能到达).…
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1720 坐标值域很大,但是真正涉及的只有\(500\)个,我们可以离散化做.二分长度,直接二维前缀和检查就行了 h时间复杂度:\(O(log10000*n^2*logn)\) 空间复杂度:\(O(n)\) 代码如下: #include <cstdio> #include <…
首先来分析一下,这是一张无向图,要求没有两条路联通的点对个数 有两条路连通,无向图,也就是说,问题转化为不在一个点双连通分量里的点对个数 tarjan即可,和求scc还不太一样-- #include<iostream> #include<cstdio> using namespace std; const int N=5005; int n,m,h[N],cnt=1,x,y,dfn[N],low[N],tmp,s[N],top,bl[N],col,d[N],ans; bool v[…
s[i]为差分后的"i这头牛前有几头比它高",计算答案的时候加成前缀和,假设第一头最高减一下即可 用map记录一下被加过的区间,避免重复 #include<iostream> #include<cstdio> #include<map> #include<algorithm> using namespace std; const int N=10005; int n,q,h,r,s[N],f[N],a,b; map<int,bool…
[题解] 弗洛伊德.更新距离的时候把$f[i][j]=min(f[i][j],f[i][k]+f[k][j])$改为$f[i][j]=min(f[i][j],max(f[i][k],f[k][j]))$. #include<cstdio> #include<algorithm> #include<cstring> #define N (400) #define rg register using namespace std; int n,m,t,a[N][N]; inl…
题目简述:一个有向图,求出这个图点数>1的强连通分量的个数. 那么就是tarjan求强联通分量的模板了. 记得要用一个数组标记节点是否在栈中. 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+10; 4 int head[N],nxt[N<<1],to[N<<1],tot; 5 int dfn[N],low[N],st[N],top,idx,cnt,sze[N]; 6 int n…