题意:有三个正整数\(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…
题意:有一组数,刚开始时\(x=0\),每次可以让\(x\)++或让某一个元素+=\(x\)后\(x\)++,每个元素只能加一次\(x\),问最少操作多少次使得所有元素能被\(k\)整除. 题解:每个元素只能被加一次,我们对每个元素%\(k\),然后记录他们出现的次数(不考虑\(k\)能整除的情况),因为\(x\)是递增的,所以如果我们将取余后的数看成一个数组的话,就相当于\(x\)在这个数组上跑循环,直到循环次数等于数组中最大的那个数为止(同时下标也要尽可能的大),所以答案也就是 (\(x\)…
比赛链接: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…
题意:有\(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…
题意/题解:经典括号匹配题目,不多说了. 代码: 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…
题意:有一个数\(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…
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…
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course…
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…