# Codeforces Round #653 (Div. 3)

A. Required Remainder
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given three integers x,y and n. Your task is to find the maximum integer k such that 0≤k≤n that kmodx=y, where mod is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with given x,y and n you need to find the maximum possible integer from 0 to n that has the remainder y modulo x.
You have to answer t independent test cases. It is guaranteed that such k exists for each test case.

#include<bits/stdc++.h>
using namespace std;
int x,y,n;
int t;
int main(){
scanf("%d",&n);
while(n--){
scanf("%d%d%d",&x,&y,&t);
int r=t%x;
if(r==y)cout<<t<<endl;
else if(r>y)cout<<t-(r-y)<<endl;
else if(r<y)cout<<t-x+(y-r)<<endl;
}
}


signed main()
{
IO_OP;

int t;
cin >> t;
while(t--) {
int x, y, n;
cin >> x >> y >> n;
cout << (n - y) / x * x + y << endl;
}

}


B. Multiply by 2, divide by 6
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it’s impossible to do that.
You have to answer t independent test cases.

2的个数m其实就是单独除以6的个数，权重是1
3的个数多于2的个数的那部分就是2再除以6的部分，权重是2，

（n-m）

signed main()
{
IO_OP;

int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int sa = 0, na = 0;
while(n % 2 == 0) n /= 2, sa++;
while(n % 3 == 0) n /= 3, na++;
if(n != 1 || sa > na) {
cout << -1 << endl;
continue;
}
cout << na + na - sa << endl;
}



C. Move Brackets
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a bracket sequence s of length n, where n is even (divisible by two). The string s consists of n2 opening brackets ‘(’ and n2 closing brackets ‘)’.
In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index i, remove the i-th character of s and insert it before or after all remaining characters of s).
Your task is to find the minimum number of moves required to obtain regular bracket sequence from s. It can be proved that the answer always exists under the given constraints.
Recall what the regular bracket sequence is:
“()” is regular bracket sequence;
if s is regular bracket sequence then “(” + s + “)” is regular bracket sequence;
if s and t are regular bracket sequences then s + t is regular bracket sequence.
For example, “()()”, “(())()”, “(())” and “()” are regular bracket sequences, but “)(”, “()(” and “)))” are not.
You have to answer t independent test cases.

#include<bits/stdc++.h>
using namespace std;
int t;
char s[2005] ;
int n;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
scanf("%s",s);
int l=0;
int r=0;
int ans=0;
int Lack=0;
for(int i=0;i<n;i++){
if(s[i]=='('){

l++;
}
else {
if(l<=0){
ans++;
}
else if(l>0){
l--;
}
}
}
//cout<<"ans=";
cout<<ans<<endl;
}
}


D. Zero Remainder Array
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array a consisting of n positive integers.
Initially, you have an integer x=0. During one move, you can do one of the following two operations:
Choose exactly one i from 1 to n and increase ai by x (ai:=ai+x), then increase x by 1 (x:=x+1).
Just increase x by 1 (x:=x+1).
The first operation can be applied no more than once to each i from 1 to n.
Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by k (the value k is given).
You have to answer t independent test cases.

D这个题，一上来就有思路，，但是这个鬼东西真的考验实战经验，

#define int ll
typedef long long ll;

#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
IO_OP;

int t;
cin >> t;
while(t--) {
int n, k;
cin >> n >> k;
map<int, int> cnt;
int mx = -1;
for(int i = 0; i < n; i++) {
int tt;
cin >> tt;
if(tt % k == 0) continue;
tt %= k;
cnt[tt]++;
mx = max(mx, cnt[tt] * k - tt);
}
cout << mx + 1 << endl;
}

}



03-13 1242

06-29 283

07-17 172

09-06 1万+

06-29 78

04-16 319

01-06 216

06-29 94

06-29 276

10-06 281

#### Codeforces Round #514 (Div. 2)

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。