layout: post title: 2018-2019 ACM-ICPC Brazil Subregional Programming Contest author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! 许老师! B.Marbles (nim博弈) 题意 一个棋盘n个点,每次可以把一个棋子移动到(x-d,y) or (x,y-d) or (x-d,y-d) 把其中一个棋子移动到(0…
$$2018-2019 ACM-ICPC Brazil Subregional Programming Contest$$ \(A.Slackline\ Adventure\) \(B.Marbles\) NIM游戏,把其中任意一个石子移动到(0,0)算赢,所以必败态为全部石子都到(1,2)和(2,1)这两个点而不是(0,0)了,跑出sg函数异或即可,注意如果出现先手直接赢的需要特判 //#pragma comment(linker, "/STACK:1024000000,1024000000&…
\(2019-2020\ ACM-ICPC\ Brazil\ Subregional\ Programming\ Contest\) \(A.Artwork\) 并查集,把检测区域能在一起的检测器放在一个并查集里,然后判断是否有一个集合能够封住左边和上边的其中一个还有右边和下边的其中一个即可 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using name…
A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能变为负数 思路:考虑第二种操作,显然,最少的操作数肯定是不同数的个数 用map 记录,特殊注意0的存在 #include <bits/stdc++.h> using namespace std; #define N 100010 unordered_map <int, int> mp;…
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路:贪心的想法,长度为k的区间的起始点肯定是某个区间的起始点,或者长度为k的区间的结束点肯定是某个区间的结束点. 因为存在最优的答案,它的起点不在某个区间的起点,那么只有两种情况. 1° 不属于任何已知区间 2° 在某个已知区间的内部 首先考虑第一种情况  如果不属于任何已知区间,那么根据贪心,我肯定…
A:留坑 B:二维sg函数,特判边界情况 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) //#pragma GCC optimize("unroll-loops") //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protect…
这几天睡眠时间都不太够,室友晚上太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操作,可以把它减去一个数,或同时减去一个数,当玩家操作后出现了(0,0)则胜利. 思路:注意这里是出现(0,0)胜,而不是全都是(0,0)胜,所以我们不能简单的球sg,最后异或得到答案. 但是我们转化一下,如果玩家面对的全是(1,2) 或(2,1),则他胜利,那么我们可以以这两个状态为起点得到sg函数…
[题目链接] 这场比赛题面英文都好长... ... A - Zero or One 模拟. #include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a != b && a!=c) { cout <<"A"; return 0; } if(b != a && b!=c) { cou…
代码: #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int main(){ int a,b,c; int sum; while(~scanf("%d%d%d",&a,&b,&c)){ sum=; )sum++; )sum++;…
前缀和. 代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 typedef long long ll; 8 const int N=5*1e6+10; 9 int a[N]; 10 ll q[N]; 11 ll flag[N]; 12 int…
代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const int N=1e4+10; 8 int a[N]; 9 int flag[N]; 10 int main(){ 11 int n,m; 12 while(~scanf("…
题目链接:https://codeforc.es/gym/101908/problem/B 题意:两个人玩游戏,有 n 块石头,初始坐标为(x,y),一次操作可以将一块石头移动到(x - u,y),(x,y - u)或者(x - u,y - u),坐标为(0,0)的石子不能移动,问先手赢还是输. 题解:显然移动石子不能移动到 x = 0,y = 0 或者 x = y 的直线上,否则下一个玩家通过一步就可以获胜,故求 sg 值的时候,遇到这些坐标上的点直接跳过,答案则为全部石子异或和,特批一下一开…
题目:https://codeforces.com/gym/101908/problem/F 题意:给你n个舞台,每个舞台有很多个节目,每个节目有个开始时间,结束时间,价值,每个舞台至少出演过一个节目,所有舞台同一时刻只能一个舞台演节目,求怎么安排节目有最大价值 思路:首先舞台数只有10,而且我们必须访问每个舞台至少一次,很明显是个状态   1<<10 ,分别代表每个舞台现在演过节目没有,然后很明显我们还有有一个区间状态. 如果题目没有要求每个舞台必须演一次的话,很明显这个问题我们就可以直接按…
题意:有一个矩形,有\(k\)个警报器,警报器所在半径\(r\)内不能走,问是否能从左上角走到右下角. 题解:用并查集将所有相交的圆合并,那么不能走的情况如下图所示 所以最后查询判断一下即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <stack> #inclu…
题意:有\(n\)袋爆米花,某个队伍有\(c\)个队员,每个队员每秒做多可以吃\(t\)粒爆米花,但一袋爆米花只能由一个队员吃完,并且一个队员只能吃连续的一袋或几袋,不能隔着吃某一袋,求将所有爆米花吃完的最少时间. 题解:这道题当时想了半天,发现怎么也求不出答案,后来想到了二分答案的办法,将答案代入并模拟题意判断看是否满足条件,二分求得最小值即可. 代码: #include <iostream> #include <cstdio> #include <cstring>…
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C…
目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic Progressions 题面 代码 Problem C Emergency Evacuation 题意 题解 代码 Problem D Shortest Common Non-Subsequence 题面 代码 Problem E Eulerian Flight Tour Problem G W…
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered 11 to nn ,the ii-th pile of stones has a_iai​ stones. There are n - 1n−1 bidirectional roads in total. For any two piles, there is a unique path from…
感想: 今天三个人的状态比昨天计院校赛的状态要好很多,然而三个人都慢热体质导致签到题wa了很多发.最后虽然跟大家题数一样(6题),然而输在罚时. 只能说,水题还是刷得少,看到签到都没灵感实在不应该. 题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A:简单贪心,按高度sort一下就好了,这里用优先队列处理 #include <cstdio> #include <queue> #i…
A: 简单题,因为题目中说了不会有数据相同: #include<cstdio> #include<algorithm> #define maxn 200005 using namespace std; struct node { ]; int id; bool operator <(const node &t)const { ]<t.a[]; } }no[maxn]; int bb[maxn],cnt,n; int main() { scanf("%d…
题目链接:http://codeforces.com/gym/101149/problem/D 题目大意: 堡垒受到攻击.堡垒是n*m的矩阵,矩阵里刚开始都是平地,然后那个数值表示在当前平地上建一面墙需要a[i][j]的时间.目前我们在位置(r, c),我们找一种方法,把(r,c)全部围起来需要的最短时间? 思路:拆点,拆成in和out两个,in和out之间的cap就是a[i][j],然后就是简单的建边拉. //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #i…
题目链接:http://codeforces.com/gym/101149/problem/K 题目大意: 给你两个点a,b.一个人在a点,一个人在b点,b点的人要追杀a的点,他的跑步速度是a的两倍.如果a点的人能在b点追击到之前回到a点这个位置,那么这个人就是安全的(b点的人追击a点的人的追击方案是:一直朝着a点的人所在的位置奔跑过去).问,这个人的安全区域是多少? 思路:几何果然不会= =,连sb题都没想到 因为是面积,所以说两点之间的距离就决定了最后的结果.因为题目给出的是单位面积.所以对…
题目链接:http://codeforces.com/gym/101149/problem/L 题目大意:有n个点(其实是n+1个点,因为编号是0~n),m条有向边.起点是0,到a和b两个节点,所经过的最少的节点的数目是多少?(a和b也算,0不算) 思路: 真的是想了半天了,不知道怎么做,虽然知道是最短路,还是偏离了方向.最后万不得已的翻了题解. 题解看的是这个人的:链接 思路大体就是: 因为如果要到两个点,路径上的点肯定是有相交点的(因为0是必然要走的).然后如果两者路径相交,肯定选择共同相交…
题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字找配对,这个配对必须是m中的,而且m中的每个只能和n中的配对一次. 配对条件,w[i]>=a[j], c[i]>=b[j]即可配对. 输出n个数字,每个数字在m个数字当中的配对. 思路:假定n对数字的是x,m对数字的是y 离散化以后sort一下x和y,这样我们就得到了第一维是排序好了的. 然后我们…
Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. Each planet is connected to other planets through some transmission channels. There are mm transmission channels in the galaxy. Each transmission cha…
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. There are two operations: Swap the first half and the last half of the sequence (if nn is odd, the middle number does not change) Swap all the numbers in…
Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on the stage show of the cultural festival, and she is going to look for her human friend, Hinata. So she must find the shortest path to Hinata’s house.…
Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. The ii-th task costs you t_iti​seconds. You want to go to bed TT seconds later. During the TT seconds, you can choose some tasks to do in order to finis…
链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只有当两点在一条链上才存在,那么直接一遍dfs从根节点向下跑途中维护一下前缀和,把所有情况中不合理情况造成的值修正. 这样的话时间复杂度就可以降得非常低了,感觉还可以优化,但是懒得写了 代码耗时:142ms. 实现代码: #include<bits/stdc++.h> using namespace…
Then n - 1n−1 lines follow. ii-th line contains two integers f_{a_i}(1 \le f_{a_i} < i)fai​​(1≤fai​​<i), w_i(0 \le w_i \le 10^{18})wi​(0≤wi​≤1018) —The parent of the ii-th node and the edge weight between the ii-th node and f_{a_i} (ifai​​(istart fr…