USACO 2017 February Gold】的更多相关文章

那天打cf前无聊练手 T1.Why Did the Cow Cross the Road 题目大意:N*N的矩阵,从左上角走到右下角,走一步消耗T,每走3步消耗当前所在位置上的权值,求最小消耗 思路:好像很傻逼但我不会做,写BFS写着写着写成SPFA,管他呢,过了就行(大致就是每个点拆成三个,就能知道什么时候要加上额外的权值) #include<cstdio> #include<algorithm> using namespace std; <<],*S=B,C;int…
Link: USACO 2017 Dec Gold 传送门 A: 为了保证复杂度明显是从终结点往回退 结果一开始全在想优化建边$dfs$……其实可以不用建边直接$multiset$找可行边跑$bfs$就行了 由于保证每个点只进队列一次.被搜索到一次,因此复杂度为$O(n*log(n))$ #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typ…
第二次参加USACO 本来打算2016-2017全勤的 January的好像忘记打了 听群里有人讨论才想起来铂金组三题很有意思,都是两个排列的交叉对问题 我最后得分889/1000(真的菜) T1.Why Did the Cow Cross the Road题目大意:给出两个N个排列(N<=100,000),允许把其中一个排列循环移动任意位,a[i]表示i在第一个排列中的位置,b[i]表示第二个,定义交叉对(i,j)满足a[i]<a[j]且b[i]>b[j],求最少交叉对.思路:数字大小…
题意 有一幅n*n的方格图,n <= 100,每个点上有一个值.从(1,1)出发,走到(n,n),只能走四联通.每走一步花费t,每走三步需要花费走完三步后到达格子的值.求最小花费的值. 拆点,dis[i][j]表示到达第i个点时走的总步数模3等于j时的最小花费值. #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorith…
Link: 传送门 A: 由于每个颜色只染色一次就确定了所有要染色的区间 要求染色的次数其实就是求区间最多嵌套多少层,如果有区间相交则无解 以上操作明显可以将左端点排序后用栈来维护 #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef double db; typedef long long ll; typedef pair<i…
Link: 传送门 A: 分层图最短路(其实就是最短路转移时多记录一维的数据 #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef double db; typedef long long ll; typedef pair<int,int> P; ; int n,T,dat[MAXN][MAXN]; ll d[MAXN][MAXN][]; struct node{…
Link: 传送门 A: 按值大小插入后用树状数组统计两边个数 #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef double db; typedef long long ll; typedef pair<int,int> P; ; P dat[MAXN]; int n,bit[MAXN],dsp[MAXN],l[MA…
AC自动机模板题(膜jcvb代码) #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <queue> using namespace std; ],tt[],Ans[]; ][],Fa…
Fiber Communications 总时间限制:  1000ms 内存限制:  65536kB 描述 Farmer John wants to connect his N (1 <= N <= 1,000) barns (numbered 1..N) with a new fiber-optic network. However, the barns are located in a circle around the edge of a large pond, so he can on…
Link: USACO 2018 Feb Gold 传送门 A: $dp[i][j][k]$表示前$i$个中有$j$个0且末位为$k$的最优解 状态数$O(n^3)$ #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int,int> P; ,INF=<<; int n,dat[MAXN],dp…