[题目]C. Black Widow [题意]给定一个表达式,形式为(...)^(...)^......^(...)=1(n个括号),括号中为1~2个值取或.有m个变量,给出表达式的值为xi或 !xi,xi只能为0或1,求变量赋值使得表达式成立的方案数.每个变量至多出现两次.n,m<=10^5. [算法]动态规划+模拟 [题解]每个括号视为一个点,对于同时出现在两个括号内的变量将两个点连边(边须记两边异同).由于每个变量至多出现两次,所以一条边就可以代表一个变量. 由于每个括号至多两个变量,所以…
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' .括号'(' ')' 组成.[括号不会嵌套] 求括号外面的连续字符串最大的字符串长度和括号内的连续字符串的个数. 举例: input 37_Hello_Vasya(and_Petya)__bye_(and_OK) output 5 4 括号外面的连续的字符串最长的字符串长度为 5 括号内有 4 个连续…
题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张,分别为:y1, y2, ...yk2:(n<=10&&k1+k2==n,所有牌的数字都不同): 依次比较x1, y1的大小,若x1>y1,依次将x1, y1加入x牌最底下:反之则将y1,x1依次加入y牌最底下:直至有方的牌输完为止:输出总共游戏的步数和赢方: 如果两方都不能赢,则…
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人KO,被KO的人不能投票了,这样循环,直到某一派的人全部被KO,问哪方赢. 思路:模拟..代码好懂.. #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #i…
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/A Description You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon…
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segmen…
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾.(2)把t的尾字符取出并添加到u的末尾. 问你当经过一系列操作后,s和t均为空时,字典序最小的u. 题解: 操作的本质: s为队列,t为栈. 贪心思路: (1)找到s中的最小字符c,不断出队并加入t,直至有一次出队的字符等于c,停止出队. (2)当t的尾字符小于等于s中的最小字符时,优先弹出t的尾…
题目传送门 神奇的门I 神奇的门II 题目大意 有$n$组学生要上课2次课,有$m$个教室,编号为$1$到$m$.要确定有多少种不同的安排上课的教室的方案(每组学生都是本质不同的),使得它们满足: 每组学生第一次上课的教室的编号小于等于第二次上课的教室的编号. 第$i$间教室在第一次上课时,恰好有$x_{i}$组学生在场. 第$i$间教室在某次上课时,中间包含的学生组数不能超过$y_{i}$. 输出答案模$10^{9} + 7$. 因为第一次上课恰好有多少人,所以这个方案数是可以直接用组合数,暂…
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws…
B. Spreadsheets 题目连接: http://www.codeforces.com/contest/1/problem/B Description In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second - number B, etc. till c…
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election committee of Flatland is preparing for presidential elections. To minimize human factor in ballot counting they decided to develop an automated Ballot Ana…
地址:http://codeforces.com/contest/660/problem/B 题目: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider 2n rows of the seats in a bus. n rows of the seats on the left…
题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公里就要花费 t秒修一次才可以继续开,车每公里花费 a秒,步行每公里花费 b秒.依次给出d, k, a, b, t.问最少需要花费多少时间到达邮局.车刚开始时是好的. 思路: 首先可以模拟一下,可以想到,如果车速比步速块,那么前 k公里路肯定选择坐车,因为开始时车是好的,不用花费多余的时间来修理车,否…
A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its t…
C. Shockers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves ciphers. He has invented his own cipher called Right-Left. Right-Left cipher is used for strings. To encrypt the string s=s1s2…
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corner…
题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始想到的是O(n^2)的动态规划,但是超时了,下面是超时的代码. #include <iostream> using namespace std; const int maxn = 200020; int n, a[maxn], f[maxn], res = 0; int main() { cin…
http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发出的消息的总数),加上一个 q 队列. 思路: 查询==1的时候,入队(记录顺序), sum++ (sum 为全部的剩余 没阅读的数量) 查询==2的时候,针对一个app,sum -(这个app发出的消息的总数 - 这个app已经阅读过的消息的数量),然后用 app数组 更新 r 数组,表示这个ap…
题目出处:http://codeforces.com/problemset/problem/2/B 题目描述 给你一个 \(n \times n\) 的二维数组,它包含的元素都是非负整数.你需要寻找一条满足如下条件的行走路线: 这条路线的起始位置在二维数组的左上角: 每一步你只可以从当前的位置往右或者往下走一格: 这条路线的终止位置在二维数组的右下角. 此外,如果我们一路上把所有的数字相乘,结果应该是最不"圆"的.换句话说,这个乘积结尾的 \(0\) 应该尽可能地少. 输入格式 输入的…
Codeforces 题面传送门 & 洛谷题面传送门 大模拟(?)+阿巴细节题,模拟赛时刚了 3h 最后因为某个细节写挂 100->40/ll/ll(下次一定不能再挂分了啊 awa) 首先先考虑怎么判 \(-1\),显然如果区间 \([l,r]\) 中间的括号构不成合法的括号序列,答案显然是 \(-1\),其次如果 \(s_l\) 是加号或乘号那算式也不合法,\(s_r\) 也同理,这可以通过前缀和+ST 表在 \(\mathcal O(n\log n)-\mathcal O(1)\) 时间…
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is…
求括号外最长单词长度,和括号里单词个数. 有限状态自动机处理一下. http://codeforces.com/problemset/problem/723/B Examples input 37_Hello_Vasya(and_Petya)__bye_(and_OK) output 5 4 input 37_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__ output 2 6 input 27(LoooonG)__shOrt__(LoooonG) output 5 2…
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented a…
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated…
题目链接: B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mary has just graduated from one well-known University and is now attending celebration party. Students like to d…
题意: 你有一个榨汁机 还有n个土豆 榨汁机可以容纳h高的土豆 每秒可以榨k高的东西 问按顺序榨完土豆要多久 思路: 直接模拟 一开始以为是最短时间排了个序 后来发现多余了…… #include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<string> #include<map>…
原文链接http://www.cnblogs.com/zhouzhendong/p/8847145.html 题目传送门 - CodeForces 553E 题意 一个有$n$个节点$m$条边的有向图,每条边连接了$a_i$和$b_i$,花费为$c_i$. 每次经过某一条边就要花费该边的$c_i$. 第$i$条边耗时为$j$的概率为$p_{i,j}$. 现在你从$1$开始走到$n$,如果你在$t$单位时间内(包括$t$)到了$n$,不需要任何额外花费,否则你要额外花费$x$. 问你在最优策略下的…
原文链接http://www.cnblogs.com/zhouzhendong/p/8990592.html 题目传送门 - CodeForces 516A 题意 对于一个正整数$x$,$f(x)=x$各个数位的阶乘之积. 给定一个数$a$,满足$f(a)>1$,求一个最大的不含有$0$或者$1$的$x$满足$f(x)=f(a)$. $a<10^{16}$ 题解 我们将$f(a)$分解质因数并统计各个质因数个数作为状态. 首先考虑到每一个数位都是$2$~$9$的,质因数只可能有$4$种. 而且…
You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Spec…