LINK:Pay to Win 自闭了 比赛的时候推出来正解了 以为复杂度不对 写完扔了 没拿map存状态就扔了23333... 一个T点:在更新map的时候 >不要写成>= 不然会徒劳的增加复杂度 被这个东西坑了好几次了. 思路:如果直接从1到n这样增加 很茫然 不知道要乘什么. 容易想到倒着做 从n到1这样.这样每次就知道到底可以除谁. 容易想到 x-w/d比x/d-w 优. 所以每次先考虑除以什么 如果要除以2 那么显然应该是2的倍数 3,5同理. 然后用map存状态 可以发现总状态量是…
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ 个 $'a'$ 和 $n$ 个 $'b'$ . 现在,让你按照原顺序取出一些字符,按照原顺序组成新的字符串,输出所有满足条件的字符串中字典序最大的?(字典序: $'b'>'a'>'\ '$) 条件限制:当且仅当取了原序列的第 $i$ 个 $'a'$ 时,原序列的第 $i$ 个 $'b'$ 也被取了…
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…
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact about trees.Let T be a tree, and let D be the diameter of the tree. • If D is even, there exists an vertex v of T such that for each vertex w inT, the dis…
题目链接:http://abc044.contest.atcoder.jp/tasks/arc060_a Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selecting one or more cards from these N card…
C - Cleaning 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_c Description There is a tree with N vertices, numbered 1 through N. The i-th of the N−1 edges connects vertices ai and bi. Currently, there are Ai stones placed on vertex i. Determine…
B - Boxes 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_b Description There are N boxes arranged in a circle. The i-th box contains Ai stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the…
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement We have an integer sequence A, whose length is N. Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take…
题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_d 题目翻译 定义只有一个点的树权值为\(0\),若干棵(可以是\(0\)棵)权值为\(k\)的树任选一个点向一个单独的结点\(v\)连边,新生成的树的权值为\(k+1\).显然对于一棵树他的权值是一个范围\([x,inf)\),求给定的树的权值范围的最小值.\(n\leqslant10^5\) 题解 假设\(bit[i]\)为以\(i\)为根的子树的权值.那么任何一对权值相同的点在树上的简…
题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_e 题目翻译 纸上写了\(N\)个\(1\)和\(M\)个\(0\),你每次可以选择\(k\)个数字擦掉,然后再写一个他们的平均值上去.保证\(N+M-1\)可以整除\(k-1\),请问最后留下来的那个数有多少种.\(N,M,K\leqslant 2000\) 题解 这题可以转化一下题意:有一棵\(k\)叉树,有\(n+m\)个叶子,每个叶子的权值是\(0\)或\(1\),其他结点的权值是子…
题目传送门:https://agc004.contest.atcoder.jp/tasks/agc004_c 题目翻译 给你一张网格图,指定的格子是紫色的,要求你构造出两张网格图,其中一张你可以构造一些格子是红色的,另一张是蓝色的,要求红色格子与蓝色格子是四联通的,最后叠在一起与紫色格子的位置不冲突.\(n,m\leqslant 500\) 题解 第一列全红,最后一列全蓝,奇数行全红,偶数行全蓝,然后紫色的格子都要有就\(OK\)了. 时间复杂度:\(O(nm)\) 空间复杂度:\(O(nm)\…