洛谷 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…
题目描述 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 alternate turns. On each turn, a player c…
1~9显然,后面平\(A\)过去 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++a) #define nR(a,b,c) for(register int a = (b); a >=…
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…
P2950 [USACO09OPEN]牛绣Bovine Embroidery 题目描述 Bessie has taken up the detailed art of bovine embroidery. Cows embroider a cloth mounted in a circular hoop of integer radius d (1 <= d <= 50,000). They sew N (2 <= N <= 50,000) threads, each in a s…
题目描述 小鱼最近被要求参加一个数字游戏,要求它把看到的一串数字(长度不一定,以0结束,最多不超过100个,数字不超过2^32-1),记住了然后反着念出来(表示结束的数字0就不要念出来了).这对小鱼的那点记忆力来说实在是太难了,你也不想想小鱼的整个脑袋才多大,其中一部分还是好吃的肉!所以请你帮小鱼编程解决这个问题. 输入格式 一行内输入一串整数,以0结束,以空格间隔. 输出格式 一行内倒着输出这一串整数,以空格间隔. 输入输出样例 输入 #1 复制 3 65 23 5 34 1 30 0 输出…
本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写了.离线算法是基于DFS的Tarjan算法. 然后就打算去学一下Tarjan,因为以前也看过但是没看完,就打算学一下,因为Tarjan算法是图论的内容,然后就让图论选手教了我一下大环套小环的怎么推,然后就尴尬了. 我是学数据结构的,没有要去抢图论的内容学... 我也看了线段树了啊. 学完这个Tarj…
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…
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream> #include<cstdio> #include<cstring> #define maxn 10009 using namespace std; int n,m,sumedge,top,sumclr,tim,ans; int Stack[maxn],instack[maxn]…
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…
代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<stack> #include<vector> using namespace std; struct node { int num,par; }p[]; ,x,y,cnt; vector<]; ]; ]; stack<int>…
每日一题 day11 打卡 Analysis 好久没大Tarjan了,练习练习模板. 只要在Tarjan后扫一遍si数组看是否大于1就好了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000+10 #define maxm 50000+10 using namespace std; inline int read() { ;…
一道tarjan的模板水题 在这里还是着重解释一下tarjan的代码 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,m; int cnt;//记录强联通分量的个数 int visitnum;//遍历的步数 int dfn[100010];//记录元素第一次被访问的步数 int low[100010];//包含i的强联通分量最早被访问的步数 int nu…
[洛谷5月月赛]玩游戏(NTT,生成函数) 题面 Luogu 题解 看一下要求的是什么东西 \((a_x+b_y)^i\)的期望.期望显然是所有答案和的平均数. 所以求出所有的答案就在乘一个逆元就好了. 现在考虑怎么算上面那个东西. 对于单个的计算,我们可以用二项式定理直接展开 得到 \[\begin{aligned}\sum(a+b)^k&=\sum\sum_{i=0}^kC_k^ia^ib^{k-i}\\&=\sum_{i=0}^kC_k^i(\sum a^i)(\sum b^{k-i…
题目背景 HNSDFZ的同学们为了庆祝春节,准备排练一场舞会. 题目描述 在越来越讲究合作的时代,人们注意的更多的不是个人物的舞姿,而是集体的排列. 为了配合每年的倒计时,同学们决定排出——“数字舞蹈”.顾名思义就是所有人一起排成若干个数字 -___-|||| 更为创新的是,每个人都是趴在地上,保证横竖. 现在给出数字及其要求摆出的大小,请你编程,模拟同学们的优美姿态. 输入输出格式 输入格式: 第一行为k.k表示要摆出数字的大小. 第二行为全部由数字组成的字符串,即要摆出的几个数字. 输出格式…
题面 HDU1527 取石子游戏 洛谷2252 取石子游戏 题解 裸的威佐夫博弈 #include<iostream> #include<cmath> using namespace std; const double phi=(sqrt(5)+1)/2; int a,b; int main() { ios::sync_with_stdio(false); while(cin>>a>>b) { if(a>b)swap(a,b); int A=abs(a…
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…
P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make money on the jobs he does, each one of which takes just one time unit. His work day starts at time 0 and has 1,000…
洛谷题目传送门 动态点分治小白,光是因为思路不清晰就耗费了不知道多少时间去gang这题,所以还是来理理思路吧. 一个树\(T\)里面\(\sum\limits_{v\in T} D_vdist(u,v)\)取到最小值的\(u\)我们可以称作带权重心.类似重心各种性质的证明过程,我们不难证出这样的点顶多只有两个. 如果\(e\)都是正数的话比较好做.类比重心性质,新带权重心一定在原带权重心和修改点之间的路径上,可以直接像首都(蒟蒻题解)那样用LCT维护以带权重心为根的树,修改时提出链二分查找出新带…
题目链接 洛谷T30212 题解 式子很容易推出来,二项式定理展开后对于\(k\)的答案即可化简为如下: \[k!(\sum\limits_{i = 0}^{k} \frac{\sum\limits_{x = 1}^{n} a_x^{i}}{i!} \centerdot \frac{\sum\limits_{x = 1}^{n} b_x^{k - i}}{(k - i)!})\] 是一个卷积的形式 我们只需对所有\(k\)预处理出\(\sum\limits_{i = 1}^{n} a_i^{k}…
https://www.lydsy.com/JudgeOnline/problem.php?id=5288 https://www.luogu.org/problemnew/show/P4436 https://loj.ac/problem/2508 看洛谷题解里面清一色的暴力,连唯一正解也是用了奇技淫巧才过(当然本题解参考了那个题解). 于是难受的我来简单说一下“正解”(如有错误请指出orz). 先从暴力开始,对于每个点我们暴力找到其能够到达的最大的区间[l,r]. 一个优化:我们在加入新的点…
题目描述 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…
bzoj1413 洛谷P2599 根本不会啊... 看题解吧 #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; typedef…
P1569 [USACO11FEB]属牛的抗议Generic Cow Prote- 题目描述 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约翰希望奶牛在抗议时保持理性,为此,他打算将所有的奶牛隔离成 若干个小组,每个小组内的奶牛的理智度总和都要大于等于零.由于奶牛是按直线排列的,所以 一个小组内的奶牛位置必须是连续的. 请帮助约翰计算一下,最多分成几组. 输入输出格式 输入格式: 第1行包含1个数N,代表奶牛的数目. 第2至N+1行每行…
本题是练习前缀和的好题!我们可以枚举前端点,确定一个长度为k的区间,然后利用前缀和统计区间内损坏的灯的数量,最后取最小值即可.AC代码: #include <bits/stdc++.h> using namespace std; inline int read()//快速读入 { ,x=; char c=getchar(); ') { ; c=getchar(); } ') { x=x*+c-'; c=getchar(); } return f*x; } ],s[],sum=; int mai…
SG搜索 n的范围在可以接受的范围内,SG搜索即可 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int MAXN = 1000005; int init() { int rv = 0 , fh = 1; char c = getchar(); whi…
如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 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中. 之后,…
P3048 [USACO12FEB]牛的IDCow IDs 12通过 67提交 题目提供者lin_toto 标签USACO2012 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 谁能解释一下这个样例啊.... 题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitiou…
P2197 [模板]nim游戏 题目描述 甲,乙两个人玩Nim取石子游戏. nim游戏的规则是这样的:地上有n堆石子(每堆石子数量小于10000),每人每次可从任意一堆石子里取出任意多枚石子扔掉,可以取完,不能不取.每次只能从一堆里取.最后没石子可取的人就输了.假如甲是先手,且告诉你这n堆石子的数量,他想知道是否存在先手必胜的策略. 输入输出格式 输入格式: 第一行一个整数T<=10,表示有T组数据 接下来每两行是一组数据,第一行一个整数n,表示有n堆石子,n<=10000; 第二行有n个数,…
题目描述 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)…