【洛谷P3131】 【USACO16JAN】子共七】的更多相关文章

P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题目描述 Farmer John's NN cows are standing in a row, as they have a tendency to do from time to time. Each cow is labeled with a distinct integer ID number so FJ can tell them apart. FJ would like to t…
[USACO16JAN]子共七Subsequences Summing to Sevensa[i]表示前缀和如果a[i]%7==t&&a[j]%7==t那么a[j]-a[i-1]一定是7的整数倍,这样就o(n)扫一遍,不断更新答案就可以了. #include<iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cmath> #include…
P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题目描述 Farmer John's cows are standing in a row, as they have a tendency to do from time to time. Each cow is labeled with a distinct integer ID number so FJ can tell them apart. FJ would like to take…
看到这一题第一印象就是暴力好打,$O(n^2)$,预计得分$70$分 这明显满足不了啊,我们要用到前缀和. $sum[i]$记录到i的前缀和,区间$[a,b]$的和就是$sum[b]-sum[a-1]$. 处理完以后怎么统计呢,$n^2$当然不行,我们要用到一个显然的定理. 如果 $a\equiv c(mod$ $k)$并且$b\equiv c(mod$ $k)$,那么$|a-b|\equiv 0(mod$ $k)$ 显然两个数的余数在相减的时候同时减去,从而只剩下$k$的倍数. 所以题目里我们…
用sum[i]表示前缀和模7的值,若存在i≤j,满足sum[i]==sum[j],则区间(i,j]的和为7的倍数. O(N)扫出sum[0]~sum[6]第一次出现的位置first和最后一次出现的次数last,答案即为Max(last[i]-first[i]) #include<cstdio> #include<algorithm> using namespace std; ; ],last[]; void read(int &k){ k=; ; char c=getcha…
妖梦费了好大的劲为幽幽子准备了一个大西瓜,甚至和兔子铃仙打了一架.现在妖梦闲来无事,就蹲在一旁看幽幽子吃西瓜.西瓜可以看作一个标准的球体,瓜皮是绿色的,瓜瓤是红色的,瓜皮的厚度可视为0.妖梦恰好以正视的角度看着这个西瓜.幽幽子是一个吃货,妖梦一走神,自己背后的刀就不见了,而西瓜也被切掉了一块.幽幽子切西瓜时刀面始终垂直于桌面,并且切下的一块在俯视图中正好是一个以西瓜中心为顶点,半径为西瓜半径的扇形.如图所示,是一种满足条件的情况 俯视: 正视: 妖梦看着红红绿绿的西瓜,忽然陷入思考,红色的西瓜瓤…
P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in to…
https://www.luogu.org/problemnew/show/P3131 A表示前缀和数组 A[r] - A[l - 1] = 0 (mod 7) 得 A[r] = A[l - 1] (mod 7) #include <cstdio> #include <algorithm> using namespace std; ; #define yxy getchar() ], last[]; inline int read() { , f = ; char c = yxy;…
传送门 有趣的前缀和. 数据范围中的n≤200" role="presentation" style="position: relative;">n≤200n≤200提示我需要写出来一个O(n3)" role="presentation" style="position: relative;">O(n3)O(n3)的算法,思来想去感觉前缀和挺靠谱的于是写了写发现只有84,检查后发现把m打成了n(…
题目描述 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白色棋子,7颗黑色棋子,有两个空白地带,任何一颗黑白棋子都可以向上下左右四个方向移动到相邻的空格,这叫行棋一步. 黑白双方交替走棋,任意一方可以先走,如果某个时刻使得任意一种颜色的棋子形成四个一线(包括斜线),这样的状态为目标棋局. 输入输出格式 输入格式: 从文件中读入一个4*4的初始棋局,黑棋子用B表示,白棋子用W表示,空格地带用O表示. 输出格式: 用最少的步数移动到目标棋局的步数. 输入输出样例: 输入: BWBO WBWB BW…