E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly …
题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\(0\)或更低,如果可以,输出操作次数,否则输出\(-1\). 题解:我们首先求\(d\)的前缀和,如果在求的过程中就能使怪兽死掉的话,直接输出即可.然后再去判断\(pre[n]\)是否小于\(0\),如果不小于,那么我们每一个循环得到的都是正的贡献,永远也打不死怪兽!再来看.我们最后的操作次数一定是…
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…