题意/题解:经典括号匹配题目,不多说了. 代码: int t; int n; string s; int cnt; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cnt=0; int ans=0; cin>>n>>s; for(int i=0;i<n;++i){ if(s[i]=='('){ cnt++; } else{ if(cnt>0) cnt--; el…
比赛链接:https://codeforces.com/contest/1374 A. Required Remainder 题意 给出 $x, y, n$,找到最大的整数 $0 \le k \le n$,使得 $k\ mod\ x = y$ . 题解 $k = mx + y$,求得满足条件最大的 $m$ 即可. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int x, y, n; cin >> x…
题目链接: http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Toda…
题目链接:https://vjudge.net/problem/CodeForces-149D D. Coloring Brackets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Once Petya read a problem about a bracket sequence. He gave it much tho…
题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\)种情况来存,即: ​ 1.\(a=b=1\). 2.\(a=1,b=0\). 3.\(a=0,b=1\). 对于2和3来说,我们可以将他们排序,然后合并到一起,最后放到第1种情况中再排一次序,取前\(k\)个前缀和即可. 代码: int n,k; int t,x,y; int ans; vector…
题意:有一组数,刚开始时\(x=0\),每次可以让\(x\)++或让某一个元素+=\(x\)后\(x\)++,每个元素只能加一次\(x\),问最少操作多少次使得所有元素能被\(k\)整除. 题解:每个元素只能被加一次,我们对每个元素%\(k\),然后记录他们出现的次数(不考虑\(k\)能整除的情况),因为\(x\)是递增的,所以如果我们将取余后的数看成一个数组的话,就相当于\(x\)在这个数组上跑循环,直到循环次数等于数组中最大的那个数为止(同时下标也要尽可能的大),所以答案也就是 (\(x\)…
题意:有一个数\(n\),每次操作可以使\(n*=2\)或\(n/=6\)(如果能被整除),求最少操作次数使得\(n=1\),如果不满足,输出\(-1\). 题解:我们只要看\(n\)的质因子即可,如果要满足条件,那么它的质因子只能含有\(2\)和\(3\),并且\(2\)的次数不大于\(3\)的次数.直接去找\(2\)和\(3\)的次数即可.(写了个质因数分解被hack了,呜呜呜) 代码: int t; int n; int main() { ios::sync_with_stdio(fals…
题意:有三个正整数\(x,y,n\),再\(1\)~\(n\)中找一个最大的数\(k\),使得\(k\ mod\ x=y\). 题解:先记\(tmp=n/x\),再判断\(tmp*x+y\)的值是否大于\(n\),如果是,直接输出\((tmp-1)*x+y\),否则输出\(tmp*x+y\). ps:这题好像可以直接二分搞 代码: int t; int x,y,n; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; whi…
Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮:使得\(x=x+k\) '√'按钮:使得\(x=\sqrt{x}\),此时\(x\)必须是平方数,游戏等级加1,即\(k=k+1\),且\(\sqrt{x}\)是\(k+1\)的倍数. 游戏开始时,\(x=2,k=1\),输出\(n(n \le 10^5)\)个数,表示每个等级对应的\(\frac…
A. Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains…
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi…
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 + .. + ( - 1)n…
Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/problem/E Description Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at t…
Codeforces Round #485 (Div. 2) C. Three displays 题目连接: http://codeforces.com/contest/987/problem/C Description It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays…
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description Polycarp lives on a coordinate line at the point x=0. He goes to his friend that lives at the point x=a. Polycarp can…
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description You are given an integer n from 1 to 10^18 without leading zeroes. In one move you can swap any two adjacent digits in…
Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored with lifeProblem B.Crossword solvingProblem C. Hacker, pack your bags! Problem A. I'm bored with life A. I'm bored with life Holidays have finished. T…
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move.…
Codeforces Round #734 (Div. 3) 20210920.网址:https://codeforces.com/contest/1551. 编程细节:下标定义不要一会[1,n]一会[0,n)啊- A 用价值为1的硬币a枚+价值为2的硬币b枚,买价值为n的东西,希望ab之差的绝对值尽量小.大水题. B1 给我们一个字符串s,用红色和绿色给s上色,规则如下: 一个字母或者不上色,或者被涂成一种颜色,即不能又红又绿. 被涂成一种颜色的所有字母,必须两两不相同. 红色字母数量=绿色字…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给出的01序列相等(比较时如果长度不等各自用0补齐) 题解: 1.我的做法是用Trie数来存储,先将所有数用0补齐成长度为18位,然后就是Trie的操作了. 2.官方题解中更好的做法是,直接将每个数的十进制表示中的奇数改成1,偶数改成0,比如12345,然后把它看成二进制数10101,还原成十进制是2…
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了. A 水题 //#pragma comment(linker, "/STACK:102400000,102400000") #include<cstdio> #include<cmath> #include<iostream> #include<…
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, 然后接下来的t秒需要的蜡烛都燃烧着,超过t秒,每减少一秒灭一支蜡烛,好!!! 详细解释:http://blog.csdn.net/kalilili/article/details/43412385 */ #include <cstdio> #include <algorithm> #i…
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再看自己的代码发现有清晰的思维是多重要 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include…