[CodeForces 344D Alternating Current]栈】的更多相关文章

题意:两根导线绕在一起,问能不能拉成两条平行线,只能向两端拉不能绕 思路:从左至右,对+-号分别进行配对,遇到连续的两个“+”或连续的两个“-”即可消掉,最后如果全部能消掉则能拉成平行线.拿两根线绕一下就理解了,也可以一根拉成直线,另一根围着它绕,然后观察能拉成直线的条件.用栈实现就行. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38…
id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" style="color:blue; text-decoration:none">Alternating Current Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64…
Description Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and st…
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/B Description Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hu…
D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in…
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) 的等比数列. 当公比为 \(1\) 时,不能用等比数列求和公式. 什么时候公比为 \(1\) ? 当 \(a=b\) 时,\(a^{-1}b=1(mod\ p)\) 当 \(a=p-b\) 时,\(a^{-1}b=(p-b)^{-1}b=-1(mod\ p)\),如果此时 \(k\) 是偶数,公比就…
Codeforces Round #200 (Div. 1) B:http://codeforces.com/problemset/problem/343/B 题意:这一题看懂题意是关键,题目的意思就是两根a,b电线相互缠绕,+表示a在b的上面,-表示b在a的上面,给以一个串,然后问你这两根线能否解开. 题解:显然,如果两个相邻的++或者--的话可以直接消去,然后就会想到用栈来模拟,相同的就消去,不同的就进栈,最后判断栈内是否为空就可以了. #include<iostream> #includ…
Psychos in a Line CodeForces - 319B There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the…
http://codeforces.com/contest/344/problem/D #include <cstdio> #include <cstring> #include <stack> #include <algorithm> using namespace std; ]; int main() { stack<char>q; scanf("%s",str); int k=strlen(str); ; i<k;…
题目链接:http://codeforces.com/problemset/problem/963/A 题目大意:就是给了你n,a,b和一段长度为k的只有'+'和‘-’字符串,保证n+1被k整除,让你你计算. 解题思路: 暴力肯定超时的,我们可以先计算出0~k-1这一段的值,当做a1,可以发现如果把每段长度为k的段的值当做一个元素,他们之间是成等比的,比值q=(b/a)^k, 然后就直接用等比数列求和公式求出答案即可.昨天把q当成b/a了,我的脑子啊... 注意,判断q==1时不能通过判断a==…