• 2024-11-16[USACO07DEC] Sightseeing Cows G
    算法初看题面没有思路,考虑使用数学语言表示注意本题最重要的信息是发现路径为一个环给你一张\(n\)点\(m\)边的有向图,第\(i\)个点点权为\(F_i\),第\(i\)条边边权为\(T_i\)找一个环,设环上的点组成的集合为\(S\),环的边组成的集合为\(E\),令\[\frac{\sum_
  • 2024-10-22P2952 [USACO09OPEN] Cow Line S
    [USACO09OPEN]CowLineS题面翻译FarmerJohn(以下简称FJ)的NNN头奶牛(用1…
  • 2024-09-29[USACO03Open] Lost Cows(二分加树状数组)
    #include<bits/stdc++.h>usingnamespacestd;#definexfirst#defineysecondtypedefpair<int,int>PII;typedeflonglongll;typedefunsignedlonglongull;typedefunsignedintuint;typedefvector<string>VS;typedefvector<int>
  • 2024-09-10题解:[USACO07DEC] Sightseeing Cows G
    洛谷P2868题目大意有个nnn个点,mmm条边的有向图,点有点权,边有边
  • 2024-08-20题解:P9944 [USACO21FEB] Comfortable Cows B
    思路由于每次输入\(x\)和\(y\)只改变其上下左右的值,所以每次只要更新其相邻的值即可。当某个位置相邻的奶牛数达到\(3\)时,舒适度加一。当某个位置相邻的奶牛数达到\(4\)时,舒适度减一。注意:每增加一头奶牛以后,如果该位置相邻正好有三头奶牛,则舒适度也要加一。ACcod
  • 2024-07-26P3131 [USACO16JAN] Subsequences Summing to Sevens S
    传送锚点:[USACO16JAN]SubsequencesSummingtoSevensS-洛谷题目描述FarmerJohn's\(N\)cowsarestandinginarow,astheyhaveatendencytodofromtimetotime.EachcowislabeledwithadistinctintegerIDnumbersoFJcantellthemapart.FJwould
  • 2024-07-23面向前方
    [USACO07MAR]FaceTheRightWayG题目描述FarmerJohnhasarrangedhisN(1≤N≤5,000)cowsinarowandmanyofthemarefacingforward,likegoodcows.Someofthemarefacingbackward,though,andheneedsthemalltofaceforwardtomakehislifeper
  • 2024-07-12Cows in a Skyscraper G
    dfs版本#include<algorithm>#include<iostream>usingnamespacestd;constintN=2e1;intcat[N],cab[N];intn,w;intans;boolcmp(inta,intb){returna>b;}voiddfs(intnow,intcnt){if(cnt>=ans){re
  • 2024-07-08P7411 [USACO21FEB] Comfortable Cows S (搜索)
    P7411[USACO21FEB]ComfortableCowsS搜索容易知道任意时刻的不合法的位置,并且决策只有将空着的位置补起来。每次加入一个点,判断其自身、上下左右是否变得不合法,往下递归即可。复杂度分析,每个点只会不合法一次(修改后就变得合法),所以只会遍历一次,复杂度是\(O(n^2)\)。#inclu
  • 2024-06-22P3056 [USACO12NOV] Clumsy Cows S
    [USACO12NOV]ClumsyCowsS题目描述Bessiethecowistryingtotypeabalancedstringofparenthesesintohernewlaptop,butsheissufficientlyclumsy(duetoherlargehooves)thatshekeepsmis-typingcharacters.Pleasehelpherbycomputingthemi
  • 2024-04-24P3667 [USACO17OPEN] Bovine Genomics G (set容器)
    [USACO17OPEN]BovineGenomicsG题目描述FarmerJohnowns\(N\)cowswithspotsand\(N\)cowswithoutspots.Havingjustcompletedacourseinbovinegenetics,heisconvincedthatthespotsonhiscowsarecausedbymutationsinthebovinegenome.Atgr
  • 2024-04-05P3052 [USACO12MAR] Cows in a Skyscraper G
    原题链接题解模拟,遍历n个物品,一开始一个箱子不给,遍历到某个物品时,先把所有已经给了的箱子放进去试试,再创一个新箱子放进去试试code#include<bits/stdc++.h>usingnamespacestd;intn,w;intcnt,ans;intchongdie=0;intbox[20],c[20];voidmoni(intnow,intcnt)//now
  • 2024-03-04P3047 [USACO12FEB] Nearby Cows G
    原题链接题解核心技巧:两次搜索第一次搜索:搜索出\(f[now][i]\)以\(now\)为根节点的子树且距离根节点恰好为\(i\)的节点的个数搜索完了之后,把范围\(k\)以内的累加第二次搜索:由于整棵树的根节点的\(f\)等于整棵树里距离不大于\(k\)的节点个数,即已经符合题目要求
  • 2024-02-26P7154 Sleeping Cows 题解
    传送门题意:给定两个数组\(a_i,b_i\),若\(a_i\leb_j\),则他俩可配对。求极大匹配的方案数。(极大不是最大,最大一定是极大)先考虑最大匹配方案数怎么求。把\(a\)和\(b\)从小到大排序。则每个\(a_i\)能匹配的\(b\)都是一段后缀,且随着\(i\)增大,这个后缀越来越小。于是从
  • 2023-12-30[USACO07DEC] Sightseeing Cows G
    [USACO07DEC]SightseeingCowsG题目描述FarmerJohnhasdecidedtorewardhiscowsfortheirhardworkbytakingthemonatourofthebigcity!Thecowsmustdecidehowbesttospendtheirfreetime.Fortunately,theyhaveadetailedcitymapshowingthe$L
  • 2023-11-09P9194 [USACO23OPEN] Triples of Cows P 题解
    Description给定一棵初始有\(n\)个点的树。在第\(i\)天,这棵树的第\(i\)个点会被删除,所有与点\(i\)直接相连的点之间都会两两连上一条边。你需要在每次删点发生前,求出满足\((a,b)\)之间有边,\((b,c)\)之间有边且\(a\not=c\)的有序三元组\((a,b,c)\)对数。\(n\leq2
  • 2023-09-12POJ 2186-Popular Cows ---强连通分量
    本题让求有多少点 是图中所有点都可到达改点的定理:在一个有向图中,如果有一个节点的出度为0,并且仅有一个这样的点,则该图中所有的点都可到达该点先求出图的强连通分量,然后将每个强连通分量化为一个层次,求是否存在一个强连通分量,该分量的出度为一,并且仅有一个这样的分量,则该连通分量
  • 2023-08-12Electric Fence
    描述Inthisproblem,"latticepoints"intheplanearepointswithintegercoordinates.Inordertocontainhiscows,FarmerJohnconstructsatriangularelectricfencebystringinga"hot"wirefromtheorigin(0,0)toalatticepoint
  • 2023-07-06P3047 [USACO12FEB] Nearby Cows G
    #include<iostream>#include<vector>usingnamespacestd;constintN=100010,M=30;intn,m;intw[N];vector<int>g[N];intf[N][M],ans[N][M];voidDP1(intu,intfa){ for(inti=0;i<=m;i++)f[u][i]=w[u]; for(intx:g
  • 2023-06-13[USACO06FEB]Treats for the Cows G/S
    [USACO06FEB]TreatsfortheCowsG/S题目描述FJhaspurchasedN(1<=N<=2000)yummytreatsforthecowswhogetmoneyforgivingvastamountsofmilk.FJsellsonetreatperdayandwantstomaximizethemoneyhereceivesoveragivenperiodtime.Th
  • 2023-06-12Codeforces Round #225 (Div. 2)-C. Milking cows
    原题链接C.Milkingcowstimelimitpertestmemorylimitpertestinputoutputn cowssittinginarow,numberedfrom 1 to nIahubcandecidetheorderinwhichhemilksthecows.Buthemustmilkeachcowex
  • 2023-06-12POJ 3264 Balanced Lineup
    思路:线段树求最大值减最小值,每个结点分别维护最大值和最小值即可。#include<cstdio>#include<queue>#include<cstring>#include<iostream>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<string>#in
  • 2023-06-12HDU 2838 Cow Sorting(树状数组)
    题意:首先每次只能交换相邻的两头牛,并且最后要求升序排列,所以最后整个序列的逆序是0,每次交换只可以消除1个逆序。(令a[i]的逆序是从1到i-1比它大的数的个数。)思路:对于某个数,要把它变成有序的,那么很容易可以推算出公式就是它自身的逆序数乘自身的值再加上它的逆序数的和,自己算算看看。
  • 2023-06-04(输出路径搜索)[USACO06OCT] Cows on Skates G
    题目描述本题使用SpecialJudge。FarmerJohn把农场划分为了一个 r 行 c 列的矩阵,并发现奶牛们无法通过其中一些区域。此刻,Bessie位于坐标为 (1,1)(1,1) 的区域,并想到坐标为 (,)(r,c) 的牛棚享用晚餐。她知道,以她所在的区域为起点,每次移动至相邻的四个区域之一,总有
  • 2023-05-10P1676 [USACO05FEB] Aggressive cows G 题解
    题目传送门解题思路最大值最小化问题,考虑二分答案。首先要排序,保证序列单调不降,然后求出两个隔间之间的距离。sort(a+1,a+1+n);for(rii=1;i<=n;i++) dis[i]=a[i+1]-a[i];二分出一个\(mid\),判断它是否合法:每次累加距离,如果距离和比\(mid\)大,说明当前可以分配牛,记录数量