P2846 [USACO08NOV]光开关Light Switching 题目大意: 灯是由高科技——外星人鼠标操控的.你只要左击两个灯所连的鼠标, 这两个灯,以及之间的灯都会由暗变亮,或由亮变暗.右击两个灯所连的鼠 标,你就可以知道这两个灯,以及之间的灯有多少灯是亮的.起初所有灯都是暗的,你的任务是在LZ之前算出灯的亮灭. 线段树的懒标记下传 #include<bits/stdc++.h> #define N 1000005 #define LL long long #define RE r…
P2826 [USACO08NOV]光开关Light Switching 题目描述 Farmer John tries to keep the cows sharp by letting them play with intellectual toys. One of the larger toys is the lights in the barn. Each of the N (2 <= N <= 100,000) cow stalls conveniently numbered 1..N…
题目描述 Farmer John tries to keep the cows sharp by letting them play with intellectual toys. One of the larger toys is the lights in the barn. Each of the N (2 <= N <= 100,000) cow stalls conveniently numbered 1..N has a colorful light above it. At th…
题目传送门 题目大意,给你一串灯,按一下开关可以将灯的状态取反(开变成关,关变成开).维护这个序列的两种操作:询问区间内有多少灯是开着的,区间按灯. 开始想的是分别维护区间内0的数量,1的数量,两个懒标记.后来真正写到维护懒标记的时候却感觉不太可行,因为你并不精确的知道区间内哪里是开着,哪里是关着的. 其实我们本质上就是在维护整个异或序列.因为把每个位置取反,实际上就是在进行异或运算.(0->1,1->0).这样我们在区间修改的时候,只需要维护区间内1的个数,把它用区间长度减去原来的值便得到新…
题目描述 灯是由高科技--外星人鼠标操控的.你只要左击两个灯所连的鼠标, 这两个灯,以及之间的灯都会由暗变亮,或由亮变暗.右击两个灯所连的鼠 标,你就可以知道这两个灯,以及之间的灯有多少灯是亮的.起初所有灯都是暗的,你的任务是在\(LZ\)之前算出灯的亮灭. 输入输出格式 输入格式: 第1 行: 用空格隔开的两个整数\(N\) 和\(M\),\(N\) 是灯数 第\(2..M+1\) 行: 每行表示一个操作, 有三个用空格分开的整数: 指令号, \(S_i\) 和\(E_i\) 第\(1\) 种…
https://www.luogu.org/problemnew/show/P2846 好多题解用线段树来写,然而分块不是更简单好些吗? 一个数组use记录这一块进行了多少次开关操作,两边单独计算,注意每次更新两边是也要维护这一块. 查询两边暴力加减,块内循环枚举. #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cmath&…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题意: 给定一个长\(N\)的序列,求满足任意两个相邻元素之间的绝对值之差不超过\(K\)的这个序列的排列有多少个? 范围: \(0<=n<=16,0<=序列元素<=25000,0<=k<=3400\) 统计次数一般是递推干的事情,但是我们发现,这个递推并没有一个很明显的顺序关系,并不可以说前几个转移到下一个之类的. 看看数据这么小,一般都是状压干的事情了. 我们可以按照规模进行递推,即一个大小…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large le…
P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each hill…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large le…
P2916 [USACO08NOV]为母牛欢呼Cheering up the C… 题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths that currently provide a way to visit each of his N (5 <= N <= 10,000) pastures (conveniently numbered 1..N).…
P2918 [USACO08NOV]买干草Buying Hay 题目描述 Farmer John is running out of supplies and needs to purchase H (1 <= H <= 50,000) pounds of hay for his cows. He knows N (1 <= N <= 100) hay suppliers conveniently numbered 1..N. Supplier i sells packages t…
题目链接 很明显的一道完全背包板子题,做法也很简单,就是要注意 这里你可以买比所需多的干草,只要达到数量就行了 状态转移方程:dp[j]=min(dp[j],dp[j-m[i]]+c[i]) 代码如下: #include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<…
传送门 题目大意: 每个工作有截至时间和耗费时间,n个工作求最小开始时间. 题解: 贪心 从n-1安排,让结束时间尽量的晚. 注意:优先级 cout<<st<0?-1:st;  (X) cout<<(st<0?-1:st);' 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 1090 using…
题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths that currently provide a way to visit each of his N (5 <= N <= 10,000) pastures (conveniently numbered 1..N). Each and every pasture is home to one cow.…
题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each hill. He has a map supplied as a matrix of i…
题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths that currently provide a way to visit each of his N (5 <= N <= 10,000) pastures (conveniently numbered 1..N). Each and every pasture is home to one cow.…
https://www.luogu.org/problem/show?pid=2916 题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths that currently provide a way to visit each of his N (5 <= N <= 10,000) pastures (conveniently numbered 1..N)…
https://www.luogu.org/problem/show?pid=2919 题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each…
考场上空间开大了一倍就爆0了QAQ- Code: #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const int maxn = 21; int height[30], pos[30]; long long dp[1 << maxn][21]; int main() { int n, delta; scanf("%d%d",&n,…
一道水状压,然而不知道是不是太久没做过dp了,我盯着它二十分钟才反应过来.... 还把数组开小了WA了一发QAQ //Twenty #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<cmath> #include<queue>…
[题目描述:] AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为n的01串. 2. 给定一个范围[l,r],伤害为伤害串的这个范围内中1的个数 3. 会被随机修改伤害串中的数值,修改的方法是把[l,r]中的所有数xor上1 AKN想知道一些时刻的伤害,请你帮助他求出这个伤害 [输入格式:] 第一行两个数n,m,表示长度为n的01串,有m个时刻 第二行一个长度为n的01串,为初始伤害串 第三行开始…
题目描述 现有\(N(2 ≤ N ≤ 100000)\)盏灯排成一排,从左到右依次编号为:\(1,2,......,N\).然后依次执行\(M(1 ≤ M ≤ 100000)\)项操作,操作分为两种:第一种操作指定一个区间\([a, b]\),然后改变编号在这个区间内的灯的状态(把开着的灯关上,关着的灯打开),第二种操作是指定一个区间\([a, b]\),要求你输出这个区间内有多少盏灯是打开的.灯在初始时都是关着的. 输入输出格式 输入格式: 第一行有两个整数\(N\)和\(M\),分别表示灯的…
什么毒瘤... 解:n = 1的,发现就是一个二次函数,解出来一个v的取值范围,选最大的即可. n = 2的,猜测可以三分.于是先二分给第一段路多少能量,然后用上面的方法求第二段路的最短时间.注意剩余能量不足跑完第二段路的时候,返回INF. 正解是啥拉格朗日乘子法,完全搞不倒... /** * There is no end though there is a start in space. ---Infinity. * It has own power, it ruins, and it go…
题目传送门..................................................................................................................................... The biggest event of the year ended tragically for Croatian teams. The most influential theoretician of CERC of…
本文同时发表于洛谷日报,您也可以通过洛谷博客进行查看. 1.介绍与开始使用 1.1 这是什么? StackEdit是基于PageDown.Stack Overflow和其他堆栈交换站点使用的Markdown库的功能齐全的开源Markdown编辑器.它可以在离线时使用,并可以把数据(md文件)存储到浏览器上,还可以绑定CouchDB.GitHub.GitLab.Google Drive等工作空间.它还可以任意创建文件夹,并且可以任意创建文件.被删除的文件还会保留在Trash文件夹里. 1.2 开始…
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类似于匈牙利(⊙o⊙) (匈牙利的复杂度惊人,1e6秒过) #include <cstdio> ]; ],fir[],to[],nex[]; int N,n,p,q; void add(int p,int q) { nex[++N]=fir[p];to[N]=q;fir[p]=N; } bool f…
没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会,要求与会职员的快乐指数最大.但是,没有职员愿和直接上司一起与会. 输入描述 Input Description 第一行一个整数N.(1<=N<=6000)接下来N行,第i+1…
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它.买的次数越多越好!你的目标是在遵循以上建议的前提下,求你最多能购买股票的次数.你将被给出一段时间内一支股票每天的出售价(2^16范围内的正整数),你可以选择在哪些天购买这支股票.每次购买都必须遵循“低价购买:再低价购买”的原则.写一个程序计算最大购买次数. 这里是某支股票的价格清单: 日期 1 2…
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N x N 的方格.输入数据中包括有树的方格的列表.你的任务是计算并输出,在他的农场中,不需要砍树却能够修建的最大正方形牛棚.牛棚的边必须和水平轴或者垂直轴平行. EXAMPLE 考虑下面的方格,它表示农夫约翰的农场,‘.'表示没有树的方格,‘#'表示有树的方格 1 2 3 4 5 6 7 8 1 .…