题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\(0\)或更低,如果可以,输出操作次数,否则输出\(-1\). 题解:我们首先求\(d\)的前缀和,如果在求的过程中就能使怪兽死掉的话,直接输出即可.然后再去判断\(pre[n]\)是否小于\(0\),如果不小于,那么我们每一个循环得到的都是正的贡献,永远也打不死怪兽!再来看.我们最后的操作次数一定是…
E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly …
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restores Permutation 题意: 有一个n的排列,但现在只给出相邻两位的差,问原排列是多少,如果不存在就输出-1. 题解: 通过相邻两位的差我们可以知道第一个元素和其它位置元素的大小关系,然后根据这个来搞一波就行了. 代码如下: #include <bits/stdc++.h> using n…
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn minutes. After a round…
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/D Description Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n s…
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/D Description Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n …
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来染一棵树 题解 选择弃掉度数最高的k个点,然后第k+1个点的度数就是答案 代码 #include<bits/stdc++.h> #define N 200005 #define pb push_back using namespace std; int n,k,u,v,in[N],c[N],m,i…
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 代码 #include<bits/stdc++.h> #define M 5000005 #define ll long long #define pb push_back using namespace std; struct N{int l,r;N(int l=0,int r=0):l(l)…
http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i]和R[j]的颜色差不多了,才算匹配成功.但是,有一种特殊的颜色‘?’,该颜色可以和任意另一半鞋子匹配. 思路: 取出‘?’,格外判断就好了 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> #pragma com…
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know…
链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何字符. 思路: 对第一个字符串建立字符与位置的映射. 再处理第二个字符. 同时第二个字符中的‘?'不做处理. 全部遍历完了以后,再处理?的情况. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; map&…
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续,当第一个时间和最后一个时间都休息的时候加上去判断一下. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 2e5; int r[MAXN]; int main() {…
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. 思路: 先判断是否为整数倍. 再将倍数不断除以2和3. 最后剩下1则可以达到否则-1. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { int n, m; cin >&g…
链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大于上面,所以先求下面矩形周围面积,再求上方矩形最下一行除外的面积. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { int w1, h1, w2, h2; cin >&g…
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positio…
我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,m; int main(){ ios::sync_with_stdio(false); cin>>n>>m; ; else{ ll tmp = m/n; ,c2=; ==){ c1++;t…
题目的意思是: 如今有一个长度为n,宽为1的方格,在上面能够放大小为1*a船,然后输入为n,k,a.分别为平地的大小,船的数量,船的长度. 一个叫alice的人已经在地图上摆好了船的位置. 然后bob总共能够有m次攻击的机会,然后他每次攻击的点为xi.可是alice并不会告诉它有没有打中(也就是说每次都觉得他是miss的).问你,bob能够在第几次攻击的时候猜測出alice在撒谎,假设猜測不出来则输出-1. 这里每两条相邻的船不能相互接壤. 思路: 用set来维护每一段的区间. 首先.我们最多能…
题意:有一长度为\(n\)的数组,求最多的区间和相同的不相交的区间的个数. 题解:我们可以先求一个前缀和,然后第一层循环遍历区间的右端点,第二层循环枚举左端点,用前缀和来\(O(1)\)求出区间和,\(pos\)表示当前区间和为\(cur\)的最右端点,如果我们枚举的左端点\(j\)比\(pos[cur]\)所在的最右端点大,那么我们就能得到区间和为\(cur\)的新区间,并更新状态.上面操作我们贪心得出一定是最优的.之后我们再遍历map,求出次数最多的区间和,然后再枚举所有区间,并且注意区间不…
题意:有两个字符串,两个字符串中的相同字符可以相互匹配,\(?\)可以和任意字符匹配,输出最大匹配的字符数量和它们分别两个字符串中的位置. 题解:很容易贪心,我们先遍历第一个字符串,然后在第二个字符串中去找与当前位置相同的字符,这个过程我们可以先将每个字符的位置存下来然后再操作,遍历完后再遍历字符和问号,最后是问号和问号匹配,具体看代码吧,主要是想学习一下用队列来模拟操作(会方便很多). 代码: int n; string l,r; queue<int> h1[30],h2[30]; vect…
题意:有一长度为\(n\)的序列\(p\),现在给你\(q_i=p_{i+1}-q_i \ (1\le i\le n)\),问你是否能还原出原序列,如果能救输出原序列,否则输出\(-1\). 题解:由:\(q_i=p_{i+1}-p_i\),我们对其求前缀和可得:\(s_i=p_{i+1}-p_1\),然后再求出:\(\sum^{n-1}_{i=1}s_i=\sum^{n}_{i=2}p_i-(n-1)*p_1\),\(\sum^{n}_{i=2}p_i=\sum^{n}_{i=1}i-p_1=…
C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes…
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/C Description Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pair…
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/B Description Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorit…
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/A Description Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resista…
D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads…
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers…
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There…
C. Money Transfers 题目连接: http://www.codeforces.com/contest/675/problem/C Description There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Al…
C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/C Description Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of number…
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很明显,把这个区间分段.分成[L, 2 * L - 1],因为这段区间中,都不大于等于L的两倍,这样就使得这段区间的贡献就是sum_number * L了. 就是中间有多少个数,每个数贡献一个L值.然后到枚举[2 * L, 3 * L - 1]这段区间,贡献的值就是sum_number * (2 *…