Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing s…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After click…
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to d…
题目链接 \(Description\) 给定两个数\(n,m\),每次可以使\(n\)减一或使\(n\)乘2.求最少需要多少次可以使\(n\)等于\(m\). \(Solution\) 暴力连边BFS或者DP都行,都是O(n)的.有更优的做法. 过程是可逆的,我们考虑m变成n,有两种操作:1是m+=1:2是当m为偶数时,m/=2. 要用最少的次数使得m<=n. 因为m加两次再除以二和先除以二再加一次得到的结果是一样的,即能除就不加.这样就O(logn)解决了. 正推n到m好像推不出性质啊..正…
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是2.但由于n不一定是质数,我们还需要再加k条边.然后对于\(i \in [1,k]\),我们加边(i,i+n/2).当\(k\leq \frac{n}{2}\)的时候,只会把一些点的度数由2变成3,否则会出现重边问题.假设新图的边数为m,那\(m \in [n,n+\frac{n}{2}]\),如果…
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常复杂,明显超出自己现在水平,卡了很久也没有好好做题.等了很长时间才开始看D题,而这时信心已经严重不足.赛后再看D题才发现自己比赛时理解错了题意,致使误以为题目非常复杂.而实际上,这个过程分析起来是非常容易的. 对于三种棱长度分别为a,b,c的石头,r最大为min(a,b,c)/2;. 如果两个石头要…
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos…
http://codeforces.com/gym/100623/attachments E题第一个优化它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下第二个优化,与次数无关,所以排个序就完事了 #include<iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cmath> #include<ctime> #…
[gym101982M][思维好题][凸壳]Mobilization 题目链接 20182019-acmicpc-pacific-northwest-regional-contest-div-1-en.pdf 题目大意 现在有\(n\)种士兵,每种士兵有一个血量\(h_i\)和潜力\(p_i\)以及花销\(c_i\). 你一共有\(C\)块钱,现在你要用这些钱去雇佣士兵,你雇佣某种士兵的数量可以是任意实数(也就是说并不一定要整数).最后你构建出来军团的战斗力等于总血量与总潜力的乘积. \((n\…
http://codeforces.com/gym/100623/attachments H题已经给出来的,包括后来添加的,都累加得到ans,那么从1-ans都是可以凑出来的,如果ans<a[now]-1,那么就添加一个ans+1,然后继续操作. #include<iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cmath> #include&l…
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. Angry Students 题目大意:有t队学生,每个学生有两种状态,生气(A)或不生气(P).(话说为什么生气的戴着圣诞帽哇)所有生气的人都会往前一个人丢雪球,被丢到的人也会变得生气,也会丢雪球.问你每队人中最后一个学生变得生气的时刻. 这题就是统计最长的连续的'P'当然前提是左边有生气的人. 代码…
土题大战Vol.0 A. 笨小猴 思维好题 题目描述 驴蛋蛋有 \(2n + 1\) 张 \(4\) 星武器卡片,每张卡片上都有两个数字,第 \(i\) 张卡片上的两个数字分别是 \(A_i\) 与 \(B_i\). 现在驴蛋蛋要从所有卡片中选出恰好 \(n + 1\) 张卡片,然后计算他选出的所有卡片中 \(A_i\) 的和与 \(B_i\) 的和.他的目的是要使他选出的卡片的\(A_i\) 的和与 \(B_i\) 的和,都要分别大于剩下 \(n\) 张没选的卡片的 \(A_i\) 的和与 \…
题目链接:http://codeforces.com/problemset/problem/520/B 题意 给出两个数n和m,n每次只能进行乘2或者减1的操作,问n至少经过多少次变换后能变成m 思路 在百度之前用了各种方法,dfs,递推什么的能用的全用了,最后都WA在了第七组 百度了一下,看到了大佬们的代码震精了!!!竟然只有一行!! 用逆推,把从n变成m转换成从m变成n. 如果m是偶数那么m一定是通过上一步乘2的操作变来的,如果是奇数,那么一定是通过上一步减一变来的.最后当m小于n的时候,停…
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每个区间的和都为0.对于每个区间来说,设该区间长度为l,则让该区间都为0的操作数为l-1,例如:1 .1 .-3 .1的操作数为3,也就是说,若把a分成k个区间,则a所需要的总的操作数为n-k. 所以现在我们的目标就是把数组a划分为尽可能多的部分,这个时候我们可以用一个map,统计前缀和的个数,因为对…
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同的城市编号为a1, a2,…,ak. 不幸的是,玛莎居住的那个国家的法律禁止在任何一个有仓库的城市开设面包店.她只能在另一个n - k城市中的一个开这家店,当然,面粉配送也要付费——从仓库到面包房每走一公里,玛莎就得支付1卢布. 形式上,玛莎将支付x卢布,如果她将打开面包店在一些城市b (ai≠b每…
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and col…
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次,000110是3次. 分析: 区间内部的数目是不会发生变化的,因为每一位都是按位取反,相当于都没变,唯一发生变化的是区间边缘,所以考虑到连续的两个或多个1或者0的时候在其中某处设置断点会使得变换次数增加,很容易理解当某处有两个连续点的时候变换次数增加1,因为一个区间只有两个端点所以变换次数最多增加…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
题目链接:http://codeforces.com/problemset/problem/407/B 题目大意:一共n+1个房间,一个人从1走到n+1,每次经过房间都会留下一个标记,每个房间有两扇门:①第一扇门通向i+1,如果当前房间标记有奇数个,则必须走第一扇门.②第二扇门通向pi(pi<=i),如果当前房间标记有偶数个,则必须走第二扇门.问从房间1走到房间n+1需要多少步,结果对1e9+7取模.解题思路:之前傻了...明明都推出规律了,结果被自己给否定了...设dp[i]表示从1~i需要走…
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to ren…
[题目链接]:http://codeforces.com/contest/520/problem/B [题意] 给你一个数n; 对它进行乘2操作,或者是-1操作; 然后问你到达m需要的步骤数; [题解] 操作的过程中; 可能会大于m吧: 也不知道是多少倍; 但也没事,不差那一点时间. bfs [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,r…
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in the first team and a_2 players…
题目大意:有一排蟑螂,只有r和b两种颜色,你可以交换任意两只蟑螂的位置,或涂改一个蟑螂的颜色,使其变成r和b交互排列的形式.问做少的操作次数. 题目思路:更改后的队列只有两种形式:长度为n以r开头:长度为n以b开头.与初始串进行比较并统计改变次数记作ans,算出必须进行的涂色操作的次数step,我们可以把交换两只不同颜色的蟑螂的位置看做进行了两次涂改操作,其次数为(ans-step). 那么得出改变为模板串的最小操作次数为:step+(ans-step)/2; #include<iostream…
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a regular polygon with nn vertices labeled from 11 to nn in counter-clockwise order. The triangulatio…
题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号的节点,然后遍历即可. 代码: #include<bits/stdc++.h> using namespace std; #define int long long #define N 1005000 int f[N];int n,m; int getf(int v){// 并查集模板 if(v=…
题意:给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的. ( ) ? ) => ( ) ( ) 完美匹配( ( ) ? => ( ( ) )完美匹配? ? ? ? => ( ) ( ) => ( ( ) ) 算一种子串 思路:看代码. #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string str; cin>>str…
A. Round House Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he…
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vect…
大家好,我们选择的是Bubble Cup比赛Div2场次的J题,不用问我Bubble Cup是什么比赛,我也不清楚.总之是一场算法比赛就是了.可能是这个比赛知名度比较低吧,参与的人数也不是很多,我们选择了一道中等通过人数的J题,作为今天的题目. 链接:https://codeforces.com/contest/1424/problem/J 这题非常不错,是一道质量很高的数学题,也很符合我的胃口.因为没有太多的trick,有的只有思维和逻辑的碰撞. 题意 我们都知道对于两个数a和b来说,我们可以…
http://codeforces.com/problemset/problem/520/B B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input:standard input output:standard output Vasya has found a strange device. On the front panel of a device there are: a…