• 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\)大,说明当前可以分配牛,记录数量
  • 2023-05-09「USACO2016JAN」Subsequences Summing to Sevens
    [USACO16JAN]SubsequencesSummingtoSevensS题目描述FarmerJohn's\(N\)cowsarestandinginarow,astheyhaveatendencytodofromtimetotime.EachcowislabeledwithadistinctintegerIDnumbersoFJcantellthemapart.FJwouldliketota
  • 2023-05-03NC51101 Lost Cows
    题目链接题目题目描述\(N(2\leqN\leq8,000)\)cowshaveuniquebrandsintherange1..N.Inaspectaculardisplayofpoorjudgment,theyvisitedtheneighborhood'wateringhole'anddrankafewtoomanybeersbeforedinner.Whenitwastimetoli
  • 2023-04-24Codeforces Round #225 (Div. 2) C. Milking cows Greedy
    Iahubhelpshisgrandfatheratthefarm.Todayhemustmilkthecows.Therearencowssittinginarow,numberedfrom1tonfromlefttoright.Eachcowiseitherfacingtotheleftorfacingtotheright.WhenIahubmilksacow,allthecowsthatseet
  • 2023-04-07POJ - 3186 Treats for the Cows(DP)
    题目大意:给你一个数组,每次你可以取两个数中的一个进行操作,要么取数组的第一个,要么数组的最后一个(取完之后,该数删除)假设取出来的数组组成了A现在要求使Sum=A[1]*1+A[2]*2+A[3]*3…+A[n]*n达到最大解题思路:用dp[i][j]表示前面取了i个,后面取了j个最大值则转
  • 2023-02-22J - Til the Cows Come Home
    J-TiltheCowsComeHomeBessieisoutinthefieldandwantstogetbacktothebarntogetasmuchsleepaspossiblebeforeFarmerJohnwakesherforthem
  • 2023-02-20Popular Cows
    PopularCowshttp://poj.org/problem?id=2186 思路涉及到有向图的强连通子图检测,参考:https://oi-wiki.org/graph/scc/https://www.cnblogs.com/zwfymqz/p/6693881.h
  • 2023-02-07POJ 3276 Face The Right Way/洛谷P2882 [USACO07MAR]面对正确的方式 反转
    题目描述FarmerJohnhasarrangedhisN(1≤N≤5,000)cowsinarowandmanyofthemarefacingforward,likegoodcows.Someofthemarefacingbackward,th
  • 2023-02-07POJ 3274 Gold Balanced Lineup/P1360 [USACO07MAR]黄金阵容均衡
    题目描述FarmerJohn'sNcows(1≤N≤100,000)sharemanysimilarities.Infact,FJhasbeenabletonarrowdownthelistoffeaturessharedbyhiscowstoa
  • 2023-01-24POJ--2386 Lake Counting(DFS)
    记录0:332023-1-24http://poj.org/problem?id=3617reference:《挑战程序设计竞赛(第2版)》2.2.3p43DescriptionFJisabouttotakehisN(1≤N≤2,000)cows