P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N <= 100,000). Each cow starts at a distinct position on the track, and some cows jog at…
传送门 题目大意:n头牛在单行道n个位置,开始用不同的速度跑步. 当后面的牛追上前面的牛,后面的牛会和前面的牛以一样的速度 跑,称为一个小团体.问:ts后有多少个小团体. 题解:模拟 倒着扫一遍,因为某头牛后面的牛对这头牛的速度没影响. 计算出ts后牛的终点,如果能撞上前面最慢的牛,那么小团体数+1 注意开long long 一开始不理解为什么倒着扫, 因为如果正着扫,看第i头牛能否撞上i+1头, 我们不确定第i+1头牛的速度,可能第i+1头牛 速度很快,追上i+2头牛速度减缓,从而被第i头牛追…
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 1000000 + 233; const long long N = 1000000000000000000; long long pos[maxn], speed[maxn], T , dest[maxn]; int A[maxn], n; int cmp(int i,in…
本蒟蒻又来发题解了, 一道较水的模拟题. 题意不过多解释, 思路如下: 在最开始的时候求出每头牛在t秒的位置(最终位置 然后,如果后一头牛追上了前一头牛,那就无视它, 把它们看成一个整体. else 就++ ans: 上代码: #include<bits/stdc++.h> using namespace std; //要开long long long long n, t, ans = 1, last[100010]; struct node { long long s, p; }a[1000…
有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度.我们把这些跑走同一个位置而且同等速度的牛看成一个小组. 请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组. #include<queue> #include<cstdio> #include<cstring&…
传送门 解题思路 比较简单的一道思路题,首先假设他们没有前面牛的限制,算出每只牛最远能跑多远.然后按照初位置从大到小扫一遍,如果末位置大于等于前面的牛,那么就说明这两头牛连一块了. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const int MAXN = 100005; typedef long long LL;…
题目大意 有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度.我们把这些跑走同一个位置而且同等速度的牛看成一个小组. 请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组. 题解 定义两头牛"能单独追上"为:若跑道上只有这两头牛,则它们能否追上.牛i和牛j(j>i)将…
题目描述 Bessie has taken heed of the evils of sloth and has decided to get fit by jogging from the barn to the pond several times a week. She doesn't want to work too hard, of course, so she only plans to jog downhill to the pond and then amble back to…
P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 86分求救 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget…
P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, s…
P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The cows will arrange themselves in a line and ask Far…
如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行(牛线),问FJ此时的行号是多少.之后,FJ会给牛一个行号,牛必须按照新行号排列成线. 行号是通过以字典序对行的所有排列进行编号来分配的.比如说:FJ有5头牛,让他们排为行号3,排列顺序为: 1:1 2 3 4 5 2:1 2 3 5 4 3:1 2 4 3 5 因此,牛将在牛线1 2 4 3 5中. 之后,…
题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competito…
https://www.luogu.org/problem/show?pid=2419 题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant ski…
想找原题请点击这里:传送门 原题: 题目背景 [Usaco2008 Jan] 题目描述 N ( ≤ N ≤ ) cows, conveniently numbered ..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among…
题意很简单,给一张图,把基本的求起点到终点最短路改成求经过k条边的最短路. 求最短路常用的算法是dijkstra,SPFA,还有floyd. 考虑floyd的过程: c[i][j]=min(c[i][j],a[i][k]+b[k][j]); 自然而然联想到矩阵乘法,每次加入一个点就相当于多加一条边,那么加k次就是k条边的最短路. 但是k可能很大(见数据范围),那么显然直接循环矩乘k次是行不通的,于是就想到了矩阵快速幂. 和普通快速幂一样的方式,只不过是把乘法替换成矩乘. 代码如下: #inclu…
对于一个能够确定名次的点,可以注意到,对于该点,入度和出度的数量加起来等于N-1(这样还是不够准确的确切的说是,能够到达这个点的数量和这个点能够到达的数量的和 floyd不仅可以求两个点之间的最短路径,还能求两个点彼此是否能够相互到达最后对于一个可以确定名次的点,能够到达的所有的点 加上 能够到达该点的所有点的和必须等于n-1当然,我们可以通过二进制来简化这个过程 最后处理结果时,设一个变量flag, 因为该点能够到达本身,flag初值赋为1对于两个点i, j首先f[i][j] | f[j][i…
题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #include<bits/stdc++.h> using namespace std; const int MAXN = 1005; int n,t,s,e; int edge[MAXN][MAXN]; int num[MAXN],tot; struct Mat{ int a[105][105]; Mat o…
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players…
题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitious, and only labels cows with binary numbers that have exactly K "1" bits (1 <= K <= 10). The leading bit of each la…
题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to…
https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since FJ's cows represent a variety of different breeds, he would like the photo to contain at least one cow fro…
本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写了.离线算法是基于DFS的Tarjan算法. 然后就打算去学一下Tarjan,因为以前也看过但是没看完,就打算学一下,因为Tarjan算法是图论的内容,然后就让图论选手教了我一下大环套小环的怎么推,然后就尴尬了. 我是学数据结构的,没有要去抢图论的内容学... 我也看了线段树了啊. 学完这个Tarj…
P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget. The roller coaster will be built on a long linear stretch of land o…
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N <= 1,000) have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of dam…
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometime…
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows move from any of the N (1 <= N <= 250)…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
https://www.luogu.org/problem/show?pid=2863#sub 题目描述 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 th…