一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前i列的方案数,其中第i列中最小的连续元素(k-1, k)处在[ Has[j-1] + 1, Has[j] ]中间 dp[i][0] 表示没有连续元素的方案 然后更新就好了 #include <iostream> #include <cstdio> #include <cmath&…
Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a string SS of length 2N2N consisting of lowercase English letters. There are 22N22N ways to color each character in SS red or blue. Among these ways, how…
B - RGB Coloring 求ax + by = k (0<=x<=n && 0<=y<=n)的方案数,最后乘上C(n, x)*C(n,y) 代码: #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long #define mp make_pair #define…
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC030C.html 题解 才发现当时是被题意杀了. 当时理解的题意是“对于任意的 (i,j) ,颜色 i 和 颜色 j 的相邻格子对数相同”.好像当时看了样例都没有发现被题意杀…… 回归正题. 如果要构造 n = k 的,那么直接 构造一个第 i 行为 i 的就好了. 那么 n<k<=2n 呢? 我们考虑斜着的列. 如果第 i 个斜列放 i ,那么也可以达到 n = k 的目的. 如果第 i 个斜列间隔…
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ 个 $'a'$ 和 $n$ 个 $'b'$ . 现在,让你按照原顺序取出一些字符,按照原顺序组成新的字符串,输出所有满足条件的字符串中字典序最大的?(字典序: $'b'>'a'>'\ '$) 条件限制:当且仅当取了原序列的第 $i$ 个 $'a'$ 时,原序列的第 $i$ 个 $'b'$ 也被取了…
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Ringo Mart, a convenience store, sells apple juice. On the opening day of Ringo Mart, there were AA cans of juice in stock in the morning. Snuke buys BB cans of juice h…
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 200200 points Problem Statement Takahashi lives in another world. There are slimes (creatures) of 1000010000 colors in this world. Let us call these colors Color 1,2,...,100001,2,...,10000. Takahashi…
原文链接www.cnblogs.com/zhouzhendong/AGC026F.html 前言 太久没有发博客了,前来水一发. 题解 不妨设先手是 A,后手是 B.定义 \(i\) 为奇数时,\(a_i\) 为"奇数位上的数":\(i\) 为偶数时, \(a_i\) 为"偶数位上的数".定义左.右两端的数分别表示 \(a_1\) 和 \(a_n\). 考虑第一步: 首先,如果 A 取了左右某一个端点,那么他必然能取走和他取的点奇偶性相同的所有点. 然后,我们考虑…
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大值定义为三个人中第二强的人的强大值.求\(n\)组最大的强大值之和. 题解 这...不是倒着选两个人,正着选一个人构成一组就好了嘛.. #include<iostream> #include<cstdio> #include<algorithm> using namespa…
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\(n\)个乘客到达了飞机场,现在他们都要坐车离开机场.第\(i\)个乘客到达的时间是\(T_i\),一个乘客必须在\([T_i,T_i+k]\)时刻做到车,否则他会生气.一辆车最多可以坐\(C\)个人.问最少安排几辆车可以让所有人都不生气. 题解 从前往后贪心即可. #include<iostream…
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\).两个子序列不同当且仅当存在一种字符在两者中的出现次数不同. \(|s|\le10^5\) solution \(\prod_{i='a'}^{'z'}(\mbox{字符}i\mbox{出现的次数}+1)-1\) #include<cstdio> #include<algorithm>…
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题解 洛谷认为此题过水,已被隐藏. #include<iostream> #include<cstdio> using namespace std; inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch…
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include<cstdio> using namespace std; #define ll long long #define MAX 100100 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>…
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把这个数字给变成\(y\).两个按钮的作用分别是让这个数加一和把这个数取反.问最少的按按钮的次数. 题解 神仙特判题,想清楚再写. #include<iostream> using namespace std; int x,y,ans=2147483647; int main() { cin>…
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ch[10]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) { scanf("%s",ch+1); for(int j=1;j<=m;++j) tot+=ch[j]=='#'…
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并且长度至少为\(n\)的最短串串长. 题解 暴力枚举\(S\)和\(T\)的重叠部分长度,然后直接\(check\) #include<iostream> #include<cstdio> #include<cstring> using namespace std; #de…
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 模拟栈,和维护括号一样的. #include<iostream> #include<cstring> using namespace std; #define MAX 200200 char ch[MAX]; int ans,tot; int main() { cin>>…
AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条边是偶数显然可以均分,否分沿着最长边隔开. #include<iostream> using namespace std; int a,b,c; int main() { cin>>a>>b>>c; if(a%2==0||b%2==0||c%2==0) cout…
AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. 题解 什么逗逼东西... #include<cstdio> #include<cstring> using namespace std; char s[1010]; bool W,E,S,N; int main() { scanf("%s",s+1); for(in…
AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; if(a<=0&&b>=0)cout<<"Zero"<<…
AtCoder Grand Contest 019 F-yes or no 解题思路: 考虑一个贪心策略,假设当前还有 \(x\) 道 \(\text{yes}\) 和 \(y\) 道 \(\text{no}\) ,那么一定猜较大者,如果 \(x=y\) 就相当于随便猜一个,把 \((x, y)\) 用坐标表示,把所有在这种决策下猜对的边用蓝色表示,走过这样一条边就相当于有 \(1\) 的贡献,然后会发现从 \((0,0)\) 到 \((n,m)\) 的所有路径经过的蓝色的边的数量都是相同的 \…
tourist出的题诶!想想就很高明,老年选手可能做不太动.不过A题还是按照惯例放水的. AtCoder Grand Contest 019 A: Ice Tea Store 题意:买0.25L,0.5L,1L,2L装的一瓶子茶分别需要a,b,c,d元,问买总共n L茶需要多少钱. a,b,c,d,n为整数. 显然a,b,c三种中我们智慧用min(4a,2b,c)去买1L.记m=min(4a,2b,c) 然后比较2m和d的大小以决定是否需要买2L一瓶的. 如果2m<=d,那么花费为nm. 如果2…
AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中有一个人的饼干数量是奇数的时候停止,求会进行几次这样子的操作,或者会永远进行下去. 首先无解的情况一定是三个数都是相等的偶数. 否则直接暴力模拟就行了.(盲猜答案不会很大) 证明一下答案的范围:不妨令\(A\le B\le C\),那么最大值和最小值之间的差就是\(C-A\),那么执行完一次操作之后…
Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没什么关系,但有一个不那么经典的推论,对于一个点 \(u\) 不在负环上的一个充要条件是 \[ \forall_{\text{Edge }v\rightarrow u} dis(S,v)+weight(v, u)\geq dis(S,u) \] 其中 \(S\) 是图中任意与 \(u\) 联通的一点.…
AtCoder Grand Contest 019 B - Reverse and Compare 题意:给定字符串,可以选定任意i.j且i<=j(当然i==j时没啥卵用),然后翻转i到j的字符串,问能组成多少种不同的字符串. tourist出的题..感觉好棒,虽然简单,但我就是不知道怎么弄,感觉思维好匮乏. 首先,如果Si=Sj,那么反转i到j和翻转i+1到j-1是一样的,也就是这种翻转不会贡献更多的答案.那么其实只要求i<j且Si!=Sj的个数就行了,当然,本身不变也是一种答案.求解i&l…
题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序列. 显然相同的数可以合并,因为在由相同的数 \(x\) 组成的数段中,在任何位置插入 \(x\),得到的序列都是相同的. 再考虑字典序的问题.你只能序列末尾或者一个 \(<x\) 的数前面插入 \(x\),否则得到的序列的字典序就会 \(\geq\) 原序列的字典序. 但这样问题还是比较棘手,我们…
A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams,…
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams, each consisting of three p…
怎么外国都喜欢考脑筋急转弯…… 题意 输入 $k$,要求构造一个 $n\times n$ 的矩阵($n$ 自选),使得恰好用 $k$ 中颜色把每个点都染色,并且同一种颜色的格子周围 相邻的每种颜色数量都相同. 比如矩阵中有两个格子的颜色是 $4$,其中一个格子周围有三个(颜色)$3$ 和一个 $1$,那另一个格子周围也得有三个 $3$ 和一个 $1$,但周围颜色的顺序不必相同. 矩阵的第 $1$ 行上面与第 $n$ 行相连,第 $1$ 列左面与第 $n$ 列相连. $k\le 1000$,且自选…
地址:http://arc080.contest.atcoder.jp/tasks/arc080_b 题目: D - Grid Coloring Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2…